#include "wings.h" #include "maths.h" #include "display.h" // bopti.h => images // tales.h => fonts #include "keyboard.h" #include "timer.h" #include "gray.h" #include "stdio.h" #include "stdlib.h" #define SIZE_MAP_X 256 #define SIZE_MAP_Y 256 #define MAX_PLANES 3 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; int main() { menu(); return 1; } void init() { unsigned char 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 + i; planes[i].dir = i; planes[i].life = 100; } } void menu() { 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) { 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() { static unsigned char i,j; static short decalx = 0; static short decaly = 0; gclear(); switch(planes[0].dir) { case 0 : decalx--; break; case 1 : decalx--; decaly++; break; case 2 : decaly++; break; case 3 : decalx++; decaly++; break; case 4 : decalx++; break; case 5 : decalx++; decaly--; break; case 6 : decaly--; break; case 7 : decalx--; decaly--; break; } if(decalx < - SIZE_MAP_X || decalx > SIZE_MAP_X || decaly < - SIZE_MAP_Y || decaly > SIZE_MAP_Y) { gtext(10, 10, "You are going to dead"); } gimage_part(planes[0].x, planes[0].y, &plane, 16*planes[0].dir, 0, 16, 16); for(i = 1; i < MAX_PLANES; i++) { // print condition if(planes[i].x + decalx > -16 || planes[i].x + decalx < 144 || planes[i].y + decaly > -16 || planes[i].y + decaly < 80) { gimage_part(planes[i].x + decalx, planes[i].y + decaly, &plane, 16*planes[i].dir, 0, 16, 16); } } gimage(10 + decalx, 10 + decaly, &cloud); for (i = 0; i < MAX_PLANES; i++) { for(j = 0; j < MAX_MISSILES; j++) { if(planes[i].missiles.distance[j] > 0) // we load the missile to reach the target { gpixel(planes[i].x + 8 + planes[i].missiles.distance[j] * cos(planes[i].missiles.dir[j] * pi_4), planes[i].y + 8 - planes[i].missiles.distance[j] * sin(planes[i].missiles.dir[j] * pi_4), color_black); planes[i].missiles.distance[j]++; } } } gupdate(); } int game() { //int dir = 0; unsigned char fire = 0; // fire disable unsigned char sum = 0; int keys[3]; unsigned char i,j = 0; timer_t *timer = NULL; timer = timer_create(40, 0); timer_attach(timer, update_frame, NULL); timer_start(timer); gray_start(); // gray engine running init(); // initialisation while(1) { multigetkey(keys, 3, 0); sum = 0; for(i = 0; i < 3; i++) { switch(keys[i]) { case KEY_UP : case KEY_DOWN : case KEY_LEFT : case KEY_RIGHT : { sum += keys[i]; // to know which replay keys pressed } break; case KEY_SHIFT : fire = 1; break; // fire enable case KEY_EXIT : { gray_stop(); // gray engine stopped timer_stop(timer); // virtual timer stopped return 1; // good bye, see you soon } } } // we determine the direction of the plane switch(sum) { case KEY_RIGHT : planes[0].dir = 0; break; case KEY_UP + KEY_RIGHT : planes[0].dir = 1; break; case KEY_UP : planes[0].dir = 2; break; case KEY_UP + KEY_LEFT : planes[0].dir = 3; break; case KEY_LEFT : planes[0].dir = 4; break; case KEY_DOWN + KEY_LEFT : planes[0].dir = 5;break; case KEY_DOWN : planes[0].dir = 6; break; case KEY_DOWN + KEY_RIGHT : planes[0].dir = 7; break; } if(fire) // put the screen on fire ! { planes[0].missiles.dir[j] = planes[0].dir; planes[0].missiles.distance[j] = 12; // fire unlimited (nearly) j = (j < MAX_MISSILES ? j + 1 : 0); fire = 0; // fire disable, shoot one by one // this code line will depend if we shoot in continue } } }