#include "bonus.h" #include "box.h" #include "mario.h" #include "world.h" #include "tile.h" #include "score.h" #include "ennemi.h" #include #define BONUS_FLEUR 4 // interne, généré depuis champi #define BULLET 1 typedef struct { int type; box_t b; int p1; } bonus_t; static int sgn(int x) { if (x>0) return 1; else if (x<0) return -1; else return 0; } static bonus_t bonus ={BONUS_NONE, {0,0,8,8,0,0,0,1}, 0}; /* 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,4,4,0,0,0,1}, 0},{0, {0,0,4,4,0,0,0,1}, 0}}; void lance_bullet() { for (int i=0; i<2; i++) { if (bullets[i].type==0) { bullets[i].type=BULLET; bullets[i].b.x=mario.p.x; bullets[i].b.y=mario.p.y+8; if (last_vx_sign==0) bullets[i].b.vx=-3; else bullets[i].b.vx=3; 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==BULLET) draw_tile(bullets[i].b.x-world_get_real_x0(), bullets[i].b.y-world_get_real_y0(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0); } } void bullet_move() { for (int i=0; i<2; i++) { if (bullets[i].type==BULLET) { 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<=world_get_real_x0()-bullets[i].b.w || bullets[i].b.x>=world_get_real_x0()+127) bullets[i].type=0; for (int a=0; adiscovered && t->type!=NONE) { bool x_collide= (bullets[i].b.x<=t->b.x && t->b.xb.x+t->b.w-1 && t->b.x+t->b.wb.y && t->b.yb.y+t->b.h-1 && t->b.y+t->b.htype=NONE; bullets[i].type=0; score_add(100); } } } } } } void bonus_set(int type, int x, int y) { bonus.type=type; if (mario.size==M_BIG && type==BONUS_CHAMPI) bonus.type=BONUS_FLEUR; bonus.b.x=x; bonus.b.y=y; bonus.b.vx=0; bonus.b.vy=0; bonus.p1=0; } void bonus_move() //+collision { if (bonus.b.x<=world_get_real_x0()-bonus.b.w || bonus.b.x>=world_get_real_x0()+127) bonus_set(BONUS_NONE,0,0); if (bonus.type==BONUS_NONE) return; if (bonus.type==BONUS_STAR) { box_jump(&bonus.b,5); } box_move(&bonus.b); if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR) { if (bonus.b.vx==0) { if (bonus.p1==0) { bonus.b.vx=1; bonus.p1=1; } else { bonus.p1*=-1; bonus.b.vx=bonus.p1; } } if (bonus.b.y<0) bonus_set(BONUS_NONE,0,0); } bool x_collide= (mario.p.x<=bonus.b.x && bonus.b.x