213 lines
5.0 KiB
C
Executable File
213 lines
5.0 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"
|
|
|
|
#define MAP_SIZE_X 256
|
|
#define MAP_SIZE_Y 256
|
|
|
|
#define MAX_PLANES 2
|
|
#define MAX_CLOUDS 15
|
|
|
|
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 missile;
|
|
|
|
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].life = 100;
|
|
planes[i].bullets = 6;
|
|
planes[i].dir.dx = i;
|
|
planes[i].dir.dy = i;
|
|
|
|
for(j = 0; j < MAX_MISSILES; j++)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
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(Direction *map_dir)
|
|
{
|
|
static unsigned char i,j;
|
|
|
|
dclear();
|
|
|
|
dprint(1, 1, "s:%d l:%d", planes[0].bullets, planes[0].life);
|
|
dprint(1, 10, "(%d,%d)", map_dir->dx, map_dir->dy);
|
|
//dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly);
|
|
|
|
for(i = 0; i < MAX_CLOUDS; i++)
|
|
{
|
|
clouds[i].x += map_dir->dx;
|
|
clouds[i].y += map_dir->dy;
|
|
dimage(clouds[i].x, clouds[i].y, &cloud);
|
|
}
|
|
|
|
for (i = 0; i < MAX_PLANES; i++)
|
|
{
|
|
if(i > 0)
|
|
{
|
|
planes[i].x += map_dir->dx + planes[i].dir.dx;
|
|
planes[i].y += map_dir->dy + 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 < MAX_MISSILES; j++)
|
|
{
|
|
planes[i].missiles[j].x += map_dir->dx - 2 * planes[i].missiles[j].dir.dx;
|
|
planes[i].missiles[j].y += map_dir->dy - 2 * planes[i].missiles[j].dir.dy;
|
|
|
|
dimage_part(planes[i].missiles[j].x, planes[i].missiles[j].y ,&missile, 8 * (1 - planes[i].missiles[j].dir.dx), 8 * (1 - planes[i].missiles[j].dir.dy), 8, 8);
|
|
}
|
|
}
|
|
dupdate();
|
|
}
|
|
|
|
int game()
|
|
{
|
|
unsigned char fire = 0, j = 0; // fire disable
|
|
|
|
//direction for the map
|
|
Direction map_dir, dir_requested;
|
|
|
|
init();
|
|
|
|
timer_t *timer = NULL;
|
|
timer = timer_create(40, 0);
|
|
timer_attach(timer, update_frame, &map_dir);
|
|
timer_start(timer);
|
|
|
|
event_t events;
|
|
|
|
map_dir.dx = dir_requested.dx = 0;
|
|
map_dir.dy = dir_requested.dy = 0;
|
|
|
|
while(1)
|
|
{
|
|
events = waitevent();
|
|
|
|
if(events.type >= event_key_press && events.type <= event_key_release)
|
|
{
|
|
switch(events.key.code)
|
|
{
|
|
case KEY_UP :
|
|
{
|
|
dir_requested.dy += 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_DOWN :
|
|
{
|
|
dir_requested.dy -= 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_LEFT :
|
|
{
|
|
dir_requested.dx += 3 - events.type;
|
|
break;
|
|
}
|
|
case KEY_RIGHT :
|
|
{
|
|
dir_requested.dx -= 3 - events.type;
|
|
break;
|
|
}
|
|
|
|
case KEY_SHIFT :
|
|
{
|
|
|
|
fire = 1;
|
|
/*if(planes[0].bullets > 0)
|
|
{
|
|
planes[0].bullets = planes[0].bullets - 1;
|
|
fire = 1;
|
|
}*/
|
|
break; // fire enable
|
|
}
|
|
|
|
case KEY_EXIT :
|
|
{
|
|
timer_destroy(timer); //destroy the virtual timer
|
|
return 1; // good bye, see you soon
|
|
}
|
|
}
|
|
}
|
|
|
|
if(dir_requested.dx != 0 || dir_requested.dy != 0)
|
|
{
|
|
map_dir = dir_requested;
|
|
planes[0].dir = dir_requested;
|
|
}
|
|
|
|
if(fire)
|
|
{
|
|
planes[0].missiles[0].dir = planes[0].dir;
|
|
|
|
planes[0].missiles[0].x = 60 - 6 * planes[0].missiles[0].dir.dx;
|
|
planes[0].missiles[0].y = 28 - 6 * planes[0].missiles[0].dir.dy;
|
|
|
|
fire = 0;
|
|
}
|
|
}
|
|
}
|