Browse Source

updated coyote time code

(cleaning some code to add functionnalities later)
master
Milang 2 years ago
parent
commit
14caa99616
  1. BIN
      SuperCbr.g1a
  2. BIN
      assets-fx/bin/lvl_1_4.png
  3. 4
      include/base.h
  4. 2
      include/bonus.h
  5. 4
      include/box.h
  6. 6
      include/constants.h
  7. BIN
      levelconverter/1_4.png
  8. 2
      src/base.c
  9. 102
      src/bonus.c
  10. 24
      src/box.c
  11. 11
      src/bullet.c
  12. 6
      src/level.c
  13. 43
      src/mario.c

BIN
SuperCbr.g1a

Binary file not shown.

BIN
assets-fx/bin/lvl_1_4.png

Binary file not shown.

4
include/base.h

@ -11,8 +11,8 @@ int sgn(const int x);
int abs(const int x);
void* mallocProf(int size);
void* mallocProf(const int size);
void freeProf(void * p);
void freeProf(void * const p);
#endif

2
include/bonus.h

@ -22,7 +22,7 @@ typedef struct
int p1;
} bonus_t;
void bonusSet(bonus_id t, int x, int y);
void bonusSet(bonus_id const t, int const x, int const y);
void bonusDraw();

4
include/box.h

@ -22,7 +22,9 @@ typedef struct
} box_t;
void boxMove(box_t * b);
bool boxContact(box_t const * b1, box_t const * b2);
void boxJump(box_t * b, int height);
void boxJump(box_t * b, int height, bool floor_needed);
#endif

6
include/constants.h

@ -1,15 +1,9 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
#define TILE_W 8
#define TILE_H 8
#define SCREEN_W 128
#define SCREEN_H 64
#include <stdbool.h>
//extern bool dark_theme_enable;
//extern bool is_in_water;
#endif // CONSTANTS_H

BIN
levelconverter/1_4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

2
src/base.c

@ -27,7 +27,7 @@ int abs(const int x)
static int ram_used=0;
void* mallocProf(int size)
void* mallocProf(int const size)
{
void* p=malloc(size);
if (p)

102
src/bonus.c

@ -1,61 +1,52 @@
#include "bonus.h"
#include "box.h"
#include "mario.h"
#include "world.h"
#include "tile.h"
#include "score.h"
#include "ennemi.h"
#include "constants.h"
#include <stdbool.h>
#include <base.h>
#include <camera.h>
#include <bonus.h>
#include <box.h>
#include <mario.h>
#include <constants.h>
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.p.h==M_BIG && t==BONUS_CHAMPI)
bonus.type=BONUS_FLEUR;
bonus.b.x=x;
bonus.b.y=y;
bonus.b.vx=0;
bonus.b.vy=0;
bonus.p1=0;
// champignon ou fleur
if (mario.p.h == M_BIG && t == BONUS_CHAMPI) bonus.type = BONUS_FLEUR;
else bonus.type=t;
// coordonnees spawn
bonus.b.x = x; bonus.b.y = y;
bonus.b.vx = bonus.b.vy = bonus.p1=0;
}
#include <score.h> // bonus en cas de prise
void bonusMove() //+collision
{
if (bonus.type==BONUS_NONE)
return;
if (bonus.type == BONUS_NONE) return;
if (bonus.type==BONUS_STAR)
{
boxJump(&bonus.b,4);
}
// animation de l'objet
boxMove(&bonus.b);
if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR)
switch (bonus.type)
{
case BONUS_STAR:
// bounce
boxJump(&bonus.b, 4, true);
// fall through
case BONUS_CHAMPI:
case BONUS_1UP:
// bounce against walls
if (bonus.b.vx==0)
{
if (bonus.p1==0)
{
bonus.b.vx=2;
bonus.p1=1;
}
else
{
bonus.p1*=-1;
bonus.b.vx=2*bonus.p1;
}
if (bonus.p1==0) bonus.p1=1;
else bonus.p1*=-1;
bonus.b.vx=2*bonus.p1;
}
if (bonus.b.y<0)
bonusSet(BONUS_NONE,0,0);
}
int collide=boxContact(&mario.p, &bonus.b);
if (collide && bonus.type!=BONUS_NONE)
if (bonus.type!=BONUS_NONE && boxContact(&mario.p, &bonus.b))
{
switch (bonus.type)
{
@ -78,17 +69,30 @@ void bonusMove() //+collision
}
}
#include <camera.h>
#include <tile.h>
void bonusDraw()
{
//bonusMove();
if (bonus.type==BONUS_NONE)
return;
if (bonus.type==BONUS_CHAMPI)
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &champi, 0,0);
if (bonus.type==BONUS_FLEUR)
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &fleur, 0,0);
if (bonus.type==BONUS_1UP)
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &life_1up, 0,0);
if (bonus.type==BONUS_STAR)
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &mario_starman, 0,0);
if (bonus.type==BONUS_NONE) return;
tileset_t const * t=0;
switch (bonus.type)
{
case BONUS_CHAMPI:
t=&champi;
break;
case BONUS_FLEUR:
t=&fleur;
break;
case BONUS_1UP:
t=&life_1up;
break;
case BONUS_STAR:
t=&mario_starman;
break;
}
if (t) tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), t, 0,0);
}

