wings/src/wings.c

174 lines
3.7 KiB
C
Raw 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-04-19 20:30:58 +02:00
#include "gray.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 20:30:58 +02:00
#define SIZE_MAP_X 512
#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
2017-04-18 21:46:27 +02:00
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-04-18 22:03:51 +02:00
/* plane direction
2017-04-18 21:46:27 +02:00
7 0 1
6 plane 2
5 4 3
*/
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()
{
unsigned char i;
for(i = 0; i < MAX_PLANES; i++)
{
planes[i].x = 10 + 16 * i;
planes[i].y = 12;
planes[i].dir = i;
planes[i].life = 100;
}
}
2017-04-17 16:55:21 +02:00
void menu()
{
2017-04-18 21:46:27 +02:00
unsigned char menu = 0;
unsigned int key = 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();
key = getkey();
switch (key)
{
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-04-18 22:03:51 +02:00
if (!menu)
2017-04-18 21:46:27 +02:00
{
2017-04-18 22:03:51 +02:00
game(); break;
2017-04-18 21:46:27 +02:00
}
else return 1;
}
case KEY_EXIT : return 1;
}
}
}
2017-04-19 20:30:58 +02:00
void update_frame(unsigned int *dir)
2017-04-18 21:46:27 +02:00
{
2017-04-19 20:30:58 +02:00
static unsigned char i;
2017-04-19 21:38:38 +02:00
static short decalx = 0, decaly = 0;
2017-04-19 20:30:58 +02:00
static int count = 0;
gclear();
gimage_part(56, 24, &plane, 16*(*dir), 0, 16, 16); // our plane
switch(*dir)
{
case 0 : decaly++; break;
case 1 : decalx--; decaly++; break;
case 2 : decalx--; break;
case 3 : decalx--; decaly--; break;
case 4 : decaly--; break;
2017-04-19 21:38:38 +02:00
case 5 : decalx++; decaly--; break;
2017-04-19 20:30:58 +02:00
case 6 : decalx++; break;
case 7 : decalx++; decaly++; break;
}
2017-04-19 21:38:38 +02:00
2017-04-19 20:30:58 +02:00
for(i = 0; i < MAX_PLANES; i++)
{
gimage_part(planes[i].x + decalx, planes[i].y + decaly, &plane, 16*planes[i].dir, 0, 16, 16);
}
2017-04-19 21:38:38 +02:00
gimage(10 + decalx, 10 + decaly, &cloud);
2017-04-19 20:30:58 +02:00
gupdate();
count++;
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-04-19 08:27:56 +02:00
2017-04-18 21:46:27 +02:00
int dir = 0;
2017-04-19 20:30:58 +02:00
2017-04-18 21:46:27 +02:00
unsigned char fire = 0; // fire disable
2017-04-19 20:30:58 +02:00
unsigned char sum = 0;
2017-04-19 08:27:56 +02:00
2017-04-18 21:46:27 +02:00
int *keys = NULL;
2017-04-19 08:27:56 +02:00
2017-04-18 21:46:27 +02:00
unsigned char i;
timer_t *timer = NULL;
timer = timer_create(40, 0);
timer_attach(timer, update_frame, &dir);
timer_start(timer);
2017-04-19 20:30:58 +02:00
gray_start(); // gray engine running
init(); // initialisation
2017-04-18 21:46:27 +02:00
while(1)
{
2017-04-19 20:30:58 +02:00
multigetkey(keys, 3, 500);
2017-04-18 21:46:27 +02:00
2017-04-18 22:03:51 +02:00
sum = 0;
2017-04-18 21:46:27 +02:00
for(i = 0; i < 3; i++)
{
2017-04-18 22:03:51 +02:00
switch(keys[i])
2017-04-18 21:46:27 +02:00
{
2017-04-18 22:03:51 +02:00
case KEY_UP : case KEY_DOWN : case KEY_LEFT : case KEY_RIGHT :
{
2017-04-19 08:27:56 +02:00
sum += keys[i]; // to know which replay keys pressed
2017-04-18 22:03:51 +02:00
}
break;
2017-04-19 08:27:56 +02:00
case KEY_SHIFT : fire = 1; break; // fire enable
2017-04-19 20:30:58 +02:00
case KEY_EXIT :
{
gray_stop(); // gray engine stopped
timer_stop(timer); //virtual timer stopped
return 1; // good bye, see you soon
}
2017-04-18 21:46:27 +02:00
}
}
2017-04-18 22:03:51 +02:00
/* we determine the direction of the plane*/
2017-04-18 21:46:27 +02:00
switch(sum)
{
case KEY_UP : dir = 0; break;
2017-04-19 20:30:58 +02:00
case KEY_UP + KEY_RIGHT : dir = 1; break;
2017-04-19 08:27:56 +02:00
case KEY_RIGHT : dir = 2; break;
2017-04-19 20:30:58 +02:00
case KEY_DOWN + KEY_RIGHT : dir = 3; break;
2017-04-19 08:27:56 +02:00
case KEY_DOWN : dir = 4; break;
2017-04-19 20:30:58 +02:00
case KEY_DOWN + KEY_LEFT : dir = 5;break;
2017-04-19 08:27:56 +02:00
case KEY_LEFT : dir = 6; break;
2017-04-19 20:30:58 +02:00
case KEY_UP + KEY_LEFT : dir = 7; break;
2017-04-18 21:46:27 +02:00
}
}
2017-04-17 16:55:21 +02:00
}