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

68 lines
1.4 KiB

#include <camera.h>
#include <mario.h>
#include <world.h>
#include <base.h>
#include <keyboard.h>
static int y=0;
static int last_vy=0;
static int immobile=0;
static int distance=0;
static int delta_y=0; // the player can choose the y positionning of the camera with arrows
int cameraX() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int cameraY() {return max(max(y-32,0)-delta_y,0);}
void cameraMove() // only vertical movement
{
static int camera_vy=0;
if (MKB_getKeyState(MK_UP) && abs(delta_y)<24) { camera_vy=0; delta_y-=4;}
if (MKB_getKeyState(MK_DOWN) && abs(delta_y)<24) { camera_vy=0; delta_y+=4;}
if (!MKB_getKeyState(MK_DOWN) && !MKB_getKeyState(MK_UP)) delta_y-=4*sgn(delta_y);
if (mario.p.y==last_vy) immobile++;
else
{
last_vy=mario.p.y;
immobile=0;
}
if (mario.p.y-cameraY()-mario.p.h<16 || mario.p.y-cameraY()>54)
{
y+=4*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;
}