24
src/box.c

@ -151,23 +151,21 @@ void boxMove(box_t * b)
move_y(b);
}
void boxJump(box_t * b, int height)
void boxJump(box_t * b, int height, bool floor_needed)
{
int sgn_vy=-1*sgn(height);
if (!floor_needed)
{
b->vy=height;
return;
}
const int sgn_vy=-1*sgn(height);
if (sgn_vy)
{
int sol=0, eau=0;
for (int j=0; j<b->w; j++)
for (int j = 0; j < b->w; j++) if (worldGetCellCategory( b->x + j, b->y + sgn_vy) == CTG_SOIL)
{
int typetemp=worldGetCellCategory(b->x+j ,b->y+sgn_vy);
if (typetemp==CTG_SOIL)
sol++;
if (typetemp==CTG_WATER)
eau++;
b->vy=height;
return;
}
if (sol)
b->vy=height;
else if (eau)
b->vy+=height/2;
}
}

11
src/bullet.c

@ -24,12 +24,13 @@ void bulletThrow()
bullets[i].type=1;
bullets[i].b.x=mario.p.x;
bullets[i].b.y=mario.p.y+8;
if (mario.last_vx_sgn==0)
bullets[i].b.vx=-9; //speed = 9
else
bullets[i].b.vx=9;
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=mario.last_vx_sgn;
return;
}
}
@ -44,7 +45,7 @@ void bulletsMove()
{
for (int i=0; i<2; i++) if (bullets[i].type) // bullet active
{
boxJump(&bullets[i].b,4);
boxJump( &bullets[i].b, 4, true);
boxMove(&bullets[i].b);
if (bullets[i].b.vx==0) bullets[i].type=0; // delete a bullet if it is stopped

6
src/level.c

@ -391,6 +391,12 @@ void setLevel(int w, int l)
extern packed_level_t bin_lvl_1_3;
unpackLevel(&bin_lvl_1_3);
}
if (w+1==1 && l+1==4) // 1-2
{
extern packed_level_t bin_lvl_1_4;
unpackLevel(&bin_lvl_1_4);
}
}
void getLevelID(int w, int l, char * str)

43
src/mario.c

@ -53,13 +53,12 @@ void marioDraw()
}
}
static int jump_buffering=0;
static int coyote_time=5;
#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_buffering=0;
coyote_time=5;
jump_input = 0;
}
int global_quit=0;
@ -76,31 +75,31 @@ void marioMove()
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)
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 (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9);
else boxJump(&mario.p, 8);
if (jump_input>0) jump=1;
else jump_input=-COYOTE_INTERVAL;
break;
}
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
{
if (mario.p.vx*sgn(mario.p.vx)>=6) mario.p.vy=9;
else mario.p.vy=8;
}
// 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
// jump buffering
if (MKB_getKeyState(MK_JUMP)==2)
{
if (jump_input<0) jump = 1; // break the rules
else jump_input = 1;
}
if (jump_buffering) jump_buffering--;
if (jump_input) jump_input++;
if (jump_input==COYOTE_INTERVAL+1) jump_input=0;
for (int i=0; i<mario.p.w; i++)
if (jump)
{
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
{
coyote_time=0;
break;
}
if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9, 0);
else boxJump(&mario.p, 8, 0);
}
coyote_time++;
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
}

Loading…
Cancel
Save