273 lines
7.8 KiB
C
Executable File
273 lines
7.8 KiB
C
Executable File
#include "wings.h"
|
|
|
|
#include "display.h" // bopti.h => images // tales.h => fonts
|
|
#include "keyboard.h"
|
|
#include "timer.h"
|
|
#include "events.h"
|
|
|
|
#include "stdio.h"
|
|
#include "stdlib.h"
|
|
|
|
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
|
|
|
|
Weapon weapon[MAX_WEAPON]; // numbre of weapon changing in the sky (fall)
|
|
|
|
extern image_t plane;
|
|
extern image_t img_menu;
|
|
extern image_t cloud;
|
|
extern image_t firearm;
|
|
extern image_t weapons;
|
|
|
|
int main()
|
|
{
|
|
menu();
|
|
return 1;
|
|
}
|
|
|
|
void init()
|
|
{
|
|
unsigned char i,j;
|
|
|
|
for(i = 0; i < MAX_PLANES; i++)
|
|
{
|
|
planes[i].x = 56;
|
|
planes[i].y = 24;
|
|
planes[i].dir.dx = 0;
|
|
planes[i].dir.dy = 0;
|
|
planes[i].life = 100;
|
|
planes[i].bullets_nb = MAX_CHARGE;
|
|
planes[i].bullets_type = 0;
|
|
|
|
for(j = 0; j < MAX_CHARGE; j++)
|
|
{
|
|
planes[i].firearm[j].dir = planes[i].dir;
|
|
planes[i].firearm[j].dir.dx = 0;
|
|
planes[i].firearm[j].dir.dy = 0;
|
|
}
|
|
}
|
|
|
|
for(i = 0; i < MAX_CLOUDS; i++)
|
|
{
|
|
clouds[i].x = 10 + 16*i;
|
|
clouds[i].y = 10 + 16*i;
|
|
}
|
|
|
|
for(i = 0; i < MAX_WEAPON; i++)
|
|
{
|
|
weapon[i].x = 14 * i + 10;
|
|
weapon[i].y = 0;
|
|
weapon[i].dy = -1;
|
|
weapon[i].type = i%2;
|
|
}
|
|
}
|
|
|
|
int menu()
|
|
{
|
|
unsigned char menu = 0;
|
|
|
|
while(1)
|
|
{
|
|
dclear();
|
|
|
|
dimage(0, 0, &img_menu);
|
|
drect(67 + menu * 19, 10 + menu * 27, 100 + menu * 19, 25 + menu * 27, color_invert);
|
|
|
|
dupdate();
|
|
|
|
switch(getkey())
|
|
{
|
|
case KEY_UP : case KEY_DOWN : menu = !menu; break;
|
|
case KEY_EXE :
|
|
{
|
|
if (!menu)
|
|
{
|
|
game(); break;
|
|
}
|
|
else return 1;
|
|
}
|
|
case KEY_EXIT : return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void update_frame(FTCb *info)
|
|
{
|
|
static unsigned char i,j;
|
|
|
|
dclear();
|
|
|
|
dprint(1, 1, "s:%d l:%d", planes[0].bullets_nb, planes[0].life);
|
|
dprint(1, 10, "(%d,%d) (%d,%d)", info->map_dir.dx, info->map_dir.dy, planes[0].x, planes[0].y);
|
|
//dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly);
|
|
|
|
if(info->dir_requested.dx != 0 || info->dir_requested.dy != 0)
|
|
{
|
|
info->map_dir = info->dir_requested;
|
|
planes[0].dir = info->dir_requested;
|
|
}
|
|
|
|
for(i = 0; i < MAX_CLOUDS; i++)
|
|
{
|
|
clouds[i].x += 2 * info->map_dir.dx;
|
|
clouds[i].y += 2 * info->map_dir.dy;
|
|
|
|
dimage(clouds[i].x, clouds[i].y, &cloud);
|
|
}
|
|
|
|
for(i = 0; i < MAX_WEAPON; i++)
|
|
{
|
|
weapon[i].y += 2 * info->map_dir.dy - weapon[i].dy;
|
|
weapon[i].x += 2 * info->map_dir.dx;
|
|
|
|
if(weapon[i].y > MAP_SIZE_Y)
|
|
{
|
|
weapon[i].y = 0;
|
|
}
|
|
|
|
dimage_part(weapon[i].x, weapon[i].y, &weapons, 10 * weapon[i].type, 0, 10, 10);
|
|
}
|
|
|
|
for (i = 0; i < MAX_PLANES; i++)
|
|
{
|
|
if(i > 0)
|
|
{
|
|
planes[i].x += 2 * info->map_dir.dx - 3 * planes[i].dir.dx;
|
|
planes[i].y += 2 * info->map_dir.dy - 3 * planes[i].dir.dy;
|
|
}
|
|
|
|
dimage_part(planes[i].x, planes[i].y, &plane, 16 * (1 - planes[i].dir.dx), 16 * (1 - planes[i].dir.dy), 16, 16);
|
|
|
|
for(j = 0; j < info->max_charge; j++)
|
|
{
|
|
planes[i].firearm[j].x += 2 * info->map_dir.dx - 4 * planes[i].firearm[j].dir.dx;
|
|
planes[i].firearm[j].y += 2 * info->map_dir.dy - 4 * planes[i].firearm[j].dir.dy;
|
|
|
|
// if one bullet is too far, delete it
|
|
if(abs(planes[i].firearm[j].x - planes[i].x) > 72 || abs(planes[i].firearm[j].y - planes[i].y) > 72)
|
|
{
|
|
info->max_charge--;
|
|
}
|
|
|
|
dimage_part(planes[i].firearm[j].x, planes[i].firearm[j].y ,&firearm, 8 * (1 - planes[i].firearm[j].dir.dx) + 24 * planes[i].bullets_type, 8 * (1 - planes[i].firearm[j].dir.dy), 8, 8);
|
|
}
|
|
}
|
|
dupdate();
|
|
}
|
|
|
|
int game()
|
|
{
|
|
unsigned char i = 0; // fire disable
|
|
|
|
FTCb info;
|
|
|
|
init();
|
|
|
|
timer_t *timer = NULL;
|
|
timer = timer_create(40, 0);
|
|
timer_attach(timer, update_frame, &info);
|
|
timer_start(timer);
|
|
|
|
event_t events;
|
|
|
|
// variable initialisation
|
|
info.map_dir.dx = info.dir_requested.dx = 0;
|
|
info.map_dir.dy = info.dir_requested.dy = 0;
|
|
info.max_charge = 0;
|
|
|
|
while(1)
|
|
{
|
|
events = waitevent();
|
|
|
|
if(events.type >= event_key_press && events.type <= event_key_release)
|
|
{
|
|
switch(events.key.code)
|
|
{
|
|
case KEY_UP :
|
|
{
|
|
info.dir_requested.dy += 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_DOWN :
|
|
{
|
|
info.dir_requested.dy -= 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_LEFT :
|
|
{
|
|
info.dir_requested.dx += 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_RIGHT :
|
|
{
|
|
info.dir_requested.dx -= 3 - events.type;
|
|
break;
|
|
}
|
|
|
|
case KEY_SHIFT :
|
|
{
|
|
//maybe (if(event.key.release))
|
|
switch(planes[0].bullets_type)
|
|
{
|
|
planes[0].bullets_nb = planes[0].bullets_nb - 1;
|
|
case 0 :
|
|
{
|
|
if(planes[0].bullets_nb > 0 && events.type == event_key_release)
|
|
{
|
|
planes[0].firearm[info.max_charge].dir = planes[0].dir;
|
|
planes[0].firearm[info.max_charge].x = 60 - 6 * planes[0].firearm[info.max_charge].dir.dx;
|
|
planes[0].firearm[info.max_charge].y = 28 - 6 * planes[0].firearm[info.max_charge].dir.dy;
|
|
info.max_charge = (info.max_charge < MAX_CHARGE - 1 ? info.max_charge + 1 : 0);
|
|
}
|
|
break;
|
|
}
|
|
case 1 :
|
|
{
|
|
if(events.type == event_key_release)
|
|
{
|
|
for(i = 0; i < ; i++)
|
|
{
|
|
planes[0].firearm[i].dir = planes[0].dir;
|
|
planes[0].firearm[i].x = 60 - 8 * planes[0].firearm[i].dir.dx * i;
|
|
planes[0].firearm[i].y = 28 - 8 * planes[0].firearm[i].dir.dy * i;
|
|
}
|
|
}
|
|
/*else if(events.type == event_key_repeat)
|
|
{
|
|
for(j = 0; j< MAX_CHARGE; j++)
|
|
{
|
|
planes[0].firearm[j].dir.dx = 0;
|
|
planes[0].firearm[j].dir.dy = 0;
|
|
planes[0].firearm[j].x = -256;
|
|
planes[0].firearm[j].y = -256;
|
|
}
|
|
}*/
|
|
break;
|
|
}
|
|
}
|
|
break; // fire enable
|
|
}
|
|
|
|
case KEY_EXIT :
|
|
{
|
|
timer_destroy(timer); //destroy the virtual timer
|
|
return 1; // good bye, see you soon
|
|
}
|
|
case KEY_1 :
|
|
{
|
|
planes[0].bullets_type = 1;
|
|
break;
|
|
}
|
|
case KEY_0 :
|
|
{
|
|
planes[0].bullets_type = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|