#include #include "tile.h" #include "world.h" #include #include #include "box.h" #include "score.h" #include "bonus.h" #include #include #include pnj mario= { {26,17,6,8,0,0,0,1}, 0 }; void marioBigger() { mario.p.h=16; mario.p.h=M_BIG; mario.bullets=0; } void marioSmaller() { mario.p.h=8; mario.p.h=M_SMALL; mario.bullets=0; if (mario.immunity==0) mario.immunity=1; } void marioDraw() { if ( (mario.immunity==0 || (mario.immunity/7)%2==0) && (mario.starMode/2)%2==0) { const int mx=mario.p.x-cameraX(mario.p.x)-1; const int my=mario.p.y-cameraY(mario.p.y); if (mario.p.h==M_SMALL) { if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn+(time_id/4)%2, 0); else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn+(time_id/8)%2, 0); else tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn, 0); } else { if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_big, 1+3*mario.last_vx_sgn+(time_id/4)%2, mario.bullets); else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_big, 1+3*mario.last_vx_sgn+(time_id/8)%2, mario.bullets); else tileDraw(mx, my, &mario_big, 3*mario.last_vx_sgn, mario.bullets); } } } #define COYOTE_INTERVAL 3 static int jump_input=0; void marioResetJump() { // disables jump buffering & coyote time until the next time mario hits the ground jump_input = 0; } int global_quit=0; void marioMove() { { // Mario star mode & immunity counters if (mario.starMode==200) mario.starMode=0; else if (mario.starMode) mario.starMode++; if (mario.immunity==60) mario.immunity=0; else if (mario.immunity) mario.immunity++; } if (mario.bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow(); { // Jump (with coyote time & jump buffering) bool jump=0; // will he jump ? // coyote time for (int i = 0; i < mario.p.w; i++) if (worldGetCellCategory(mario.p.x + i, mario.p.y - 1)==CTG_SOIL) { if (jump_input>0) jump=1; else jump_input=-COYOTE_INTERVAL; break; } // jump buffering if (MKB_getKeyState(MK_JUMP)==2) { if (jump_input<0) jump = 1; // break the rules else jump_input = 1; } if (jump_input) jump_input++; if (jump_input==COYOTE_INTERVAL+1) jump_input=0; if (jump) { if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9, 0); else boxJump(&mario.p, 8, 0); } if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height } { // Lateral move int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows) // cells next to mario int c1=worldGetCellCategory(mario.p.x, mario.p.y-1/*+mario.p.h*/); int c2=worldGetCellCategory(mario.p.x+mario.p.w-1, mario.p.y-1/*+mario.p.h*/); static int mario_timeAccel=0; mario_timeAccel=1-mario_timeAccel; // increments & %2 if (vx!=sgn(mario.p.vx)) mario_timeAccel=1; // reverse direction means deceleration which is 2 times faster if (mario_timeAccel) { if (vx) { // sprinte et est sur le sol if (MKB_getKeyState(MK_RUN) && (c1==CTG_SOIL || c2==CTG_SOIL) && (abs(mario.p.vx)<=7 || sgn(mario.p.vx)!=vx)) mario.p.vx+=vx; else if (abs(mario.p.vx+vx) <= 4) mario.p.vx+=vx; // ralentissement si au dela de la vitesse sans sprint else if (MKB_getKeyState(MK_RUN)==0 && abs(mario.p.vx)>4) mario.p.vx-=sgn(mario.p.vx); } else mario.p.vx-=sgn(mario.p.vx); } { // last vx sign determination if (vx>0 && (c1==CTG_SOIL || c2==CTG_SOIL)) mario.last_vx_sgn=1; if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL)) mario.last_vx_sgn=0; } if (mario.p.x+mario.p.vxtype==COIN && c->taken==0) {coinAdd();c->taken=1;} c=(coin_t*)worldGetCell(mario.p.x+mario.p.w-1, mario.p.y); if (c->type==COIN && c->taken==0) {coinAdd();c->taken=1;} c=(coin_t*)worldGetCell(mario.p.x, mario.p.y+mario.p.h-1); if (c->type==COIN && c->taken==0) {coinAdd();c->taken=1;} c=(coin_t*)worldGetCell(mario.p.x+mario.p.w-1, mario.p.y+mario.p.h-1); if (c->type==COIN && c->taken==0) {coinAdd();c->taken=1;} } {// End level flag detection end_level_t *e1=(end_level_t*)worldGetCell(mario.p.x, mario.p.y), *e2=(end_level_t*)worldGetCell(mario.p.x+mario.p.w-1, mario.p.y); if (e1->type==END_LEVEL) { finish_level=1; scoreAdd(400*e1->bonus); } if (e2->type==END_LEVEL) { finish_level=1; scoreAdd(400*e2->bonus); } } {// mario box auto hit gift_t* c=(gift_t*)worldGetCell((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h); if ((c->type==GIFT || c->type==BRICK) && (c->time_hit_id==0 && mario.p.last_vy>0)) { c->hidden=0; mario.p.last_vy=0; if (c->number) { c->time_hit_id=1; switch (c->content) { case 1: c->number--; coinAdd(); break; case 2: c->number--; bonusSet(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8); break; case 3: c->number--; bonusSet(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8); break; case 4: c->number--; bonusSet(BONUS_STAR,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8); break; } } else if (c->content==0 && mario.p.h==M_BIG && c->type==BRICK) { c->state=c->time_hit_id=1; mario.p.vy=3; } else if (c->content==0 && c->type==BRICK) c->time_hit_id=1; } } }