From a736fb48f0df0513a81e730822f8d55234cf72de Mon Sep 17 00:00:00 2001 From: flo Date: Sun, 30 Jul 2017 15:20:33 +0200 Subject: [PATCH] new motor and improvement --- Makefile | 4 +- Makefile.config | 2 +- img/cloud.bmp | Bin img/img_menu.bmp | Bin img/missile.bmp | Bin 0 -> 1782 bytes img/missiles.bmp | Bin 1590 -> 0 bytes img/plane.bmp | Bin 6198 -> 6966 bytes include/maths.h | 0 include/wings.h | 29 +++---- misc/icon.bmp | Bin 1802 -> 1802 bytes src/maths.c | 0 src/wings.c | 193 +++++++++++++++++------------------------------ 12 files changed, 86 insertions(+), 142 deletions(-) mode change 100644 => 100755 img/cloud.bmp mode change 100644 => 100755 img/img_menu.bmp create mode 100755 img/missile.bmp delete mode 100644 img/missiles.bmp mode change 100644 => 100755 img/plane.bmp mode change 100644 => 100755 include/maths.h mode change 100644 => 100755 include/wings.h mode change 100644 => 100755 misc/icon.bmp mode change 100644 => 100755 src/maths.c mode change 100644 => 100755 src/wings.c diff --git a/Makefile b/Makefile index 12dee19..1adfd60 100755 --- a/Makefile +++ b/Makefile @@ -16,11 +16,11 @@ $(OBJDIR): ## Compile sprites $(OBJDIR)/%.bmp.o: $(IMGDIR)/%.bmp - fxconv $< -o $@ -n $(basename $(notdir $<)) + fxconv -image $< -o $@ -n $(basename $(notdir $<)) ## Compile fonts $(OBJDIR)/%.bmp.o: $(FONTDIR)/%.bmp - fxconv $< -o $@ -n $(basename $(notdir $<)) --font + fxconv -font $< -o $@ -n $(basename $(notdir $<)) ## Make an object file out of an ASM source file $(OBJDIR)/%.s.o: $(SRCDIR)/%.s diff --git a/Makefile.config b/Makefile.config index 910c78d..5a9c348 100755 --- a/Makefile.config +++ b/Makefile.config @@ -25,7 +25,7 @@ CC = sh3eb-elf-gcc CFLAGS = -m3 -mb -Os -nostdlib -Wall -Wextra -Wno-main -pedantic -std=c11 -I $(INCDIR) `fxsdk --cflags` ## Linker LD = sh3eb-elf-gcc -LFLAGS = `fxsdk --cflags` `fxsdk --libs` +LFLAGS = `fxsdk --cflags --libs` ## Object copier OBJCPY = sh3eb-elf-objcopy ## Object dump diff --git a/img/cloud.bmp b/img/cloud.bmp old mode 100644 new mode 100755 diff --git a/img/img_menu.bmp b/img/img_menu.bmp old mode 100644 new mode 100755 diff --git a/img/missile.bmp b/img/missile.bmp new file mode 100755 index 0000000000000000000000000000000000000000..ec070f5289a758f99ded8f7cdcb781f165efabc6 GIT binary patch literal 1782 zcmb`B!EM7Z6hqxhXXpr-pab-toikOhE}bdU9dxBMCUZ4j`PnH=xy=$ay3?suWG8$wxlL_`8(Eb$LoM6X zPT54%ShZIv_g4wL%>1g8l}%S|9m5h^pv+swe0)BjeBD)!Mn51mBr76Y?W}p1IF$kn z#%GCSQva{V50l{II%yZKdZOdcyfK1~=lI^t+Pk!FtSX#*$rea+3uET#h)ijx@G7;S5(tGG0KsB%!_ EA3^aDBme*a literal 0 HcmV?d00001 diff --git a/img/missiles.bmp b/img/missiles.bmp deleted file mode 100644 index 0161f8cd499b5a47aceef6cc5b318975f9455ca8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1590 zcma)&K?*`K5JPn%9>F7c0@vc+`yWSx(MOo+6bmhx^dy{9(=z3SR#}1NPKyl{G{DLPr>#+w^@Qol^p5fZz7NmX3r+&CxCP8Jsq1E``mWn zs_sw01yxh+k!5e<-zk1)qp8Be}X*@0mk$C$NA`>A*Jxy6pLqL=$-7_mse4tm)& zZ(ylo$~?zna^oy~1te2Wi_UwgAPN>oqNBL!b_Qp+53m$&EdflE)&Ld;Qb&r3b_ETO zgCOctI3eIuI4bE7F_H{Ni=loQc`Y@?9vPU^80i4ZCB+{qJqm{+V#azp7k7O3!(pn3 z0bWL*%gldv_s->~I3DMnU5f90ObY`y+Fi7Zm`iaa6WDd_&mnYlqgl3a(f(2=yo|#1)Qz5ZcIhYbho5Wr`z-&vVW;yf|5p?+ zMMPgP*3)GXGsI=ZSk~=WGj20AQMuRteZ+p&Ia+*pxfJuQFyo5Uz6*U5^(mYXOj#JP zHq-UT$jg?o)bk5;-p)-on5c9Thm>Wa?Bd^uWj9SOGE;P30q06wN(K7B>e z=1UYu?>n7akj6qU2h*nlLl>trM1~7ij(!a^%&cH-2)W7{9WMz;xim zI$>@#3#PV2kH==mP!c?&0LEKlchpOGzzzoRlr+{ZTbP)hJ!znS8OI&2b0r!Sxoo%u zsum_r>`n(pT;klFgIouT<_;9;3_%IEO3$vts)fg5Bf;Ky-Itq5S|L{WLQ2r z=GvLkW%uJ?qU?;y~{YxF031ssV7aW6KQ@1ei88VzJQ@awm$9_>OdJ$@u92 zcwX#%gyBiVYZdii5+e^ea-&4Bo zq;KN1ES73^K6*s5+zARpz<=+=&?c+;qnXjOdIpw{VE$B=5m_=U5v06_rLe*30L?Dc zP#daT`_facVW@I9+B9|`HjG}*GDI=U&75_&H+Z3wzL&=BR&8*1CmaZ7u>6)|zDEPF zaS=z|Doyqhi=am0vwK;to?bHd`x|qWJf(A3=#=!ktIeUNVQ++|%8EdAZuu m(3{;oxdPLx1`Bw82H0J}X~f-zOa4E-yzcVm5W6RxyyO$1H4v=; diff --git a/include/maths.h b/include/maths.h old mode 100644 new mode 100755 diff --git a/include/wings.h b/include/wings.h old mode 100644 new mode 100755 index a1ccdfe..9e0ebd4 --- a/include/wings.h +++ b/include/wings.h @@ -3,12 +3,19 @@ #define MAX_MISSILES 4 +// direction management +typedef struct Direction +{ + char dx; + char dy; +} Direction; + // missiles management typedef struct Missile { short x; short y; - unsigned char dir; + Direction dir; // short distance; // distance between the plane and the missile unsigned char type; } Missile; @@ -18,16 +25,17 @@ typedef struct Plane { short x; short y; - unsigned char dir; + Direction dir; + // (dx, dy) /* plane direction management - 3 2 1 - 4 plane 0 - 5 6 7 + (1, 1) (0, 1) (-1, 1) + (1, 0) plane (-1, 0) + (1,-1) (0,-1) (-1,-1) */ unsigned char life; - unsigned char reload; + unsigned char bullets; Missile missiles[MAX_MISSILES]; // align @@ -39,16 +47,9 @@ typedef struct Cloud short y; } Cloud; -typedef enum Type -{ - dX = 0, - dY = 2, -} Type; - int menu(void); void init(void); -char get_decal(unsigned char dir, Type type); -void *update_frame(void); +void *update_frame(Direction *direction); int game(void); #endif diff --git a/misc/icon.bmp b/misc/icon.bmp old mode 100644 new mode 100755 index 542e05b4f35dff9c7edef6c3f3210ecdcfa02057..dc1ab0a483561945f146ba3e69a9fc426a052313 GIT binary patch literal 1802 zcmchUOAf*?3`9d0Ai8A%E7qKV1F+{fy(z~*3KLt2rfxpaMnsA`j-SVt`go29C+CiM z!@c63aCh#4=-g{BpIPwU&+?uLytkjiLfehu@Qb%$oAV7H(@GzZN|j5|%zPO!y0^EP z%&D2oDPyE72ucJ7$#7juqe0l9q)kgUMekHxMFxkEZEZfH@i;cAb%3n4uC>|qKW~{7 zg6^bZnFc}*uqZSCBqB=HBUlDBP4*DxEWEXzwc*EPBLW!(_3 z*ca>*_AZ?fQ+n;o$1F_KG|T^&j04!)S7V?SnB}cg=ZEa}+#x&X3@W3=hwPMW33Xi< z^6bU>N^xunG(0*imv&_?UB=cW%a+*^o$MB7p images // tales.h => fonts #include "keyboard.h" #include "timer.h" -#include "gray.h" +#include "events.h" #include "stdio.h" #include "stdlib.h" @@ -13,7 +12,7 @@ #define MAP_SIZE_Y 256 #define MAX_PLANES 2 -#define MAX_CLOUDS 2 +#define MAX_CLOUDS 15 Plane planes[MAX_PLANES]; // number of planes in the map (with us) //others planes are controlled by the AI @@ -24,7 +23,7 @@ Cloud clouds[MAX_CLOUDS]; //number of clouds in this beautifull sky extern image_t plane; extern image_t img_menu; extern image_t cloud; -extern image_t missiles; +extern image_t missile; int main() { @@ -40,14 +39,13 @@ void init() { planes[i].x = 56 + 16 * i; planes[i].y = 24 + i; - planes[i].dir = i; planes[i].life = 100; - planes[i].reload = 6; + 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].distance = 0; planes[i].missiles[j].dir = planes[i].dir; planes[i].missiles[j].type = 0; } @@ -60,30 +58,9 @@ void init() } } -// void infos() -// { -// unsigned int key = 0; -// -// while(key != KEY_SHIFT) -// { -// dclear(); -// -// dtext(1, 1, "All informations"); -// dprint(1, 10, "life : %d", planes[0].life); -// dprint(1, 20, "shoot : %d", planes[0].reload); -// dtext(1,54,"F1 to leave"); -// dupdate(); -// -// key = getkey(); -// } -// } - int menu() { unsigned char menu = 0; - unsigned int key = 0; - - //extern image_t img_menu; while(1) { @@ -94,128 +71,118 @@ int menu() dupdate(); - key = getkey(); - - switch (key) + switch(getkey()) { case KEY_UP : case KEY_DOWN : menu = !menu; break; case KEY_EXE : + { + if (!menu) { - if (!menu) - { - game(); break; - } - else return 1; + game(); break; } + else return 1; + } case KEY_EXIT : return 1; } } } -char get_decal(unsigned char dir, Type type) -{ - char dx[4] = {-1, -1 , 0, 1}; - char n = 1; - - dir += type; - - while(dir >=4) - { - dir-=4; - n = -n; - } - return n*dx[dir]; -} - -void *update_frame() +void *update_frame(Direction *map_dir) { static unsigned char i,j; dclear(); - dprint(1, 1, "s:%d l:%d", planes[0].reload, planes[0].life); - //dprint(1, 20, "(%d,%d)", get_decal(planes[0].dir, dX), get_decal(planes[0].dir, dY)); + 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); - clouds[i].x += get_decal(planes[0].dir, dX); - clouds[i].y += get_decal(planes[0].dir, dY); } for (i = 0; i < MAX_PLANES; i++) { if(i > 0) { - planes[i].x += get_decal(planes[0].dir, dX); - planes[i].y += get_decal(planes[0].dir, dY); + 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*planes[i].dir, 0, 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++) { - planes[i].missiles[j].x -= get_decal(planes[i].missiles[j].dir, dX); - planes[i].missiles[j].y -= get_decal(planes[i].missiles[j].dir, dY); + 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 ,&missiles, 8 * planes[i].missiles[j].dir, 0, 8, 8); + 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(); } -#define MAX_KEYS 4 - int game() { - unsigned char fire = 0; // fire disable - unsigned char sum = 0; + unsigned char fire = 0, j = 0; // fire disable - unsigned int sum_keys[8] = { KEY_RIGHT, KEY_RIGHT + KEY_UP, KEY_UP, KEY_LEFT + KEY_UP, KEY_LEFT, KEY_LEFT + KEY_DOWN, KEY_DOWN, KEY_RIGHT + KEY_DOWN }; + //direction for the map + Direction map_dir, dir_requested; - int keys[MAX_KEYS]; - - unsigned char i; - unsigned char j; - - j = 0; - - init(); // initialisation + init(); timer_t *timer = NULL; - timer = timer_create(40, 0); - timer_attach(timer, update_frame, NULL); + 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) { - multigetkey(keys, MAX_KEYS, 0); + events = waitevent(); - sum = 0; - - - for(i = 0; i < MAX_KEYS; i++) + if(events.type >= event_key_press && events.type <= event_key_release) { - switch(keys[i]) + switch(events.key.code) { - case KEY_UP : case KEY_DOWN : case KEY_LEFT : case KEY_RIGHT : + case KEY_UP : { - sum += keys[i]; + 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 : { - if(planes[0].reload > 0) + + fire = 1; + /*if(planes[0].bullets > 0) { + planes[0].bullets = planes[0].bullets - 1; fire = 1; - //planes[0].reload = planes[0].reload - 1; - } - break; // fire enable + }*/ + break; // fire enable } case KEY_EXIT : @@ -223,47 +190,23 @@ int game() timer_destroy(timer); //destroy the virtual timer return 1; // good bye, see you soon } - - // case KEY_OPTN : - // { - // timer_stop(timer); // virtual timer stopped - // - // infos(); - // - // //timer = timer_create(40, 0); - // //timer_attach(timer, &update_frame, NULL); - // timer_start(timer); - // break; - // } } } -// we determine the direction of the plane - - for(i = 0; i < 8; i++) + if(dir_requested.dx != 0 || dir_requested.dy != 0) { - if(sum == sum_keys[i]) - { - planes[0].dir = i; - break; - } + map_dir = dir_requested; + planes[0].dir = dir_requested; } - - if(fire == 1) // put the screen on fire ! + if(fire) { - planes[0].missiles[j].x = planes[0].x; - planes[0].missiles[j].y = planes[0].y; - planes[0].missiles[j].dir = planes[0].dir; // the missile take the direction of the plane + planes[0].missiles[0].dir = planes[0].dir; - j = j + 1; + 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; - if(j >= MAX_MISSILES) - { - j = 0; - } - - fire = 0; // fire disable, shoot one by one // this code line will depend if we shoot in continue + fire = 0; } } }