270 lines
6.0 KiB
C
270 lines
6.0 KiB
C
#include "wings.h"
|
|
//#include "maths.h"
|
|
|
|
#include "display.h" // bopti.h => images // tales.h => fonts
|
|
#include "keyboard.h"
|
|
#include "timer.h"
|
|
#include "gray.h"
|
|
|
|
#include "stdio.h"
|
|
#include "stdlib.h"
|
|
|
|
#define MAP_SIZE_X 256
|
|
#define MAP_SIZE_Y 256
|
|
|
|
#define MAX_PLANES 2
|
|
#define MAX_CLOUDS 2
|
|
|
|
Plane planes[MAX_PLANES]; // number of planes in the map (with us)
|
|
//others planes are controlled by the AI
|
|
|
|
Cloud clouds[MAX_CLOUDS]; //number of clouds in this beautifull sky
|
|
// generated by the IA
|
|
|
|
extern image_t plane;
|
|
extern image_t img_menu;
|
|
extern image_t cloud;
|
|
extern image_t missiles;
|
|
|
|
int main()
|
|
{
|
|
menu();
|
|
return 1;
|
|
}
|
|
|
|
void init()
|
|
{
|
|
unsigned char i,j;
|
|
|
|
for(i = 0; i < MAX_PLANES; i++)
|
|
{
|
|
planes[i].x = 56 + 16 * i;
|
|
planes[i].y = 24 + i;
|
|
planes[i].dir = i;
|
|
planes[i].life = 100;
|
|
planes[i].reload = 6;
|
|
|
|
for(j = 0; j < MAX_MISSILES; j++)
|
|
{
|
|
|
|
//planes[i].missiles[j].distance = 0;
|
|
planes[i].missiles[j].dir = planes[i].dir;
|
|
planes[i].missiles[j].type = 0;
|
|
}
|
|
}
|
|
|
|
for(i = 0; i < MAX_CLOUDS; i++)
|
|
{
|
|
clouds[i].x = 10 + 16*i;
|
|
clouds[i].y = 10 + 16*i;
|
|
}
|
|
}
|
|
|
|
// void infos()
|
|
// {
|
|
// unsigned int key = 0;
|
|
//
|
|
// while(key != KEY_SHIFT)
|
|
// {
|
|
// dclear();
|
|
//
|
|
// dtext(1, 1, "All informations");
|
|
// dprint(1, 10, "life : %d", planes[0].life);
|
|
// dprint(1, 20, "shoot : %d", planes[0].reload);
|
|
// dtext(1,54,"F1 to leave");
|
|
// dupdate();
|
|
//
|
|
// key = getkey();
|
|
// }
|
|
// }
|
|
|
|
int menu()
|
|
{
|
|
unsigned char menu = 0;
|
|
unsigned int key = 0;
|
|
|
|
//extern image_t img_menu;
|
|
|
|
while(1)
|
|
{
|
|
dclear();
|
|
|
|
dimage(0, 0, &img_menu);
|
|
drect(67 + menu * 19, 10 + menu * 27, 100 + menu * 19, 25 + menu * 27, color_invert);
|
|
|
|
dupdate();
|
|
|
|
key = getkey();
|
|
|
|
switch (key)
|
|
{
|
|
case KEY_UP : case KEY_DOWN : menu = !menu; break;
|
|
case KEY_EXE :
|
|
{
|
|
if (!menu)
|
|
{
|
|
game(); break;
|
|
}
|
|
else return 1;
|
|
}
|
|
case KEY_EXIT : return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
char get_decal(unsigned char dir, Type type)
|
|
{
|
|
char dx[4] = {-1, -1 , 0, 1};
|
|
char n = 1;
|
|
|
|
dir += type;
|
|
|
|
while(dir >=4)
|
|
{
|
|
dir-=4;
|
|
n = -n;
|
|
}
|
|
return n*dx[dir];
|
|
}
|
|
|
|
void *update_frame()
|
|
{
|
|
static unsigned char i,j;
|
|
|
|
dclear();
|
|
|
|
dprint(1, 1, "s:%d l:%d", planes[0].reload, planes[0].life);
|
|
//dprint(1, 20, "(%d,%d)", get_decal(planes[0].dir, dX), get_decal(planes[0].dir, dY));
|
|
//dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly);
|
|
|
|
for(i = 0; i < MAX_CLOUDS; i++)
|
|
{
|
|
dimage(clouds[i].x, clouds[i].y, &cloud);
|
|
clouds[i].x += get_decal(planes[0].dir, dX);
|
|
clouds[i].y += get_decal(planes[0].dir, dY);
|
|
}
|
|
|
|
for (i = 0; i < MAX_PLANES; i++)
|
|
{
|
|
if(i > 0)
|
|
{
|
|
planes[i].x += get_decal(planes[0].dir, dX);
|
|
planes[i].y += get_decal(planes[0].dir, dY);
|
|
}
|
|
|
|
dimage_part(planes[i].x, planes[i].y, &plane, 16*planes[i].dir, 0, 16, 16);
|
|
|
|
for(j = 0; j < MAX_MISSILES; j++)
|
|
{
|
|
planes[i].missiles[j].x -= get_decal(planes[i].missiles[j].dir, dX);
|
|
planes[i].missiles[j].y -= get_decal(planes[i].missiles[j].dir, dY);
|
|
|
|
dimage_part(planes[i].missiles[j].x, planes[i].missiles[j].y ,&missiles, 8 * planes[i].missiles[j].dir, 0, 8, 8);
|
|
}
|
|
|
|
}
|
|
|
|
dupdate();
|
|
}
|
|
|
|
#define MAX_KEYS 4
|
|
|
|
int game()
|
|
{
|
|
unsigned char fire = 0; // fire disable
|
|
unsigned char sum = 0;
|
|
|
|
unsigned int sum_keys[8] = { KEY_RIGHT, KEY_RIGHT + KEY_UP, KEY_UP, KEY_LEFT + KEY_UP, KEY_LEFT, KEY_LEFT + KEY_DOWN, KEY_DOWN, KEY_RIGHT + KEY_DOWN };
|
|
|
|
int keys[MAX_KEYS];
|
|
|
|
unsigned char i;
|
|
unsigned char j;
|
|
|
|
j = 0;
|
|
|
|
init(); // initialisation
|
|
|
|
timer_t *timer = NULL;
|
|
|
|
timer = timer_create(40, 0);
|
|
timer_attach(timer, update_frame, NULL);
|
|
timer_start(timer);
|
|
|
|
while(1)
|
|
{
|
|
multigetkey(keys, MAX_KEYS, 0);
|
|
|
|
sum = 0;
|
|
|
|
|
|
for(i = 0; i < MAX_KEYS; i++)
|
|
{
|
|
switch(keys[i])
|
|
{
|
|
case KEY_UP : case KEY_DOWN : case KEY_LEFT : case KEY_RIGHT :
|
|
{
|
|
sum += keys[i];
|
|
break;
|
|
}
|
|
|
|
case KEY_SHIFT :
|
|
{
|
|
if(planes[0].reload > 0)
|
|
{
|
|
fire = 1;
|
|
//planes[0].reload = planes[0].reload - 1;
|
|
}
|
|
break; // fire enable
|
|
}
|
|
|
|
case KEY_EXIT :
|
|
{
|
|
timer_destroy(timer); //destroy the virtual timer
|
|
return 1; // good bye, see you soon
|
|
}
|
|
|
|
// case KEY_OPTN :
|
|
// {
|
|
// timer_stop(timer); // virtual timer stopped
|
|
//
|
|
// infos();
|
|
//
|
|
// //timer = timer_create(40, 0);
|
|
// //timer_attach(timer, &update_frame, NULL);
|
|
// timer_start(timer);
|
|
// break;
|
|
// }
|
|
}
|
|
}
|
|
|
|
// we determine the direction of the plane
|
|
|
|
for(i = 0; i < 8; i++)
|
|
{
|
|
if(sum == sum_keys[i])
|
|
{
|
|
planes[0].dir = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
if(fire == 1) // put the screen on fire !
|
|
{
|
|
planes[0].missiles[j].x = planes[0].x;
|
|
planes[0].missiles[j].y = planes[0].y;
|
|
planes[0].missiles[j].dir = planes[0].dir; // the missile take the direction of the plane
|
|
|
|
j = j + 1;
|
|
|
|
if(j >= MAX_MISSILES)
|
|
{
|
|
j = 0;
|
|
}
|
|
|
|
fire = 0; // fire disable, shoot one by one // this code line will depend if we shoot in continue
|
|
}
|
|
}
|
|
}
|