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/camera.c

85 lines
1.3 KiB

#include <camera.h>
#include <mario.h>
#include <world.h>
#include <base.h>
static int y=0;
int cameraX() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int cameraY() {return max(y-32,0);}
static int immobile=0;
static int last_vy=0;
static int distance=0;
void cameraMove() // movement vertical seulement
{
/* static int isMoving=0;
static int ref_y=0;
if (mario.p.y-cameraY()<16 || mario.p.y-cameraY()>56)
{
isMoving=1;
ref_y=mario.p.y;
}
if (isMoving)
{
for (int i=0; i<9; i++)
y+=sgn(mario.p.y-y);
if (y==ref_y)
isMoving=0;
}
*/
static int camera_vy=0;
if (mario.p.y==last_vy) // mario arrêté
immobile++;
else
{
last_vy=mario.p.y;
immobile=0;
}
if (mario.p.y-cameraY()-mario.p.h<16 || mario.p.y-cameraY()>54)
{
y+=5*sgn(mario.p.y-y);
}
if (immobile>=2)
{
//y+=(mario.p.y-y)/3;
if (camera_vy==0)
{
distance=2*(mario.p.y-y)*sgn(mario.p.y-y);
}
//décéleration après avoir parvouru la moitié de la distance, sinon acceleration
if (camera_vy*(camera_vy+1)>distance)
camera_vy--;
else
camera_vy++;
//y++;
if (camera_vy<0)
camera_vy=0;
if (((y+camera_vy*sgn(mario.p.y-y)/2)-(mario.p.y))*sgn(mario.p.y-y)>0)
{
y=mario.p.y;
camera_vy=0;
}
else
y+=(camera_vy*sgn(mario.p.y-y))/2;
}
last_vy=mario.p.y;
}
void cameraAdjust()
{
y=mario.p.y;
}
void cameraReset()
{
y=0;
}