add coyote time & jump buffering

This commit is contained in:
Milang 2020-02-07 10:39:43 +01:00
parent 4ed9222790
commit 1aa5edd231
1 changed files with 29 additions and 3 deletions

View File

@ -128,14 +128,40 @@ void mario_move()
bullet_throw();
}
if (mkb_getstate(MK_JUMP)==2) //|| keys[MK_JUMP2]==2)
static int jump_buffering=0;
static int coyote_time=0;
if (mkb_getstate(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
{
if (mario.p.vx*sgn(mario.p.vx)>=6)
box_jump(&mario.p, 9);
else
box_jump(&mario.p, 8);
if (mario.p.vy<=0 && mkb_getstate(MK_JUMP)==2 && coyote_time<4) // n'a pas sauté alors que la touche était enfoncée et coyote time
{
if (mario.p.vx*sgn(mario.p.vx)>=6)
mario.p.vy=9;
else
mario.p.vy=8;
}
else if (mario.p.vy<=0 && mkb_getstate(MK_JUMP)==2) // n'a pas sauté alors que la touche était enfoncée
jump_buffering=5;
}
else if (mario.p.vy>=2 && mkb_getstate(MK_JUMP)==0)
if (jump_buffering)
jump_buffering--;
for (int i=0; i<mario.p.w; i++)
{
if (world_get_ctg(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
{
coyote_time=0;
break;
}
}
coyote_time++;
if (mario.p.vy>=2 && mkb_getstate(MK_JUMP)==0)
mario.p.vy--;
int vx=sgn(mkb_getstate(MK_RIGHT) - mkb_getstate(MK_LEFT));
@ -155,7 +181,7 @@ void mario_move()
{
if (mkb_getstate(MK_RUN) && (c1==CTG_SOIL || c2==CTG_SOIL))
{
if(mario.p.vx*sgn(mario.p.vx)<=8)
if(mario.p.vx*vx<=8)
mario.p.vx+=vx;
}
else