2019-11-21 19:30:54 +01:00
|
|
|
#include "mario.h"
|
|
|
|
#include "tile.h"
|
|
|
|
#include "world.h"
|
|
|
|
#include <gint/display.h>
|
2020-01-29 14:34:47 +01:00
|
|
|
#include <keyboard.h>
|
2019-11-21 19:30:54 +01:00
|
|
|
#include "box.h"
|
2019-11-30 13:57:18 +01:00
|
|
|
#include "score.h"
|
2019-12-05 19:24:16 +01:00
|
|
|
#include "bonus.h"
|
2020-01-29 14:34:47 +01:00
|
|
|
#include <bullets.h>
|
|
|
|
#include <camera.h>
|
2020-02-15 19:35:49 +01:00
|
|
|
#include <base.h>
|
2019-11-21 19:30:54 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
|
2019-11-30 13:57:18 +01:00
|
|
|
int id_frame=0;
|
2019-12-05 19:24:16 +01:00
|
|
|
|
2019-11-21 19:30:54 +01:00
|
|
|
pnj mario=
|
|
|
|
{
|
2020-02-16 12:51:27 +01:00
|
|
|
{26,17,6,8,0,0,0,1},
|
2019-11-30 13:57:18 +01:00
|
|
|
M_SMALL,
|
|
|
|
M_RIGHT1, M_WALK,
|
|
|
|
0
|
2019-11-21 19:30:54 +01:00
|
|
|
};
|
2020-02-16 20:43:35 +01:00
|
|
|
|
2019-12-05 19:24:16 +01:00
|
|
|
int mario_has_bullets=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
static int mario_timeAccel=0;
|
2019-11-25 19:12:25 +01:00
|
|
|
int mario_dead=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
|
|
|
|
// Used to draw mario (mario direction)
|
2019-11-30 13:57:18 +01:00
|
|
|
int last_vx_sign=1;
|
2019-12-11 16:31:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
// After he becomes little
|
2019-12-05 19:24:16 +01:00
|
|
|
int mario_immunity=0;
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
|
|
|
|
int mario_starMode=0;
|
|
|
|
|
|
|
|
void marioBigger()
|
2019-12-05 19:24:16 +01:00
|
|
|
{
|
|
|
|
mario.p.h=16;
|
|
|
|
mario.size=M_BIG;
|
|
|
|
mario_has_bullets=0;
|
|
|
|
}
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void marioSmaller()
|
2019-12-05 19:24:16 +01:00
|
|
|
{
|
|
|
|
mario.p.h=8;
|
|
|
|
mario.size=M_SMALL;
|
|
|
|
mario_has_bullets=0;
|
2019-12-07 14:32:38 +01:00
|
|
|
if (mario_immunity==0)
|
2020-02-15 19:35:49 +01:00
|
|
|
mario_immunity=1;
|
2019-12-07 14:32:38 +01:00
|
|
|
//mario.p.vy=5;
|
2019-12-05 19:24:16 +01:00
|
|
|
}
|
2019-11-21 19:30:54 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void marioDraw()
|
2019-11-21 19:30:54 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
if ( (mario_immunity==0 || (mario_immunity/7)%2==0) && (mario_starMode/2)%2==0)
|
2019-11-30 13:57:18 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
const int mx=mario.p.x-cameraX(mario.p.x)-1;
|
|
|
|
const int my=mario.p.y-cameraY(mario.p.y);
|
2019-12-08 16:34:32 +01:00
|
|
|
if (mario.size==M_SMALL)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
|
|
|
|
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
|
|
|
|
else tileDraw(mx, my, &mario_small, 2*last_vx_sign, 0);
|
2019-12-08 16:34:32 +01:00
|
|
|
}
|
2019-12-05 19:24:16 +01:00
|
|
|
else
|
2019-12-08 16:34:32 +01:00
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
|
|
|
|
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
|
|
|
|
else tileDraw(mx, my, &mario_big, 3*last_vx_sign, mario_has_bullets);
|
2019-12-08 16:34:32 +01:00
|
|
|
}
|
2019-12-05 19:24:16 +01:00
|
|
|
}
|
2019-11-21 19:30:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int test_sol_le_plus_proche(int x, int y)
|
|
|
|
{
|
2019-11-30 13:57:18 +01:00
|
|
|
int distance=0;
|
|
|
|
int t=0;
|
|
|
|
while (t==0)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
int type_sol = worldGetCellCategory(x, y-1);
|
2019-12-08 16:34:32 +01:00
|
|
|
if (type_sol==CTG_SOIL)
|
2020-02-15 19:35:49 +01:00
|
|
|
t=1;
|
2019-12-08 16:34:32 +01:00
|
|
|
if (type_sol==CTG_DEATH)
|
2020-02-15 19:35:49 +01:00
|
|
|
return distance+1;
|
2020-02-16 20:43:35 +01:00
|
|
|
type_sol = worldGetCellCategory(x+7, y-1);
|
2019-12-08 16:34:32 +01:00
|
|
|
if (type_sol==CTG_SOIL)
|
2020-02-15 19:35:49 +01:00
|
|
|
t=1;
|
2019-12-08 16:34:32 +01:00
|
|
|
if (type_sol==CTG_DEATH)
|
2020-02-15 19:35:49 +01:00
|
|
|
return distance+1;
|
2019-11-30 13:57:18 +01:00
|
|
|
y--;
|
|
|
|
distance++;
|
|
|
|
}
|
|
|
|
return distance;
|
2019-11-21 19:30:54 +01:00
|
|
|
}
|
|
|
|
|
2020-02-16 13:32:16 +01:00
|
|
|
static int jump_buffering=0;
|
|
|
|
static int coyote_time=5;
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
void resetMarioJump()
|
2020-02-16 13:32:16 +01:00
|
|
|
{
|
|
|
|
jump_buffering=0;
|
|
|
|
coyote_time=5;
|
|
|
|
}
|
2019-11-25 19:12:25 +01:00
|
|
|
|
2019-11-21 19:30:54 +01:00
|
|
|
int global_quit=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
void marioMove()
|
2019-11-21 19:30:54 +01:00
|
|
|
{
|
2019-11-30 13:57:18 +01:00
|
|
|
id_frame++;
|
2020-01-29 14:34:47 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (mario_starMode==200) mario_starMode=0;
|
|
|
|
else if (mario_starMode) mario_starMode++;
|
2020-02-16 13:32:16 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (mario_immunity==60) mario_immunity=0;
|
|
|
|
else if (mario_immunity) mario_immunity++;
|
2020-02-07 10:39:43 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (mario_has_bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
|
2020-02-07 10:39:43 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (MKB_getKeyState(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
|
|
|
|
{
|
|
|
|
if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9);
|
|
|
|
else boxJump(&mario.p, 8);
|
|
|
|
|
|
|
|
if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2 && coyote_time<4) // n'a pas sauté alors que la touche était enfoncée et coyote time =4 frames = 0.2 sec
|
2020-02-07 10:39:43 +01:00
|
|
|
{
|
2020-02-15 19:35:49 +01:00
|
|
|
if (mario.p.vx*sgn(mario.p.vx)>=6) mario.p.vy=9;
|
|
|
|
else mario.p.vy=8;
|
2020-02-07 10:39:43 +01:00
|
|
|
}
|
2020-02-16 20:43:35 +01:00
|
|
|
// n'a pas sauté alors que la touche était enfoncée
|
|
|
|
else if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2) jump_buffering=5; // Jump buffering during 5-1 frames = 0.2 sec
|
2019-11-30 13:57:18 +01:00
|
|
|
}
|
2020-02-16 20:43:35 +01:00
|
|
|
|
|
|
|
if (jump_buffering) jump_buffering--;
|
2020-02-07 10:39:43 +01:00
|
|
|
|
|
|
|
for (int i=0; i<mario.p.w; i++)
|
|
|
|
{
|
2020-02-16 20:43:35 +01:00
|
|
|
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
|
2020-02-07 10:39:43 +01:00
|
|
|
{
|
|
|
|
coyote_time=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
coyote_time++;
|
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows)
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
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*/);
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
mario_timeAccel=1-mario_timeAccel;
|
|
|
|
if (vx==-sgn(mario.p.vx)) mario_timeAccel=1;
|
|
|
|
if (mario_timeAccel)
|
2019-11-30 13:57:18 +01:00
|
|
|
{
|
2020-02-15 19:35:49 +01:00
|
|
|
if (vx)
|
2019-12-03 19:53:30 +01:00
|
|
|
{
|
2020-02-15 19:35:49 +01:00
|
|
|
// sprinte et est sur le sol
|
2020-02-16 20:43:35 +01:00
|
|
|
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;
|
2020-02-15 19:35:49 +01:00
|
|
|
else if (abs(mario.p.vx+vx) <= 4) mario.p.vx+=vx;
|
|
|
|
// ralentissement si au dela de la vitesse sans sprint
|
2020-02-16 20:43:35 +01:00
|
|
|
else if (MKB_getKeyState(MK_RUN)==0 && abs(mario.p.vx)>4) mario.p.vx-=sgn(mario.p.vx);
|
2019-11-30 13:57:18 +01:00
|
|
|
}
|
2020-02-15 19:35:49 +01:00
|
|
|
else mario.p.vx-=sgn(mario.p.vx);
|
2019-11-30 13:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vx>0 && (c1==CTG_SOIL || c2==CTG_SOIL))
|
2020-02-15 19:35:49 +01:00
|
|
|
last_vx_sign=1;
|
2019-11-30 13:57:18 +01:00
|
|
|
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL))
|
2020-02-15 19:35:49 +01:00
|
|
|
last_vx_sign=0;
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
if (mario.p.x+mario.p.vx<cameraX(mario.p.x))
|
2019-12-11 16:31:18 +01:00
|
|
|
{
|
2019-12-05 19:24:16 +01:00
|
|
|
mario.p.vx=0;
|
2020-02-16 20:43:35 +01:00
|
|
|
mario.p.x=cameraX(mario.p.x);
|
2019-12-11 16:31:18 +01:00
|
|
|
}
|
2020-01-06 20:56:10 +01:00
|
|
|
//teleporteurs_check();
|
2020-02-16 20:43:35 +01:00
|
|
|
boxMove(&mario.p); // <-> + gravity
|
2019-12-05 19:24:16 +01:00
|
|
|
|
2019-11-30 13:57:18 +01:00
|
|
|
if (mario.p.y<0)
|
2020-02-15 19:35:49 +01:00
|
|
|
mario_dead=1;
|
2019-11-30 13:57:18 +01:00
|
|
|
if (mario.p.vx==0)
|
2020-02-16 20:43:35 +01:00
|
|
|
mario_timeAccel=0;
|
2019-11-30 13:57:18 +01:00
|
|
|
|
|
|
|
// coins
|
2019-12-04 19:27:27 +01:00
|
|
|
coin_t* c;
|
2020-02-16 20:43:35 +01:00
|
|
|
c=(coin_t*)worldGetCell(mario.p.x, mario.p.y);
|
2019-12-04 19:27:27 +01:00
|
|
|
if (c->type==COIN && c->taken==0)
|
2020-02-16 20:43:35 +01:00
|
|
|
{coinAdd();c->taken=1;}
|
|
|
|
c=(coin_t*)worldGetCell(mario.p.x+mario.p.w-1, mario.p.y);
|
2019-12-04 19:27:27 +01:00
|
|
|
if (c->type==COIN && c->taken==0)
|
2020-02-16 20:43:35 +01:00
|
|
|
{coinAdd();c->taken=1;}
|
|
|
|
c=(coin_t*)worldGetCell(mario.p.x, mario.p.y+mario.p.h-1);
|
2019-12-04 19:27:27 +01:00
|
|
|
if (c->type==COIN && c->taken==0)
|
2020-02-16 20:43:35 +01:00
|
|
|
{coinAdd();c->taken=1;}
|
|
|
|
c=(coin_t*)worldGetCell(mario.p.x+mario.p.w-1, mario.p.y+mario.p.h-1);
|
2019-12-04 19:27:27 +01:00
|
|
|
if (c->type==COIN && c->taken==0)
|
2020-02-16 20:43:35 +01:00
|
|
|
{coinAdd();c->taken=1;}
|
2019-12-04 19:27:27 +01:00
|
|
|
|
2020-02-16 20:43:35 +01:00
|
|
|
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);
|
2020-01-15 20:42:51 +01:00
|
|
|
if (e1->type==END_LEVEL)
|
2020-01-15 12:18:14 +01:00
|
|
|
{
|
|
|
|
finish_level=1;
|
2020-02-16 20:43:35 +01:00
|
|
|
scoreAdd(400*e1->bonus);
|
2020-01-15 20:42:51 +01:00
|
|
|
}
|
|
|
|
if (e2->type==END_LEVEL)
|
|
|
|
{
|
|
|
|
finish_level=1;
|
2020-02-16 20:43:35 +01:00
|
|
|
scoreAdd(400*e2->bonus);
|
2020-01-15 12:18:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 19:24:16 +01:00
|
|
|
//if ((mario.p.x+mario.p.w/2)/8==(mario.p.x+mario.p.w/2-1)/8)
|
|
|
|
//{
|
2020-02-16 20:43:35 +01:00
|
|
|
gift_t* t=(gift_t*)worldGetCell((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h);
|
2019-12-05 19:24:16 +01:00
|
|
|
|
2019-12-08 16:34:32 +01:00
|
|
|
if (t->type==GIFT || t->type==BRICK)
|
|
|
|
{
|
|
|
|
brick_t *c=(brick_t*)t;
|
2020-01-30 21:09:18 +01:00
|
|
|
if (c->time_hit_id==0 && mario.p.last_vy>0)
|
2019-12-04 19:27:27 +01:00
|
|
|
{
|
2020-01-30 21:09:18 +01:00
|
|
|
if (c->content==0 || c->number)
|
|
|
|
{
|
|
|
|
c->time_hit_id=1;
|
|
|
|
mario.p.last_vy=0;
|
|
|
|
}
|
|
|
|
|
2019-12-08 16:34:32 +01:00
|
|
|
if (c->content==1 && c->number)
|
2019-12-04 19:27:27 +01:00
|
|
|
{
|
2019-12-08 16:34:32 +01:00
|
|
|
c->number--;
|
2020-02-16 20:43:35 +01:00
|
|
|
coinAdd();
|
2019-12-07 14:32:38 +01:00
|
|
|
}
|
2019-12-08 16:34:32 +01:00
|
|
|
else if (c->content==2 && c->number)
|
|
|
|
{
|
|
|
|
c->number--;
|
2020-02-16 20:43:35 +01:00
|
|
|
bonusSet(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
2019-12-08 16:34:32 +01:00
|
|
|
}
|
|
|
|
else if (c->content==3 && c->number)
|
|
|
|
{
|
|
|
|
c->number--;
|
2020-02-16 20:43:35 +01:00
|
|
|
bonusSet(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
2019-12-08 16:34:32 +01:00
|
|
|
}
|
2019-12-16 19:23:36 +01:00
|
|
|
else if (c->content==4 && c->number)
|
|
|
|
{
|
|
|
|
c->number--;
|
2020-02-16 20:43:35 +01:00
|
|
|
bonusSet(BONUS_STAR,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
2019-12-16 19:23:36 +01:00
|
|
|
}
|
2019-12-08 16:34:32 +01:00
|
|
|
else if (c->content==0 && mario.size==M_BIG && c->type==BRICK)
|
|
|
|
{
|
|
|
|
c->state=1;
|
|
|
|
mario.p.vy=0;
|
|
|
|
}
|
|
|
|
c->hidden=0;
|
2019-12-04 19:27:27 +01:00
|
|
|
}
|
2019-12-08 16:34:32 +01:00
|
|
|
}
|
2019-12-05 19:24:16 +01:00
|
|
|
|
|
|
|
//}
|
2019-11-30 13:57:18 +01:00
|
|
|
|
2019-11-21 19:30:54 +01:00
|
|
|
}
|