Le nouveau Super Mario Bros pour la gamme des fx9860g https://www.planet-casio.com/Fr/forums/topic15994-1-[addin]-SuperCasioBros-v0.1.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
supercasiobros/src/plateforme.c

116 lines
2.5 KiB

#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)
{
// Si mario et la plateforme vont se chevaucher, la plateforme est immobilisée
{
box_t b = p->b;
b.x+=b.vx;
b.y+=b.vy;
int x_collide= (mario.p.x<=b.x && b.x<mario.p.x+mario.p.w) || (mario.p.x<=b.x+b.w-1 && b.x+b.w<mario.p.x+mario.p.w);
int y_collide= (mario.p.y<=b.y && b.y<mario.p.y+mario.p.h) || (mario.p.y<=b.y+b.h-1 && b.y+b.h<mario.p.y+mario.p.h);
if (x_collide&&y_collide)
return;
}
box_t temp=p->b;
box_move(&p->b);
// Si mario est sur la plateforme, il bouge avec
if (((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)) && (mario.p.y-3==p->b.y))
{
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);
}