79 lines
1.8 KiB
C
79 lines
1.8 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 bullet_throw()
|
|
{
|
|
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=-6;
|
|
else
|
|
bullets[i].b.vx=6;
|
|
bullets[i].b.vy=0;
|
|
bullets[i].p1=last_vx_sign;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void bullet_display()
|
|
{
|
|
for (int i=0; i<2; i++)
|
|
{
|
|
if (bullets[i].type==1)
|
|
draw_tile(bullets[i].b.x-camera_x(), bullets[i].b.y-camera_y(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
|
|
}
|
|
}
|
|
|
|
void bullet_move()
|
|
{
|
|
for (int i=0; i<2; i++)
|
|
{
|
|
if (bullets[i].type==1)
|
|
{
|
|
box_jump(&bullets[i].b,4);
|
|
box_move(&bullets[i].b);
|
|
if (bullets[i].b.vx==0)
|
|
bullets[i].type=0;
|
|
if (bullets[i].b.y<0)
|
|
bullets[i].type=0;
|
|
if (bullets[i].b.x<=camera_x()-bullets[i].b.w || bullets[i].b.x>=camera_x()+127)
|
|
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;
|
|
score_add(KILL_ENNEMI);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |