opimisations about mario

master
Milang 3 years ago
parent 86286e4b29
commit 1a877773f7
  1. BIN
      SuperCbr.g1a
  2. 19
      include/mario.h
  3. 8
      src/bonus.c
  4. 4
      src/bullet.c
  5. 6
      src/ennemi.c
  6. 2
      src/keyboard.c
  7. 8
      src/levelchanger.c
  8. 61
      src/mario.c
  9. 4
      src/score.c
  10. 2
      src/world.c

Binary file not shown.

@ -1,8 +1,8 @@
#ifndef MARIO_H
#define MARIO_H
#define M_SMALL 0
#define M_BIG 1
#define M_SMALL 8
#define M_BIG 16
#define M_LEFT1 0
#define M_LEFT2 1
@ -21,10 +21,11 @@
typedef struct
{
box_t p;
int size; // small, big
int type1; // left1 left2, right1, right2,
int type2; // jump, down...
int running;
unsigned starMode :9;
unsigned immunity :6;
unsigned last_vx_sgn :1;
unsigned dead :1;
unsigned bullets :1;
} pnj;
extern pnj mario;
extern int coins;
@ -37,12 +38,6 @@ void marioSmaller();
extern int global_quit;
extern int numero_frame;
extern int mario_xMax;
extern int mario_dead;
extern int mario_immunity;
extern int mario_has_bullets;
extern int last_vx_sign;
extern int mario_starMode;
#endif

@ -15,7 +15,7 @@ static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 0};
void bonusSet(bonus_id t, int x, int y)
{
bonus.type=t;
if (mario.size==M_BIG && t==BONUS_CHAMPI)
if (mario.p.h==M_BIG && t==BONUS_CHAMPI)
bonus.type=BONUS_FLEUR;
bonus.b.x=x;
bonus.b.y=y;
@ -61,8 +61,8 @@ void bonusMove() //+collision
{
case BONUS_CHAMPI:
case BONUS_FLEUR:
if (mario.size==M_SMALL) marioBigger();
else mario_has_bullets=1;
if (mario.p.h==M_SMALL) marioBigger();
else mario.bullets=1;
break;
case BONUS_1UP:
@ -71,7 +71,7 @@ void bonusMove() //+collision
case BONUS_STAR:
bonusSet(BONUS_NONE,0,0);
mario_starMode=1;
mario.starMode=1;
}
scoreAdd(1000);
bonusSet(BONUS_NONE,0,0);

@ -24,12 +24,12 @@ void bulletThrow()
bullets[i].type=1;
bullets[i].b.x=mario.p.x;
bullets[i].b.y=mario.p.y+8;
if (last_vx_sign==0)
if (mario.last_vx_sgn==0)
bullets[i].b.vx=-9; //speed = 9
else
bullets[i].b.vx=9;
bullets[i].b.vy=0;
bullets[i].p1=last_vx_sign;
bullets[i].p1=mario.last_vx_sgn;
return;
}
}

