diff --git a/img/firearm.bmp b/img/firearm.bmp new file mode 100755 index 0000000..5612b9d Binary files /dev/null and b/img/firearm.bmp differ diff --git a/img/missile.bmp b/img/missile.bmp deleted file mode 100755 index ec070f5..0000000 Binary files a/img/missile.bmp and /dev/null differ diff --git a/img/weapons.bmp b/img/weapons.bmp new file mode 100755 index 0000000..0562943 Binary files /dev/null and b/img/weapons.bmp differ diff --git a/include/wings.h b/include/wings.h index 3166f16..dd7a3c7 100755 --- a/include/wings.h +++ b/include/wings.h @@ -1,7 +1,13 @@ #ifndef WINGS #define WINGS -#define MAX_MISSILES 4 +#define MAX_CHARGE 40 +#define MAX_PLANES 7 +#define MAX_CLOUDS 15 +#define MAX_WEAPON 3 + +#define MAP_SIZE_X 256 +#define MAP_SIZE_Y 256 // direction management typedef struct Direction @@ -10,15 +16,15 @@ typedef struct Direction char dy; } Direction; -// missiles management -typedef struct Missile +// Arms management +typedef struct Firearm { short x; short y; Direction dir; + char useful; // short distance; // distance between the plane and the missile - unsigned char type; -} Missile; +} Firearm; // plane management typedef struct Plane @@ -35,9 +41,12 @@ typedef struct Plane */ unsigned char life; - unsigned char bullets; + unsigned char bullets_nb; + unsigned char bullets_type; + // 0 : missiles + // 1 : lightning - Missile missiles[MAX_MISSILES]; + Firearm firearm[MAX_CHARGE]; // align } Plane; @@ -47,15 +56,25 @@ typedef struct Cloud short y; } Cloud; -typedef struct Dir_t +//for timer callback +typedef struct FTCb { Direction map_dir; Direction dir_requested; -} Dir_t; + unsigned char max_charge; +} FTCb; + +typedef struct Weapon +{ + short x; + short y; + char dy; + char type; +} Weapon; int menu(void); void init(void); -void update_frame(Dir_t *way); +void update_frame(FTCb *info); int game(void); #endif diff --git a/obj/cloud.bmp.o b/obj/cloud.bmp.o new file mode 100755 index 0000000..0bdfb15 Binary files /dev/null and b/obj/cloud.bmp.o differ diff --git a/obj/firearm.bmp.o b/obj/firearm.bmp.o new file mode 100755 index 0000000..41f5e27 Binary files /dev/null and b/obj/firearm.bmp.o differ diff --git a/obj/img_menu.bmp.o b/obj/img_menu.bmp.o new file mode 100755 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 100755 index 0000000..e1d7802 Binary files /dev/null and b/obj/maths.c.o differ diff --git a/obj/plane.bmp.o b/obj/plane.bmp.o new file mode 100755 index 0000000..71f1501 Binary files /dev/null and b/obj/plane.bmp.o differ diff --git a/obj/weapons.bmp.o b/obj/weapons.bmp.o new file mode 100755 index 0000000..18cfe41 Binary files /dev/null and b/obj/weapons.bmp.o differ diff --git a/obj/wings.c.o b/obj/wings.c.o new file mode 100755 index 0000000..73e6188 Binary files /dev/null and b/obj/wings.c.o differ diff --git a/src/wings.c b/src/wings.c index 28189f2..c068d83 100755 --- a/src/wings.c +++ b/src/wings.c @@ -8,22 +8,19 @@ #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 +Weapon weapon[MAX_WEAPON]; // numbre of weapon changing in the sky (fall) + extern image_t plane; extern image_t img_menu; extern image_t cloud; -extern image_t missile; +extern image_t firearm; +extern image_t weapons; int main() { @@ -37,17 +34,19 @@ void init() for(i = 0; i < MAX_PLANES; i++) { - planes[i].x = 56 + 16 * i; - planes[i].y = 24 + i; + planes[i].x = 56; + planes[i].y = 24; + planes[i].dir.dx = 0; + planes[i].dir.dy = 0; planes[i].life = 100; - planes[i].bullets = 6; - planes[i].dir.dx = i; - planes[i].dir.dy = i; + planes[i].bullets_nb = MAX_CHARGE; + planes[i].bullets_type = 0; - for(j = 0; j < MAX_MISSILES; j++) + for(j = 0; j < MAX_CHARGE; j++) { - planes[i].missiles[j].dir = planes[i].dir; - planes[i].missiles[j].type = 0; + planes[i].firearm[j].dir = planes[i].dir; + planes[i].firearm[j].dir.dx = 0; + planes[i].firearm[j].dir.dy = 0; } } @@ -56,6 +55,14 @@ void init() clouds[i].x = 10 + 16*i; clouds[i].y = 10 + 16*i; } + + 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; + } } int menu() @@ -87,45 +94,65 @@ int menu() } } -void update_frame(Dir_t *way) +void update_frame(FTCb *info) { static unsigned char i,j; dclear(); - dprint(1, 1, "s:%d l:%d", planes[0].bullets, planes[0].life); - dprint(1, 10, "(%d,%d)", way->map_dir.dx, way->map_dir.dy); + 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); //dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly); - if(way->dir_requested.dx != 0 || way->dir_requested.dy != 0) + if(info->dir_requested.dx != 0 || info->dir_requested.dy != 0) { - way->map_dir = way->dir_requested; - planes[0].dir = way->dir_requested; + info->map_dir = info->dir_requested; + planes[0].dir = info->dir_requested; } for(i = 0; i < MAX_CLOUDS; i++) { - clouds[i].x += way->map_dir.dx; - clouds[i].y += way->map_dir.dy; + clouds[i].x += 2 * info->map_dir.dx; + clouds[i].y += 2 * info->map_dir.dy; + dimage(clouds[i].x, clouds[i].y, &cloud); } + 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); + } + for (i = 0; i < MAX_PLANES; i++) { if(i > 0) { - planes[i].x += way->map_dir.dx - planes[i].dir.dx; - planes[i].y += way->map_dir.dy - planes[i].dir.dy; + 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; } - dimage_part(planes[i].x, planes[i].y, &plane, 16*(1 - planes[i].dir.dx), 16 * (1 - planes[i].dir.dy), 16, 16); + 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++) + for(j = 0; j < info->max_charge; j++) { - planes[i].missiles[j].x += way->map_dir.dx - 2 * planes[i].missiles[j].dir.dx; - planes[i].missiles[j].y += way->map_dir.dy - 2 * planes[i].missiles[j].dir.dy; + 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; - 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); + // 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); } } dupdate(); @@ -133,22 +160,23 @@ void update_frame(Dir_t *way) int game() { - unsigned char fire = 0, j = 0; // fire disable + unsigned char i = 0; // fire disable - //direction for the map - Dir_t way; + FTCb info; init(); timer_t *timer = NULL; - timer = timer_create(50, 0); - timer_attach(timer, update_frame, &way); + timer = timer_create(40, 0); + timer_attach(timer, update_frame, &info); timer_start(timer); event_t events; - way.map_dir.dx = way.dir_requested.dx = 0; - way.map_dir.dy = way.dir_requested.dy = 0; + // variable initialisation + info.map_dir.dx = info.dir_requested.dx = 0; + info.map_dir.dy = info.dir_requested.dy = 0; + info.max_charge = 0; while(1) { @@ -160,34 +188,66 @@ int game() { case KEY_UP : { - way.dir_requested.dy += 3 - events.type; + info.dir_requested.dy += 3 - events.type; break; } case KEY_DOWN : { - way.dir_requested.dy -= 3 - events.type; + info.dir_requested.dy -= 3 - events.type; break; } case KEY_LEFT : { - way.dir_requested.dx += 3 - events.type; + info.dir_requested.dx += 3 - events.type; break; } case KEY_RIGHT : { - way.dir_requested.dx -= 3 - events.type; + info.dir_requested.dx -= 3 - events.type; break; } case KEY_SHIFT : { - - fire = 1; - /*if(planes[0].bullets > 0) + //maybe (if(event.key.release)) + switch(planes[0].bullets_type) { - planes[0].bullets = planes[0].bullets - 1; - fire = 1; - }*/ + 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; + } + } break; // fire enable } @@ -196,17 +256,17 @@ int game() timer_destroy(timer); //destroy the virtual timer return 1; // good bye, see you soon } + case KEY_1 : + { + planes[0].bullets_type = 1; + break; + } + case KEY_0 : + { + planes[0].bullets_type = 0; + break; + } } } - - 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; - } } } diff --git a/wings.bin b/wings.bin new file mode 100755 index 0000000..78bc2d3 Binary files /dev/null and b/wings.bin differ diff --git a/wings.elf b/wings.elf new file mode 100755 index 0000000..c4e4113 Binary files /dev/null and b/wings.elf differ diff --git a/wings.g1a b/wings.g1a new file mode 100755 index 0000000..8398fc1 Binary files /dev/null and b/wings.g1a differ