This commit is contained in:
flo 2017-04-19 22:43:18 +02:00
parent a8b0d57dd1
commit 0bbb013e75
2 changed files with 62 additions and 30 deletions

View File

@ -1,13 +1,31 @@
#ifndef WINGS
#define WINGS
typedef struct Missile
{
unsigned char dir;
short x[4];
short y[4];
} Missile;
typedef struct Plane
{
short x;
short y;
unsigned char dir;
/* plane direction management
7 0 1
6 plane 2
5 4 3
*/
unsigned char life;
struct Missile missiles;
// align
} Plane;
#endif

View File

@ -12,19 +12,13 @@
#define SIZE_MAP_Y 512
#define MAX_PLANES 3
Plane planes[MAX_PLANES]; // number of planes in the map except us
//planes are controlled by the AI
Plane planes[MAX_PLANES]; // number of planes in the map (with us)
//others planes are controlled by the AI
extern image_t plane;
extern image_t img_menu;
extern image_t cloud;
/* plane direction
7 0 1
6 plane 2
5 4 3
*/
int main()
{
menu();
@ -35,7 +29,12 @@ void init()
{
unsigned char i;
for(i = 0; i < MAX_PLANES; i++)
planes[0].x = 56;
planes[0].y = 24;
planes[0].dir = 0;
planes[0].life = 100;
for(i = 1; i < MAX_PLANES; i++)
{
planes[i].x = 10 + 16 * i;
planes[i].y = 12;
@ -76,17 +75,14 @@ void menu()
}
}
void update_frame(unsigned int *dir)
void update_frame()
{
static unsigned char i;
static short decalx = 0, decaly = 0;
static int count = 0;
gclear();
gimage_part(56, 24, &plane, 16*(*dir), 0, 16, 16); // our plane
switch(*dir)
switch(planes[0].dir)
{
case 0 : decaly++; break;
case 1 : decalx--; decaly++; break;
@ -98,34 +94,46 @@ void update_frame(unsigned int *dir)
case 7 : decalx++; decaly++; break;
}
gimage_part(planes[0].x, planes[0].y, &plane, 16*planes[0].dir, 0, 16, 16);
for(i = 0; i < MAX_PLANES; i++)
for(i = 1; i < MAX_PLANES; i++)
{
gimage_part(planes[i].x + decalx, planes[i].y + decaly, &plane, 16*planes[i].dir, 0, 16, 16);
}
for (i = 0; i < MAX_PLANES; i++)
{
for(j = 0; j < MAX_MISSILES; j++)
{
if(planes[i].missile.distance[j] > 0) // we load the missile to reach the target
{
//gline(plane[0].x, plane[0].y, )
}
}
}
gimage(10 + decalx, 10 + decaly, &cloud);
gupdate();
count++;
}
int game()
{
int dir = 0;
//int dir = 0;
unsigned char fire = 0; // fire disable
unsigned char sum = 0;
int *keys = NULL;
int keys[3];
unsigned char i;
timer_t *timer = NULL;
timer = timer_create(40, 0);
timer_attach(timer, update_frame, &dir);
timer_attach(timer, update_frame, NULL);
timer_start(timer);
gray_start(); // gray engine running
@ -133,7 +141,7 @@ int game()
while(1)
{
multigetkey(keys, 3, 500);
multigetkey(keys, 3, 0);
sum = 0;
@ -150,7 +158,7 @@ int game()
case KEY_EXIT :
{
gray_stop(); // gray engine stopped
timer_stop(timer); //virtual timer stopped
timer_stop(timer); // virtual timer stopped
return 1; // good bye, see you soon
}
}
@ -160,14 +168,20 @@ int game()
switch(sum)
{
case KEY_UP : dir = 0; break;
case KEY_UP + KEY_RIGHT : dir = 1; break;
case KEY_RIGHT : dir = 2; break;
case KEY_DOWN + KEY_RIGHT : dir = 3; break;
case KEY_DOWN : dir = 4; break;
case KEY_DOWN + KEY_LEFT : dir = 5;break;
case KEY_LEFT : dir = 6; break;
case KEY_UP + KEY_LEFT : dir = 7; break;
case KEY_UP : planes[0].dir = 0; break;
case KEY_UP + KEY_RIGHT : planes[0].dir = 1; break;
case KEY_RIGHT : planes[0].dir = 2; break;
case KEY_DOWN + KEY_RIGHT : planes[0].dir = 3; break;
case KEY_DOWN : planes[0].dir = 4; break;
case KEY_DOWN + KEY_LEFT : planes[0].dir = 5;break;
case KEY_LEFT : planes[0].dir = 6; break;
case KEY_UP + KEY_LEFT : planes[0].dir = 7; break;
}
if(fire) // put the screen on fire !
{
planes.missiles.dir = planes[0].dir;
planes[0].missiles.distance[j] = 1; // fire unlimited
}
}
}