@ -106,8 +106,8 @@ bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p));
void hurtMario()
{
if (mario.size==M_SMALL && mario_immunity==0)
{mario_dead=1;finish_level=0;}
if (mario.p.h==M_SMALL && mario.immunity==0)
{mario.dead=1;finish_level=0;}
else marioSmaller();
}
@ -142,7 +142,7 @@ void ennemiMove(ennemi_t *e)
return;
bool e_hitMario=ennemi_check_collision(e);
if (e_hitMario&&mario_starMode)
if (e_hitMario&&mario.starMode)
{
e->life=DEAD;
e->p1=0;

@ -100,7 +100,7 @@ static int menu_pause() // 1 exit, 0 continue
if (a==10) // Cheat code
{
marioBigger();
mario_has_bullets=1;
mario.bullets=1;
lifesAdd(20);
extern image_t img_dev;

@ -258,7 +258,7 @@ int PlayLevel(int w, int l)
initRefreshTimer();
//int finish_status=0; // FAil
finish_level=0; mario_dead=0;
finish_level=0; mario.dead=0;
setLevel(w, l);
if (map_current==0)
{
@ -267,7 +267,7 @@ int PlayLevel(int w, int l)
}
cameraAdjust();
bonusSet(0, 0, 0);
mario.last_vx_sgn=1;
while(global_quit==0)
@ -282,9 +282,9 @@ int PlayLevel(int w, int l)
scoreDisplay();
dupdate();
if (mario_dead)
if (mario.dead)
{
mario_immunity=0;
mario.immunity=0;
int i=6;
while(mario.p.y>=0)
{

@ -14,58 +14,41 @@
pnj mario=
{
{26,17,6,8,0,0,0,1},
M_SMALL,
M_RIGHT1, M_WALK,
0
};
// if mario is able to throw fire bullets
int mario_has_bullets=0;
// If mario is dead
int mario_dead=0;
// Used to draw mario (mario direction)
int last_vx_sign=1;
// After he becomes little
int mario_immunity=0;
// Time during mario is invincible
int mario_starMode=0;
void marioBigger()
{
mario.p.h=16;
mario.size=M_BIG;
mario_has_bullets=0;
mario.p.h=M_BIG;
mario.bullets=0;
}
void marioSmaller()
{
mario.p.h=8;
mario.size=M_SMALL;
mario_has_bullets=0;
if (mario_immunity==0) mario_immunity=1;
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)
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.size==M_SMALL)
if (mario.p.h==M_SMALL)
{
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(time_id/4)%2, 0);
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(time_id/8)%2, 0);
else tileDraw(mx, my, &mario_small, 2*last_vx_sign, 0);
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*last_vx_sign+(time_id/4)%2, mario_has_bullets);
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(time_id/8)%2, mario_has_bullets);
else tileDraw(mx, my, &mario_big, 3*last_vx_sign, mario_has_bullets);
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);
}
}
}
@ -83,14 +66,14 @@ 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.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.immunity==60) mario.immunity=0;
else if (mario.immunity) mario.immunity++;
}
if (mario_has_bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
if (mario.bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
{ // Jump (with coyote time & jump buffering)
if (MKB_getKeyState(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
@ -147,8 +130,8 @@ void marioMove()
}
{ // last vx sign determination
if (vx>0 && (c1==CTG_SOIL || c2==CTG_SOIL)) last_vx_sign=1;
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL)) last_vx_sign=0;
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.vx<cameraX(mario.p.x)) // security: avoid mario to go to the left of the screen
@ -160,7 +143,7 @@ void marioMove()
boxMove(&mario.p); // apply gravity
if (mario.p.y<0) mario_dead=1; // die if out of the map
if (mario.p.y<0) mario.dead=1; // die if out of the map
{// take coins that mario touchs
coin_t* c;
@ -213,7 +196,7 @@ void marioMove()
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.size==M_BIG && c->type==BRICK)
else if (c->content==0 && mario.p.h==M_BIG && c->type==BRICK)
{
c->state=c->time_hit_id=1;
mario.p.vy=3;

@ -33,7 +33,7 @@ void gameNew()
combo=0;
combo_id=-10;
marioSmaller();
mario_immunity=0;
mario.immunity=0;
levelNew();
time_spent=0;
}
@ -111,7 +111,7 @@ void scoreDisplay()
dtext(50,0,str, C_BLACK, C_WHITE);
}
if ((mario_dead|finish_level)==0)
if ((mario.dead|finish_level)==0)
{
if (0==(time_id++)%8)
{

@ -169,7 +169,7 @@ void worldDraw()
for (int i=0, mx=mx0; i<=17; i++, mx+=8) for (int j=0, my=my0; j<=9; j++, my+=8) cellDraw(mx, my, 8*i-sx0, 8*j-sy0,1);
// draw immunity remaining time [It's a progress bar on the left side of the screen]
if (mario_immunity) drect(0,64-MARIO_IMMUNITY_TIME+mario_immunity,2,64, C_BLACK);
if (mario.immunity) drect(0,64-MARIO_IMMUNITY_TIME+mario.immunity,2,64, C_BLACK);
}

Loading…
Cancel
Save