From bd1cf523aaf0225ad0f76e4107ebdc993bc3673c Mon Sep 17 00:00:00 2001 From: flo Date: Thu, 20 Apr 2017 22:25:52 +0200 Subject: [PATCH] pb dimage_part quand x < 0 --- img/cloud.bmp | Bin 822 -> 822 bytes img/missiles.bmp | Bin 0 -> 1590 bytes img/plane.bmp | Bin 6198 -> 6198 bytes include/wings.h | 9 +++- src/wings.c | 109 +++++++++++++++++++++++++++++++++-------------- 5 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 img/missiles.bmp diff --git a/img/cloud.bmp b/img/cloud.bmp index c342ecac94318a9fbda5765b82fcdff210929f37..7a1e5a21b64b4775c1a1d969adcc17da26840e8c 100644 GIT binary patch literal 822 zcmdUq-3fp&41_B#;G-irK?m^N{m0RxS3W|jzBiC?xt~DJtFEP0)jZT&@1^XGFJ1TI zdCy<*oqw!fW#Hq8lVp#tf$_wkF%#evGe#1Ll(Mg@vtJP|3*aF#GWe4ec}Zhom>oR# CoMsvT literal 822 zcmZ?rHDhJ~12Z700mK4O%*Y@C7H5FULpTuf|DXiOF2rP`IT@(H0WSb5K-L0LzW@gS unuMvIx>|5qfy)+5^$_m>)nnCyUp+(%Pz@XaMUcY>nGLc48$ebwq}c$keJm#c diff --git a/img/missiles.bmp b/img/missiles.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0161f8cd499b5a47aceef6cc5b318975f9455ca8 GIT binary patch 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!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=; literal 6198 zcmcJPL5@>F5JQI>u;d7wVAdn{+=-*)reJXNWVwEK`h$p+;I?16I+>7f-`~Hy{dv6W z^{bvg^!%*nr?+SD{6`j#pNofqMfkK&m~3EaiDdTrWaA0LmdE3PJ`v(SK0drc;_mp# z3Nh~AzY&<(c@mv4x0(%8D>28*(Fa&gm0YGWy=9f|{gXf0%Xa}VcM(a<)Q*{bx?$?_9`~4*>XE$lW=c`=CMl^jNwk>D zA1(pEZxi=%n^)8;ZHNMVR4M^O|Ag~f1V06B)nJl-ACs9?a*9vpeEdYpFvT_(fm~^>sMPy+>dew<9rhb2jreMpAkUS< zB5TX!F9$JKqOQ#mKHp24lO&ZOwIITmGyk&~gOR|Yfk7}L91Hvu$)s5bVhPWS1S@IW)tPE#L`Ct z;H0Q;en!&FN>r4`RSDw>qe=JWU<@KQQ865+*pv`S%t1RR%xab&@D(86{Tsm1NmZ5n x%gtT2zgzYnl66BJDVY(@z8vhX&_}8-w#y~{;uC(k@ju;Md)+)=S64c@$uC1XJd*$b diff --git a/include/wings.h b/include/wings.h index 68596e0..fb8148d 100644 --- a/include/wings.h +++ b/include/wings.h @@ -1,14 +1,16 @@ #ifndef WINGS #define WINGS -#define MAX_MISSILES 4 +#define MAX_MISSILES 8 +// missiles management typedef struct Missile { unsigned char dir[MAX_MISSILES]; short distance[MAX_MISSILES]; // distance between the plane and the missile } Missile; +// plane management typedef struct Plane { short x; @@ -27,6 +29,9 @@ typedef struct Plane // align } Plane; - +int menu(void); +void init(void); +void *update_frame(void); +int game(void); #endif diff --git a/src/wings.c b/src/wings.c index bb827ec..116b74e 100644 --- a/src/wings.c +++ b/src/wings.c @@ -11,7 +11,9 @@ #define SIZE_MAP_X 256 #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 @@ -19,6 +21,7 @@ Plane planes[MAX_PLANES]; // number of planes in the map (with us) extern image_t plane; extern image_t img_menu; extern image_t cloud; +extern image_t missiles; int main() { @@ -44,7 +47,7 @@ void init() } } -void menu() +int menu() { unsigned char menu = 0; unsigned int key = 0; @@ -76,13 +79,13 @@ void menu() } } -void update_frame() +void *update_frame() { static unsigned char i,j; static short decalx = 0; static short decaly = 0; - gclear(); + dclear(); switch(planes[0].dir) { @@ -98,58 +101,60 @@ void update_frame() 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"); + dtext(1, 10, "You are going to dead"); } - gimage_part(planes[0].x, planes[0].y, &plane, 16*planes[0].dir, 0, 16, 16); + 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 > -16 || planes[i].x + decalx < 144 || planes[i].y + decaly > -16 || planes[i].y + decaly < 80) + if(planes[i].x + decalx > 0 || planes[i].x + decalx < 128 || planes[i].y + decaly > 0 || planes[i].y + decaly < 64) { - gimage_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); } } - gimage(10 + decalx, 10 + decaly, &cloud); + dimage(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]++; - } + + //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]++; + // } } } - gupdate(); + dupdate(); } int game() { - - //int dir = 0; - unsigned char fire = 0; // fire disable unsigned char sum = 0; int keys[3]; - unsigned char i,j = 0; + unsigned char i; + unsigned char j; + + j = 0; timer_t *timer = NULL; timer = timer_create(40, 0); - timer_attach(timer, update_frame, NULL); + timer_attach(timer, &update_frame, NULL); timer_start(timer); - gray_start(); // gray engine running - init(); // initialisation while(1) @@ -165,12 +170,12 @@ int game() case KEY_UP : case KEY_DOWN : case KEY_LEFT : case KEY_RIGHT : { sum += keys[i]; // to know which replay keys pressed + break; } - 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 } @@ -181,21 +186,59 @@ int game() 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; + 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 ! { + j = j + 1; + + if(j >= MAX_MISSILES) + { + j = 0; + } + planes[0].missiles.dir[j] = planes[0].dir; - planes[0].missiles.distance[j] = 12; // fire unlimited (nearly) - j = (j < MAX_MISSILES ? j + 1 : 0); + 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 } }