supercasiobros/src/bonus.c

99 lines
1.6 KiB
C

#include <bonus.h>
#include <box.h>
#include <mario.h>
#include <constants.h>
static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 0};
void bonusSet(bonus_id t, int x, int y)
{
// champignon ou fleur
if (mario.p.h == M_BIG && t == BONUS_CHAMPI) bonus.type = BONUS_FLEUR;
else bonus.type=t;
// coordonnees spawn
bonus.b.x = x; bonus.b.y = y;
bonus.b.vx = bonus.b.vy = bonus.p1=0;
}
#include <score.h> // bonus en cas de prise
void bonusMove() //+collision
{
if (bonus.type == BONUS_NONE) return;
// animation de l'objet
boxMove(&bonus.b);
switch (bonus.type)
{
case BONUS_STAR:
// bounce
boxJump(&bonus.b, 4, true);
// fall through
case BONUS_CHAMPI:
case BONUS_1UP:
// bounce against walls
if (bonus.b.vx==0)
{
if (bonus.p1==0) bonus.p1=1;
else bonus.p1*=-1;
bonus.b.vx=2*bonus.p1;
}
if (bonus.b.y<0)
bonusSet(BONUS_NONE,0,0);
}
if (bonus.type!=BONUS_NONE && boxContact(&mario.p, &bonus.b))
{
switch (bonus.type)
{
case BONUS_CHAMPI:
case BONUS_FLEUR:
if (mario.p.h==M_SMALL) marioBigger();
else mario.bullets=1;
break;
case BONUS_1UP:
lifesAdd(1);
break;
case BONUS_STAR:
bonusSet(BONUS_NONE,0,0);
mario.starMode=1;
}
scoreAdd(1000);
bonusSet(BONUS_NONE,0,0);
}
}
#include <camera.h>
#include <tile.h>
void bonusDraw()
{
if (bonus.type==BONUS_NONE) return;
tileset_t const * t=0;
switch (bonus.type)
{
case BONUS_CHAMPI:
t=&champi;
break;
case BONUS_FLEUR:
t=&fleur;
break;
case BONUS_1UP:
t=&life_1up;
break;
case BONUS_STAR:
t=&mario_starman;
break;
}
if (t) tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), t, 0,0);
}