on fire
This commit is contained in:
parent
0bbb013e75
commit
ebceb1a60a
BIN
img/plane.bmp
BIN
img/plane.bmp
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
44
src/wings.c
44
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue