65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
#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}
|
|
};
|
|
|
|
void bulletThrow()
|
|
{
|
|
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)
|
|
bullets[i].b.vx=-9; //speed = 9
|
|
else
|
|
bullets[i].b.vx=9;
|
|
bullets[i].b.vy=0;
|
|
bullets[i].p1=last_vx_sign;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void bulletsDraw()
|
|
{
|
|
for (int i=0; i<2; i++) if (bullets[i].type==1) tileDraw(bullets[i].b.x-cameraX(), bullets[i].b.y-cameraY(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
|
|
}
|
|
|
|
void bulletsMove()
|
|
{
|
|
for (int i=0; i<2; i++) if (bullets[i].type) // bullet active
|
|
{
|
|
boxJump(&bullets[i].b,4);
|
|
boxMove(&bullets[i].b);
|
|
|
|
if (bullets[i].b.vx==0) bullets[i].type=0; // delete a bullet if it is stopped
|
|
if (bullets[i].b.y<0) bullets[i].type=0; // delete a bullet if it is out of the map
|
|
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+127) bullets[i].type=0; // delete a bullet if it is out of the screen
|
|
|
|
// contact with ennemies
|
|
for (int a=0; a<ennemis_global_size; a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
|
|
{
|
|
ennemis_global[a].life=DEAD;
|
|
bullets[i].type=0;
|
|
scoreAdd(KILL_ENNEMI);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|