101 lines
2.2 KiB
C
101 lines
2.2 KiB
C
#include "bonus.h"
|
|
#include "box.h"
|
|
#include "mario.h"
|
|
#include "world.h"
|
|
#include "tile.h"
|
|
#include "score.h"
|
|
#include "ennemi.h"
|
|
#include "constants.h"
|
|
#include <stdbool.h>
|
|
#include <base.h>
|
|
#include <camera.h>
|
|
|
|
static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 0};
|
|
|
|
void bonus_set(bonus_id t, int x, int y)
|
|
{
|
|
bonus.type=t;
|
|
if (mario.size==M_BIG && t==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.type==BONUS_NONE)
|
|
return;
|
|
|
|
if (bonus.type==BONUS_STAR)
|
|
{
|
|
box_jump(&bonus.b,4);
|
|
}
|
|
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=2;
|
|
bonus.p1=1;
|
|
}
|
|
else
|
|
{
|
|
bonus.p1*=-1;
|
|
bonus.b.vx=2*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<mario.p.x+mario.p.w) || (mario.p.x<=bonus.b.x+bonus.b.w-1 && bonus.b.x+bonus.b.w<mario.p.x+mario.p.w);
|
|
bool y_collide= (mario.p.y<=bonus.b.y && bonus.b.y<mario.p.y+mario.p.h) || (mario.p.y<=bonus.b.y+bonus.b.h-1 && bonus.b.y+bonus.b.h<mario.p.y+mario.p.h);
|
|
if (x_collide&&y_collide)
|
|
{
|
|
if (bonus.type==BONUS_CHAMPI)
|
|
{
|
|
bonus_set(BONUS_NONE,0,0);
|
|
score_add(1000);
|
|
mario_bigger();
|
|
}
|
|
if (bonus.type==BONUS_FLEUR)
|
|
{
|
|
bonus_set(BONUS_NONE,0,0);
|
|
mario_has_bullets=1;
|
|
score_add(1000);
|
|
}
|
|
if (bonus.type==BONUS_1UP)
|
|
{
|
|
bonus_set(BONUS_NONE,0,0);
|
|
score_add(1000);
|
|
lifes_add();
|
|
}
|
|
if (bonus.type==BONUS_STAR)
|
|
{
|
|
bonus_set(BONUS_NONE,0,0);
|
|
score_add(1000);
|
|
mario_star_mode=1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void bonus_draw()
|
|
{
|
|
//bonus_move();
|
|
if (bonus.type==BONUS_NONE)
|
|
return;
|
|
if (bonus.type==BONUS_CHAMPI)
|
|
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &champi, 0,0);
|
|
if (bonus.type==BONUS_FLEUR)
|
|
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &fleur, 0,0);
|
|
if (bonus.type==BONUS_1UP)
|
|
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &life_1up, 0,0);
|
|
if (bonus.type==BONUS_STAR)
|
|
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &mario_starman, 0,0);
|
|
} |