From 1aa5edd2313c211d35bb614ebb82210e57663a0c Mon Sep 17 00:00:00 2001 From: Milang Date: Fri, 7 Feb 2020 10:39:43 +0100 Subject: [PATCH] add coyote time & jump buffering --- src/mario.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/mario.c b/src/mario.c index bdfd1b0..5d1e3e9 100755 --- a/src/mario.c +++ b/src/mario.c @@ -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=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