78 lines
1.4 KiB
C
78 lines
1.4 KiB
C
#include "ennemi.h"
|
|
#include "mario.h"
|
|
#include "box.h"
|
|
#include "tile.h"
|
|
#include "world.h"
|
|
#include "score.h"
|
|
|
|
|
|
void display_ennemi(ennemi_t const * e)
|
|
{
|
|
if (e->life==DEAD)
|
|
return;
|
|
if (e->b.x-e->b.w<=world_get_real_x0(0) || e->b.x>=world_get_real_x0(0)+127)
|
|
return;
|
|
if (e->type==GOOMBA)
|
|
{
|
|
extern image_t img_goomba;
|
|
tileset_t goomba={&img_goomba, 8, 8, 1};
|
|
if (e->life==1)
|
|
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
|
|
if (e->life==0)
|
|
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &goomba, 0, 0);
|
|
}
|
|
}
|
|
void move_ennemi(ennemi_t *e)
|
|
{
|
|
|
|
if (e->b.x-e->b.w<=world_get_real_x0(0) || e->b.x>=world_get_real_x0(0)+127)
|
|
return;
|
|
if (e->life==DEAD)
|
|
return;
|
|
if (e->type==NONE)
|
|
return;
|
|
if (e->type==GOOMBA)
|
|
{
|
|
int old_vx=e->b.vx;
|
|
if (time_id%2)
|
|
e->b.vx=0;
|
|
|
|
box_move(&e->b);
|
|
|
|
if (time_id%2)
|
|
e->b.vx=old_vx;
|
|
|
|
if (e->b.vx==0)
|
|
{
|
|
if (e->p1==0)
|
|
{
|
|
e->b.vx=-1;
|
|
e->p1=-1;
|
|
}
|
|
if (e->p1==1)
|
|
{
|
|
e->b.vx=-1;
|
|
e->p1=-1;
|
|
}
|
|
if (e->p1==-1)
|
|
{
|
|
e->b.vx=1;
|
|
e->p1=1;
|
|
}
|
|
}
|
|
if (e->b.y<0)
|
|
e->type=NONE;
|
|
}
|
|
}
|
|
void ennemi_collision(ennemi_t *e);
|
|
|
|
ennemi_t * ennemis_global=0;
|
|
int ennemis_global_size=0;
|
|
void display_ennemi_table()
|
|
{
|
|
for (int i=0; i<ennemis_global_size; i++)
|
|
{
|
|
move_ennemi(&ennemis_global[i]);
|
|
display_ennemi(&ennemis_global[i]);
|
|
}
|
|
} |