2020-01-29 14:34:57 +01:00
|
|
|
#include <bullets.h>
|
|
|
|
#include <bonus.h>
|
|
|
|
#include <constants.h>
|
|
|
|
#include <mario.h>
|
|
|
|
#include <tile.h>
|
|
|
|
#include <camera.h>
|
|
|
|
#include <base.h>
|
|
|
|
#include <ennemi.h>
|
|
|
|
#include <score.h>
|
|
|
|
/* Les balles ont les memes propriétés que les boulets et sont donc gérées ici */
|
|
|
|
|
|
|
|
static bonus_t bullets[2] =
|
|
|
|
{
|
|
|
|
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0},
|
|
|
|
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0}
|
|
|
|
};
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void bulletThrow()
|
2020-01-29 14:34:57 +01:00
|
|
|
{
|
|
|
|
for (int i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
if (bullets[i].type==0)
|
|
|
|
{
|
|
|
|
bullets[i].type=1;
|
|
|
|
bullets[i].b.x=mario.p.x;
|
|
|
|
bullets[i].b.y=mario.p.y+8;
|
|
|
|
if (last_vx_sign==0)
|
2020-02-07 10:39:21 +01:00
|
|
|
bullets[i].b.vx=-9; //speed = 9
|
2020-01-29 14:34:57 +01:00
|
|
|
else
|
2020-02-07 10:39:21 +01:00
|
|
|
bullets[i].b.vx=9;
|
2020-01-29 14:34:57 +01:00
|
|
|
bullets[i].b.vy=0;
|
|
|
|
bullets[i].p1=last_vx_sign;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void bulletsDraw()
|
2020-01-29 14:34:57 +01:00
|
|
|
{
|
|
|
|
for (int i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
if (bullets[i].type==1)
|
2020-02-16 20:43:35 +01:00
|
|
|
tileDraw(bullets[i].b.x-cameraX(), bullets[i].b.y-cameraY(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
|
2020-01-29 14:34:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void bulletsMove()
|
2020-01-29 14:34:57 +01:00
|
|
|
{
|
|
|
|
for (int i=0; i<2; i++)
|
|
|
|
{
|
|
|
|
if (bullets[i].type==1)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
boxJump(&bullets[i].b,4);
|
|
|
|
boxMove(&bullets[i].b);
|
2020-01-29 14:34:57 +01:00
|
|
|
if (bullets[i].b.vx==0)
|
|
|
|
bullets[i].type=0;
|
|
|
|
if (bullets[i].b.y<0)
|
|
|
|
bullets[i].type=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+127)
|
2020-01-29 14:34:57 +01:00
|
|
|
bullets[i].type=0;
|
|
|
|
for (int a=0; a<ennemis_global_size; a++)
|
|
|
|
{
|
|
|
|
ennemi_t* t=&ennemis_global[a];
|
|
|
|
if (t->discovered && t->type!=NONE)
|
|
|
|
{
|
|
|
|
bool x_collide= (bullets[i].b.x<=t->b.x && t->b.x<bullets[i].b.x+bullets[i].b.w) || (bullets[i].b.x<=t->b.x+t->b.w-1 && t->b.x+t->b.w<bullets[i].b.x+bullets[i].b.w);
|
|
|
|
bool y_collide= (bullets[i].b.y<=t->b.y && t->b.y<bullets[i].b.y+bullets[i].b.h) || (bullets[i].b.y<=t->b.y+t->b.h-1 && t->b.y+t->b.h<bullets[i].b.y+bullets[i].b.h);
|
|
|
|
if (x_collide&& y_collide)
|
|
|
|
{
|
|
|
|
t->life=DEAD;
|
|
|
|
bullets[i].type=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
scoreAdd(KILL_ENNEMI);
|
2020-01-29 14:34:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|