diff --git a/include/maths.h b/include/maths.h index a8cdcf2..93984c6 100644 --- a/include/maths.h +++ b/include/maths.h @@ -1,6 +1,9 @@ #ifndef MATHS #define MATHS +float fcos(unsigned char x); +float fsin(unsigned char x); + #define pi 3.14159265358 #define pi_2 1.570796327 #define pi_4 0.78539981635 diff --git a/include/wings.h b/include/wings.h index fb8148d..d05e858 100644 --- a/include/wings.h +++ b/include/wings.h @@ -1,13 +1,14 @@ #ifndef WINGS #define WINGS -#define MAX_MISSILES 8 +#define MAX_MISSILES 2 // missiles management typedef struct Missile { - unsigned char dir[MAX_MISSILES]; - short distance[MAX_MISSILES]; // distance between the plane and the missile + unsigned char dir; + short distance; // distance between the plane and the missile + unsigned char type; } Missile; // plane management @@ -24,8 +25,9 @@ typedef struct Plane */ unsigned char life; + unsigned char reload; - struct Missile missiles; + Missile missiles[MAX_MISSILES]; // align } Plane; diff --git a/obj/cloud.bmp.o b/obj/cloud.bmp.o new file mode 100644 index 0000000..0bdfb15 Binary files /dev/null and b/obj/cloud.bmp.o differ diff --git a/obj/img_menu.bmp.o b/obj/img_menu.bmp.o new file mode 100644 index 0000000..5d0e665 Binary files /dev/null and b/obj/img_menu.bmp.o differ diff --git a/obj/maths.c.o b/obj/maths.c.o new file mode 100644 index 0000000..61118d0 Binary files /dev/null and b/obj/maths.c.o differ diff --git a/obj/missiles.bmp.o b/obj/missiles.bmp.o new file mode 100644 index 0000000..1c4c170 Binary files /dev/null and b/obj/missiles.bmp.o differ diff --git a/obj/plane.bmp.o b/obj/plane.bmp.o new file mode 100644 index 0000000..cf103a5 Binary files /dev/null and b/obj/plane.bmp.o differ diff --git a/obj/wings.c.o b/obj/wings.c.o new file mode 100644 index 0000000..b342e93 Binary files /dev/null and b/obj/wings.c.o differ diff --git a/src/maths.c b/src/maths.c index 37d81ba..f4a3bca 100644 --- a/src/maths.c +++ b/src/maths.c @@ -1,5 +1,20 @@ #include "maths.h" +//get the value of sin/cos(dir * pi_4) + +float fcos(unsigned char x) +{ + float cos[4] = {1.0, 0.707106, 0.0, -0.707106}; + + return (x < 4 ? cos[x] : - cos[x%4]); +} + +float fsin(unsigned char x) +{ + return fcos(x - 2); +} + + #define MAX_TURN 6 float cos(float x) diff --git a/src/wings.c b/src/wings.c index 116b74e..4800b42 100644 --- a/src/wings.c +++ b/src/wings.c @@ -13,7 +13,6 @@ #define SIZE_MAP_Y 256 #define MAX_PLANES 3 -#define MAX_MISSILES 8 Plane planes[MAX_PLANES]; // number of planes in the map (with us) //others planes are controlled by the AI @@ -31,19 +30,32 @@ int main() void init() { - unsigned char i; + unsigned char i,j; - planes[0].x = 56; - planes[0].y = 24; - planes[0].dir = 0; - planes[0].life = 100; + for(i = 0; i < MAX_PLANES; i++) + { + planes[i].x = 56 + 16 * i; + planes[i].y = 24 + i; + planes[i].dir = i; + planes[i].life = 100; + planes[i].reload = 6; + + for(j = 0; j < MAX_MISSILES; j++) + { + planes[i].missiles[j].distance = 0; + planes[i].missiles[j].dir = planes[i].dir; + planes[i].missiles[j].type = 0; + } + } +} + +void AI() // iA start +{ + unsigned char i; 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; + } } @@ -99,21 +111,14 @@ void *update_frame() case 7 : decalx--; decaly--; break; } - if(decalx < - SIZE_MAP_X || decalx > SIZE_MAP_X || decaly < - SIZE_MAP_Y || decaly > SIZE_MAP_Y) - { - dtext(1, 10, "You are going to dead"); - } + dimage_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 > 0 || planes[i].x + decalx < 128 || planes[i].y + decaly > 0 || planes[i].y + decaly < 64) - { - //dimage_part(planes[i].x + decalx, planes[i].y + decaly, &plane, 16*planes[i].dir, 0, 16, 16); - } + // dimage_part(planes[i].x + decalx, planes[i].y + decaly, &plane, 16*planes[i].dir, 0, 16, 16); + dimage(planes[i].x + decalx, planes[i].y + decaly, &plane); } dimage(10 + decalx, 10 + decaly, &cloud); @@ -122,15 +127,11 @@ void *update_frame() { for(j = 0; j < MAX_MISSILES; j++) { + dimage_part(planes[i].x + 4 + (planes[i].missiles[j].distance + 15) * fcos(planes[i].missiles[j].dir), + planes[i].y + 4 - (planes[i].missiles[j].distance + 15) * fsin(planes[i].missiles[j].dir), + &missiles, 8 * planes[i].missiles[j].dir, 0, 8, 8); - //if(planes[i].missiles.distance[j] > 0) // we load the missile to reach the target - // { - dimage_part(planes[i].x + 4 + (planes[i].missiles.distance[j] + 15) * cos(planes[i].missiles.dir[j] * pi_4), - planes[i].y + 4 - (planes[i].missiles.distance[j] + 15) * sin(planes[i].missiles.dir[j] * pi_4), - &missiles, 8 * planes[i].missiles.dir[j], 0, 8, 8); - - planes[i].missiles.distance[j]++; - // } + planes[i].missiles[j].distance++; } } @@ -149,13 +150,15 @@ int game() j = 0; + init(); // initialisation + timer_t *timer = NULL; timer = timer_create(40, 0); timer_attach(timer, &update_frame, NULL); timer_start(timer); - init(); // initialisation + while(1) { @@ -230,6 +233,9 @@ int game() if(fire) // put the screen on fire ! { + planes[0].missiles[j].dir = planes[0].dir; // the missile take the direction of the plane + planes[0].missiles[j].distance = 0; // fire unlimited (nearly) + j = j + 1; if(j >= MAX_MISSILES) @@ -237,8 +243,6 @@ int game() j = 0; } - planes[0].missiles.dir[j] = planes[0].dir; - planes[0].missiles.distance[j] = 0; // fire unlimited (nearly) fire = 0; // fire disable, shoot one by one // this code line will depend if we shoot in continue } } diff --git a/wings.bin b/wings.bin new file mode 100755 index 0000000..251ee31 Binary files /dev/null and b/wings.bin differ diff --git a/wings.elf b/wings.elf new file mode 100755 index 0000000..34d4907 Binary files /dev/null and b/wings.elf differ diff --git a/wings.g1a b/wings.g1a new file mode 100644 index 0000000..053566e Binary files /dev/null and b/wings.g1a differ