This commit is contained in:
flo 2017-04-30 18:09:11 +02:00
parent 9dc720aff7
commit d2707857d4
2 changed files with 72 additions and 74 deletions

View File

@ -31,8 +31,21 @@ typedef struct Plane
// align
} Plane;
typedef struct Cloud
{
short x;
short y;
} Cloud;
typedef enum Type
{
dX = 0,
dY = 2,
} Type;
int menu(void);
void init(void);
char get_decal(unsigned char dir, Type type);
void *update_frame(void);
int game(void);

View File

@ -13,10 +13,14 @@
#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;
@ -47,31 +51,39 @@ void init()
planes[i].missiles[j].type = 0;
}
}
}
void infos()
{
unsigned int key = 0;
while(key != KEY_SHIFT)
for(i = 0; i < MAX_CLOUDS; i++)
{
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();
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();
@ -99,41 +111,49 @@ int menu()
}
}
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;
static char decalx, decaly;
dclear();
dprint(1, 1, "s:%d l:%d", planes[0].reload, planes[0].life);
dprint(1, 10, "(%d,%d)", decalx, decaly);
decalx = decaly = 0;
switch(planes[0].dir)
{
case 0 : case 1 : decalx = -1; decaly = planes[0].dir ;break;
case 2 : decaly = 1; break;
case 3 : case 4 : case 5 : decalx = 1; decaly = 4 - planes[0].dir; break;
case 6 : decaly = -1; break;
case 7 : decalx = -1; decaly = -1; break;
}
//dprint(1, 20, "(%d,%d)", get_decal(planes[0].dir, dX), get_decal(planes[0].dir, dY));
for(i = 0; i < MAX_PLANES; i++)
{
if(i > 0)
{
planes[i].x += decalx;
planes[i].y += decaly;
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);
}
//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);
}
dimage(10 + decalx, 10 + decaly, &cloud);
for (i = 0; i < MAX_PLANES; i++)
{
@ -148,7 +168,6 @@ void *update_frame()
}
dupdate();
return;
}
#define MAX_KEYS 4
@ -158,6 +177,7 @@ 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];
@ -180,18 +200,17 @@ int game()
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]; // to know which replay keys pressed
sum += keys[i];
break;
}
case
case KEY_SHIFT :
{
if(planes[0].reload > 0)
@ -224,51 +243,17 @@ int game()
// we determine the direction of the plane
switch(sum)
for(i = 0; i < 8; i++)
{
case KEY_RIGHT :
if(sum == sum_keys[i])
{
planes[0].dir = 0;
break;
}
case KEY_UP + KEY_RIGHT :
{
planes[0].dir = 1;
break;
}
case KEY_UP :
{
planes[0].dir = 2;
break;
}
case KEY_UP + KEY_LEFT :
{
planes[0].dir = 3;
break;
}
case KEY_LEFT :
{
planes[0].dir = 4;
break;
}
case KEY_DOWN + KEY_LEFT :
{
planes[0].dir = 5;
break;
}
case KEY_DOWN :
{
planes[0].dir = 6;
break;
}
case KEY_DOWN + KEY_RIGHT :
{
planes[0].dir = 7;
planes[0].dir = i;
break;
}
}
if(fire) // put the screen on fire !
if(fire == 1) // put the screen on fire !
{
planes[0].missiles[j].dir = planes[0].dir; // the missile take the direction of the plane
planes[0].missiles[j].distance = 0; // fire unlimited (nearly)