same problem, but it is late

This commit is contained in:
flo 2017-04-21 22:32:40 +02:00
parent bd1cf523aa
commit 2443143e69
13 changed files with 59 additions and 35 deletions

View File

@ -1,6 +1,9 @@
#ifndef MATHS
#define MATHS
float fcos(unsigned char x);
float fsin(unsigned char x);
#define pi 3.14159265358
#define pi_2 1.570796327
#define pi_4 0.78539981635

View File

@ -1,13 +1,14 @@
#ifndef WINGS
#define WINGS
#define MAX_MISSILES 8
#define MAX_MISSILES 2
// missiles management
typedef struct Missile
{
unsigned char dir[MAX_MISSILES];
short distance[MAX_MISSILES]; // distance between the plane and the missile
unsigned char dir;
short distance; // distance between the plane and the missile
unsigned char type;
} Missile;
// plane management
@ -24,8 +25,9 @@ typedef struct Plane
*/
unsigned char life;
unsigned char reload;
struct Missile missiles;
Missile missiles[MAX_MISSILES];
// align
} Plane;

BIN
obj/cloud.bmp.o Normal file

Binary file not shown.

BIN
obj/img_menu.bmp.o Normal file

Binary file not shown.

BIN
obj/maths.c.o Normal file

Binary file not shown.

BIN
obj/missiles.bmp.o Normal file

Binary file not shown.

BIN
obj/plane.bmp.o Normal file

Binary file not shown.

BIN
obj/wings.c.o Normal file

Binary file not shown.

View File

@ -1,5 +1,20 @@
#include "maths.h"
//get the value of sin/cos(dir * pi_4)
float fcos(unsigned char x)
{
float cos[4] = {1.0, 0.707106, 0.0, -0.707106};
return (x < 4 ? cos[x] : - cos[x%4]);
}
float fsin(unsigned char x)
{
return fcos(x - 2);
}
#define MAX_TURN 6
float cos(float x)

View File

@ -13,7 +13,6 @@
#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
@ -31,19 +30,32 @@ int main()
void init()
{
unsigned char i;
unsigned char i,j;
planes[0].x = 56;
planes[0].y = 24;
planes[0].dir = 0;
planes[0].life = 100;
for(i = 0; i < MAX_PLANES; i++)
{
planes[i].x = 56 + 16 * i;
planes[i].y = 24 + i;
planes[i].dir = i;
planes[i].life = 100;
planes[i].reload = 6;
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;
}
}
}
void AI() // iA start
{
unsigned char i;
for(i = 1; i < MAX_PLANES; i++)
{
planes[i].x = 10 + 16 * i;
planes[i].y = 12 + i;
planes[i].dir = i;
planes[i].life = 100;
}
}
@ -99,21 +111,14 @@ void *update_frame()
case 7 : decalx--; decaly--; break;
}
if(decalx < - SIZE_MAP_X || decalx > SIZE_MAP_X || decaly < - SIZE_MAP_Y || decaly > SIZE_MAP_Y)
{
dtext(1, 10, "You are going to dead");
}
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 > 0 || planes[i].x + decalx < 128 || planes[i].y + decaly > 0 || planes[i].y + decaly < 64)
{
//dimage_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);
dimage(planes[i].x + decalx, planes[i].y + decaly, &plane);
}
dimage(10 + decalx, 10 + decaly, &cloud);
@ -122,15 +127,11 @@ void *update_frame()
{
for(j = 0; j < MAX_MISSILES; j++)
{
dimage_part(planes[i].x + 4 + (planes[i].missiles[j].distance + 15) * fcos(planes[i].missiles[j].dir),
planes[i].y + 4 - (planes[i].missiles[j].distance + 15) * fsin(planes[i].missiles[j].dir),
&missiles, 8 * planes[i].missiles[j].dir, 0, 8, 8);
//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]++;
// }
planes[i].missiles[j].distance++;
}
}
@ -149,13 +150,15 @@ int game()
j = 0;
init(); // initialisation
timer_t *timer = NULL;
timer = timer_create(40, 0);
timer_attach(timer, &update_frame, NULL);
timer_start(timer);
init(); // initialisation
while(1)
{
@ -230,6 +233,9 @@ int game()
if(fire) // put the screen on fire !
{
planes[0].missiles[j].dir = planes[0].dir; // the missile take the direction of the plane
planes[0].missiles[j].distance = 0; // fire unlimited (nearly)
j = j + 1;
if(j >= MAX_MISSILES)
@ -237,8 +243,6 @@ int game()
j = 0;
}
planes[0].missiles.dir[j] = planes[0].dir;
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
}
}

BIN
wings.bin Executable file

Binary file not shown.

BIN
wings.elf Executable file

Binary file not shown.

BIN
wings.g1a Normal file

Binary file not shown.