pb dimage_part quand x < 0

This commit is contained in:
flo 2017-04-20 22:25:52 +02:00
parent cc7cf2bd05
commit bd1cf523aa
5 changed files with 83 additions and 35 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

After

Width:  |  Height:  |  Size: 822 B

BIN
img/missiles.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -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

View File

@ -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
}
}