wings/src/wings.c

273 lines
7.8 KiB
C
Raw Permalink Normal View History

2017-04-17 16:55:21 +02:00
#include "wings.h"
#include "display.h" // bopti.h => images // tales.h => fonts
#include "keyboard.h"
2017-04-18 21:46:27 +02:00
#include "timer.h"
2017-07-30 15:20:33 +02:00
#include "events.h"
2017-04-18 21:46:27 +02:00
2017-04-17 16:55:21 +02:00
#include "stdio.h"
#include "stdlib.h"
2017-04-19 22:43:18 +02:00
Plane planes[MAX_PLANES]; // number of planes in the map (with us)
//others planes are controlled by the AI
2017-04-18 21:46:27 +02:00
2017-04-30 18:09:11 +02:00
Cloud clouds[MAX_CLOUDS]; //number of clouds in this beautifull sky
// generated by the IA
2017-08-04 20:55:49 +02:00
Weapon weapon[MAX_WEAPON]; // numbre of weapon changing in the sky (fall)
2017-04-17 16:55:21 +02:00
extern image_t plane;
2017-04-18 21:46:27 +02:00
extern image_t img_menu;
2017-04-19 20:30:58 +02:00
extern image_t cloud;
2017-08-04 20:55:49 +02:00
extern image_t firearm;
extern image_t weapons;
2017-04-18 22:03:51 +02:00
2017-04-17 16:55:21 +02:00
int main()
{
2017-04-18 21:46:27 +02:00
menu();
2017-04-17 16:55:21 +02:00
return 1;
}
2017-04-19 20:30:58 +02:00
void init()
{
2017-04-21 22:32:40 +02:00
unsigned char i,j;
2017-04-19 22:43:18 +02:00
2017-04-21 22:32:40 +02:00
for(i = 0; i < MAX_PLANES; i++)
2017-04-19 20:30:58 +02:00
{
2017-08-04 20:55:49 +02:00
planes[i].x = 56;
planes[i].y = 24;
planes[i].dir.dx = 0;
planes[i].dir.dy = 0;
2017-04-19 20:30:58 +02:00
planes[i].life = 100;
2017-08-04 20:55:49 +02:00
planes[i].bullets_nb = MAX_CHARGE;
planes[i].bullets_type = 0;
2017-04-21 22:32:40 +02:00
2017-08-04 20:55:49 +02:00
for(j = 0; j < MAX_CHARGE; j++)
2017-04-21 22:32:40 +02:00
{
2017-08-04 20:55:49 +02:00
planes[i].firearm[j].dir = planes[i].dir;
planes[i].firearm[j].dir.dx = 0;
planes[i].firearm[j].dir.dy = 0;
2017-04-21 22:32:40 +02:00
}
}
2017-04-30 18:09:11 +02:00
for(i = 0; i < MAX_CLOUDS; i++)
2017-04-22 21:02:24 +02:00
{
2017-04-30 18:09:11 +02:00
clouds[i].x = 10 + 16*i;
clouds[i].y = 10 + 16*i;
2017-04-22 21:02:24 +02:00
}
2017-08-04 20:55:49 +02:00
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;
}
2017-04-22 21:02:24 +02:00
}
2017-04-20 22:25:52 +02:00
int menu()
2017-04-17 16:55:21 +02:00
{
2017-04-18 21:46:27 +02:00
unsigned char menu = 0;
2017-04-30 18:09:11 +02:00
2017-04-18 21:46:27 +02:00
while(1)
{
dclear();
dimage(0, 0, &img_menu);
drect(67 + menu * 19, 10 + menu * 27, 100 + menu * 19, 25 + menu * 27, color_invert);
dupdate();
2017-07-30 15:20:33 +02:00
switch(getkey())
2017-04-18 21:46:27 +02:00
{
2017-04-19 20:30:58 +02:00
case KEY_UP : case KEY_DOWN : menu = !menu; break;
2017-04-18 21:46:27 +02:00
case KEY_EXE :
2017-07-30 15:20:33 +02:00
{
if (!menu)
2017-04-18 21:46:27 +02:00
{
2017-07-30 15:20:33 +02:00
game(); break;
2017-04-18 21:46:27 +02:00
}
2017-07-30 15:20:33 +02:00
else return 1;
}
2017-04-18 21:46:27 +02:00
case KEY_EXIT : return 1;
}
}
}
2017-08-04 20:55:49 +02:00
void update_frame(FTCb *info)
2017-04-18 21:46:27 +02:00
{
2017-04-20 12:44:09 +02:00
static unsigned char i,j;
2017-04-19 20:30:58 +02:00
2017-04-20 22:25:52 +02:00
dclear();
2017-04-19 20:30:58 +02:00
2017-08-04 20:55:49 +02:00
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);
2017-04-26 11:25:48 +02:00
//dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly);
2017-04-30 18:37:55 +02:00
2017-08-04 20:55:49 +02:00
if(info->dir_requested.dx != 0 || info->dir_requested.dy != 0)
2017-07-30 16:40:36 +02:00
{
2017-08-04 20:55:49 +02:00
info->map_dir = info->dir_requested;
planes[0].dir = info->dir_requested;
2017-07-30 16:40:36 +02:00
}
2017-04-30 18:09:11 +02:00
for(i = 0; i < MAX_CLOUDS; i++)
{
2017-08-04 20:55:49 +02:00
clouds[i].x += 2 * info->map_dir.dx;
clouds[i].y += 2 * info->map_dir.dy;
2017-04-30 18:09:11 +02:00
dimage(clouds[i].x, clouds[i].y, &cloud);
}
2017-04-19 20:30:58 +02:00
2017-08-04 20:55:49 +02:00
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);
}
2017-04-19 22:43:18 +02:00
for (i = 0; i < MAX_PLANES; i++)
{
2017-04-30 18:37:55 +02:00
if(i > 0)
{
2017-08-04 20:55:49 +02:00
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;
2017-04-30 18:37:55 +02:00
}
2017-08-04 20:55:49 +02:00
dimage_part(planes[i].x, planes[i].y, &plane, 16 * (1 - planes[i].dir.dx), 16 * (1 - planes[i].dir.dy), 16, 16);
2017-07-30 15:20:33 +02:00
2017-08-04 20:55:49 +02:00
for(j = 0; j < info->max_charge; j++)
2017-04-19 22:43:18 +02:00
{
2017-08-04 20:55:49 +02:00
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;
2017-04-20 22:25:52 +02:00
2017-08-04 20:55:49 +02:00
// 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);
2017-04-19 22:43:18 +02:00
}
}
2017-04-20 22:25:52 +02:00
dupdate();
2017-04-18 21:46:27 +02:00
}
2017-04-18 22:03:51 +02:00
int game()
2017-04-18 21:46:27 +02:00
{
2017-08-04 20:55:49 +02:00
unsigned char i = 0; // fire disable
2017-04-19 08:27:56 +02:00
2017-08-04 20:55:49 +02:00
FTCb info;
2017-04-29 16:10:30 +02:00
2017-07-30 15:20:33 +02:00
init();
2017-04-21 22:32:40 +02:00
2017-04-18 21:46:27 +02:00
timer_t *timer = NULL;
2017-08-04 20:55:49 +02:00
timer = timer_create(40, 0);
timer_attach(timer, update_frame, &info);
2017-04-18 21:46:27 +02:00
timer_start(timer);
2017-07-30 15:20:33 +02:00
event_t events;
2017-04-18 21:46:27 +02:00
2017-08-04 20:55:49 +02:00
// variable initialisation
info.map_dir.dx = info.dir_requested.dx = 0;
info.map_dir.dy = info.dir_requested.dy = 0;
info.max_charge = 0;
2017-04-18 21:46:27 +02:00
2017-07-30 15:20:33 +02:00
while(1)
{
events = waitevent();
2017-04-30 18:09:11 +02:00
2017-07-30 15:20:33 +02:00
if(events.type >= event_key_press && events.type <= event_key_release)
2017-04-18 21:46:27 +02:00
{
2017-07-30 15:20:33 +02:00
switch(events.key.code)
2017-04-18 21:46:27 +02:00
{
2017-07-30 15:20:33 +02:00
case KEY_UP :
{
2017-08-04 20:55:49 +02:00
info.dir_requested.dy += 3 - events.type;
2017-07-30 15:20:33 +02:00
break;
}
case KEY_DOWN :
2017-04-18 22:03:51 +02:00
{
2017-08-04 20:55:49 +02:00
info.dir_requested.dy -= 3 - events.type;
2017-07-30 15:20:33 +02:00
break;
}
case KEY_LEFT :
{
2017-08-04 20:55:49 +02:00
info.dir_requested.dx += 3 - events.type;
2017-07-30 15:20:33 +02:00
break;
}
case KEY_RIGHT :
{
2017-08-04 20:55:49 +02:00
info.dir_requested.dx -= 3 - events.type;
2017-04-20 22:25:52 +02:00
break;
2017-04-18 22:03:51 +02:00
}
2017-04-20 22:25:52 +02:00
2017-04-22 21:02:24 +02:00
case KEY_SHIFT :
{
2017-08-04 20:55:49 +02:00
//maybe (if(event.key.release))
switch(planes[0].bullets_type)
2017-04-22 21:02:24 +02:00
{
2017-08-04 20:55:49 +02:00
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;
}
}
2017-07-30 15:20:33 +02:00
break; // fire enable
2017-04-22 21:02:24 +02:00
}
2017-04-19 20:30:58 +02:00
case KEY_EXIT :
{
2017-04-22 21:02:24 +02:00
timer_destroy(timer); //destroy the virtual timer
2017-04-19 20:30:58 +02:00
return 1; // good bye, see you soon
}
2017-08-04 20:55:49 +02:00
case KEY_1 :
{
planes[0].bullets_type = 1;
break;
}
case KEY_0 :
{
planes[0].bullets_type = 0;
break;
}
2017-04-18 21:46:27 +02:00
}
}
}
2017-04-17 16:55:21 +02:00
}