115 lines
2.2 KiB
C
115 lines
2.2 KiB
C
#include <plateforme.h>
|
|
|
|
#include <world.h>
|
|
#include <mario.h>
|
|
#include <tile.h>
|
|
#include <score.h>
|
|
#include <camera.h>
|
|
#include <level.h>
|
|
#include <gint/std/string.h>
|
|
#include <gint/std/stdlib.h>
|
|
#include <base.h>
|
|
|
|
int plateforme_table_size=0;
|
|
plateforme_t* plateformes=0;
|
|
|
|
void reset_plateforme(plateforme_t* p)
|
|
{
|
|
p->b.x=p->xinit;
|
|
p->b.y=p->yinit;
|
|
}
|
|
|
|
void move_plateforme(plateforme_t* p)
|
|
{
|
|
|
|
int xc = (mario.p.x<p->b.x+p->b.w && mario.p.x>=p->b.x) || (mario.p.x+mario.p.w<p->b.x+p->b.w && mario.p.x+mario.p.w>=p->b.x);
|
|
int yc = (mario.p.y-3==p->b.y);
|
|
|
|
/*if (p->type==P_FALLING)
|
|
{
|
|
if (p->v)
|
|
p->v++;
|
|
p->b.y+=p->v/2;
|
|
}*/
|
|
box_t temp=p->b;
|
|
|
|
box_move(&p->b);
|
|
|
|
// Si mario est sur la plateforme, il bouge avec
|
|
if (xc&&yc)
|
|
{
|
|
box_t mario_clone=mario.p;
|
|
mario_clone.vx=temp.vx;
|
|
mario_clone.vy=temp.vy;
|
|
box_move(&mario_clone);
|
|
mario.p.x=mario_clone.x;
|
|
mario.p.y=mario_clone.y;
|
|
}
|
|
|
|
|
|
if (p->b.vx==0)
|
|
{
|
|
p->b.vx=-temp.vx;
|
|
//p->b.x -= sgn(p->b.vx);
|
|
}
|
|
if (p->b.vy==0)
|
|
p->b.vy=-temp.vy;
|
|
}
|
|
|
|
void display_plateformes()
|
|
{
|
|
if (plateformes==0 || plateforme_table_size==0)
|
|
return;
|
|
plateforme_t * p=0;
|
|
for (int i=0; i<plateforme_table_size; i++)
|
|
{
|
|
p=&plateformes[i];
|
|
for (int j=p->b.x; j < p->b.x+p->b.w; j+=3)
|
|
draw_tile(j-camera_x(),p->b.y-camera_y(), &tplateforme, 0,0);
|
|
//drect(p->b.x-world_get_real_x0(),64-(p->b.y-world_get_real_y0()),p->b.x-world_get_real_x0()+p->b.w,64-(p->b.y-world_get_real_y0()-3), C_BLACK);
|
|
}
|
|
}
|
|
|
|
void move_plateformes()
|
|
{
|
|
if (plateformes==0 || plateforme_table_size==0)
|
|
return;
|
|
plateforme_t * p=0;
|
|
for (int i=0; i<plateforme_table_size; i++)
|
|
{
|
|
p=&plateformes[i];
|
|
move_plateforme(p);
|
|
}
|
|
}
|
|
|
|
int plateforme_check_collide(int x, int y)
|
|
{
|
|
if (plateformes==0 || plateforme_table_size==0)
|
|
return 0;
|
|
for (int i=0; i<plateforme_table_size; i++)
|
|
{
|
|
plateforme_t * p=&plateformes[i];
|
|
if (p->b.x<=x && p->b.x+p->b.w>x && p->b.y<=y && p->b.y+3>y)
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
void init_plateformes(plateforme_t * table, int s)
|
|
{
|
|
plateforme_table_size=0;
|
|
if (plateformes)
|
|
{
|
|
free_prof(plateformes);
|
|
plateformes=0;
|
|
}
|
|
if (0==table)
|
|
return;
|
|
int size=sizeof(plateforme_t)*s;
|
|
plateformes=malloc_prof(size);
|
|
if (plateformes==0)
|
|
malloc_error();
|
|
plateforme_table_size=s;
|
|
memcpy(plateformes, table, size);
|
|
} |