From ebceb1a60a5b8193fc3827ae8c12f52dfd19dfc2 Mon Sep 17 00:00:00 2001 From: flo Date: Thu, 20 Apr 2017 12:44:09 +0200 Subject: [PATCH] on fire --- img/plane.bmp | Bin 6198 -> 6198 bytes include/maths.h | 11 +++++++++++ include/wings.h | 13 +++++++------ src/maths.c | 28 ++++++++++++++++++++++++++++ src/wings.c | 44 +++++++++++++++++++++++++------------------- 5 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 include/maths.h create mode 100644 src/maths.c diff --git a/img/plane.bmp b/img/plane.bmp index 58de2d4c69acf1e82b10067d853c96d5f22d2d45..b6717e2985c2fb097bc271d4c1cb0722c0f50d82 100644 GIT binary patch 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 literal 6198 zcmb`C!BImo5JRB@j+8(J6u_OH=p1$sywPaw^(P@S39|Ggo45DZ=ZEjlYyG~|_oKc~ z^?iK!34Z>R#plyLm>~@LAIbg=bJZPMEF)%kNO#edCVtI>? zvm+rM6B6f$QIUWT;aEg`{%zeSj5wM=JkI)Vkgt|KV4!|-RNH5NqUwyp=8RKyT zE77CjYKp~3dwnQ&42R7S0n{;oeiTDd0?Zej0dNuB9tE%)m+z@hxrQmBkEgDG^8@A; z*HN#dr_wS-_7r9b$mEwgFcA(6;utYfm4J!D*ElJ6g`ia;qB>GXbOvmQdR-3P4#e6H zz(+(;S8!2JXGgP)1k9y~9S}Z8ihfb)0U$!q#Xh2rafy}L zNjbr5VF%+g==Gjz%^8ZoFz!eni&P+c5oQ_j9zidgfqT| zU%dMl>tMcvDM7T`zZ0My_tud}q656pVX*6UNV*{aO6aZ*gyYAkdxVC;K@5=?0q`M) z`Vjf@ykBGi{ZjeIE5KsGkMl^s-Mj2-BqBc^0f(h|7@{+SbG(t+62neKJAj2{ofNUe a26K0>S8g8nk*=8y(aC!p#*ZUK9+@w=eFVP% diff --git a/include/maths.h b/include/maths.h new file mode 100644 index 0000000..a8cdcf2 --- /dev/null +++ b/include/maths.h @@ -0,0 +1,11 @@ +#ifndef MATHS + #define MATHS + +#define pi 3.14159265358 +#define pi_2 1.570796327 +#define pi_4 0.78539981635 + +float cos(float x); +float sin(float x); + +#endif diff --git a/include/wings.h b/include/wings.h index 1411b14..68596e0 100644 --- a/include/wings.h +++ b/include/wings.h @@ -1,11 +1,12 @@ #ifndef WINGS #define WINGS +#define MAX_MISSILES 4 + typedef struct Missile { - unsigned char dir; - short x[4]; - short y[4]; + unsigned char dir[MAX_MISSILES]; + short distance[MAX_MISSILES]; // distance between the plane and the missile } Missile; typedef struct Plane @@ -15,9 +16,9 @@ typedef struct Plane unsigned char dir; /* plane direction management - 7 0 1 - 6 plane 2 - 5 4 3 + 3 2 1 + 4 plane 0 + 5 6 7 */ unsigned char life; diff --git a/src/maths.c b/src/maths.c new file mode 100644 index 0000000..f70832c --- /dev/null +++ b/src/maths.c @@ -0,0 +1,28 @@ +#include "maths.h" + +#define MAX_TURN 24 + +float cos(float x) +{ +int a = 8 * MAX_TURN - 6; +int b = 2 * MAX_TURN * (2 * MAX_TURN - 1); // 2n(2n-1) +float s = 1; + +int i; + +x = x*x; // x² + +for(i = 0; i < MAX_TURN; i++) + { + s = 1 - x * s / b; + b -= a; + a -= 8; + } + +return s; +} + +float sin(float x) +{ + return cos(x - pi_2); +} diff --git a/src/wings.c b/src/wings.c index d369333..7c37c63 100644 --- a/src/wings.c +++ b/src/wings.c @@ -1,4 +1,5 @@ #include "wings.h" +#include "maths.h" #include "display.h" // bopti.h => images // tales.h => fonts #include "keyboard.h" @@ -40,6 +41,7 @@ void init() planes[i].y = 12; planes[i].dir = i; planes[i].life = 100; + } } @@ -77,21 +79,21 @@ void menu() void update_frame() { - static unsigned char i; + static unsigned char i,j; static short decalx = 0, decaly = 0; gclear(); switch(planes[0].dir) { - case 0 : decaly++; break; + case 0 : decalx--; break; case 1 : decalx--; decaly++; break; - case 2 : decalx--; break; - case 3 : decalx--; decaly--; break; - case 4 : decaly--; break; + case 2 : decaly++; break; + case 3 : decalx++; decaly++; break; + case 4 : decalx++; break; case 5 : decalx++; decaly--; break; - case 6 : decalx++; break; - case 7 : decalx++; decaly++; break; + case 6 : decaly--; break; + case 7 : decalx--; decaly--; break; } gimage_part(planes[0].x, planes[0].y, &plane, 16*planes[0].dir, 0, 16, 16); @@ -106,9 +108,10 @@ void update_frame() { for(j = 0; j < MAX_MISSILES; j++) { - if(planes[i].missile.distance[j] > 0) // we load the missile to reach the target + if(planes[i].missiles.distance[j] > 0) // we load the missile to reach the target { - //gline(plane[0].x, plane[0].y, ) + 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]++; } } } @@ -128,7 +131,7 @@ int game() int keys[3]; - unsigned char i; + unsigned char i,j; timer_t *timer = NULL; @@ -137,6 +140,7 @@ int game() timer_start(timer); gray_start(); // gray engine running + init(); // initialisation while(1) @@ -164,24 +168,26 @@ int game() } } -/* we determine the direction of the plane*/ +// we determine the direction of the plane switch(sum) { - case KEY_UP : planes[0].dir = 0; break; + case KEY_RIGHT : planes[0].dir = 0; break; case KEY_UP + KEY_RIGHT : planes[0].dir = 1; break; - case KEY_RIGHT : planes[0].dir = 2; break; - case KEY_DOWN + KEY_RIGHT : planes[0].dir = 3; break; - case KEY_DOWN : planes[0].dir = 4; 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_LEFT : planes[0].dir = 6; break; - case KEY_UP + KEY_LEFT : planes[0].dir = 7; 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.missiles.dir = planes[0].dir; - planes[0].missiles.distance[j] = 1; // fire unlimited + 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 // this code line will depend if we shoot in continue } } }