diff --git a/SuperCbr.g1a b/SuperCbr.g1a index b617e6d..fcab2be 100644 Binary files a/SuperCbr.g1a and b/SuperCbr.g1a differ diff --git a/assets-fx/bin/lvl_1_4.png b/assets-fx/bin/lvl_1_4.png new file mode 100644 index 0000000..3dbbe1b Binary files /dev/null and b/assets-fx/bin/lvl_1_4.png differ diff --git a/include/base.h b/include/base.h index 59602f5..7a58c77 100644 --- a/include/base.h +++ b/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 diff --git a/include/bonus.h b/include/bonus.h index 0ab2b4a..8d0509c 100644 --- a/include/bonus.h +++ b/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(); diff --git a/include/box.h b/include/box.h index 151f7b1..bbda310 100755 --- a/include/box.h +++ b/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 diff --git a/include/constants.h b/include/constants.h index 50344d4..31af9e6 100644 --- a/include/constants.h +++ b/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 -//extern bool dark_theme_enable; -//extern bool is_in_water; - #endif // CONSTANTS_H diff --git a/levelconverter/1_4.png b/levelconverter/1_4.png new file mode 100644 index 0000000..12d1668 Binary files /dev/null and b/levelconverter/1_4.png differ diff --git a/src/base.c b/src/base.c index 03fc5c0..624b1e7 100644 --- a/src/base.c +++ b/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) diff --git a/src/bonus.c b/src/bonus.c index ffed65c..2fd1924 100644 --- a/src/bonus.c +++ b/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 -#include -#include +#include +#include +#include +#include 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 // 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 +#include + 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); } diff --git a/src/box.c b/src/box.c index c57871d..8ebf7a8 100755 --- a/src/box.c +++ b/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; jw; 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; } } diff --git a/src/bullet.c b/src/bullet.c index bab3cc5..69804c7 100644 --- a/src/bullet.c +++ b/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 diff --git a/src/level.c b/src/level.c index bbcdb01..59a93ce 100644 --- a/src/level.c +++ b/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) diff --git a/src/mario.c b/src/mario.c index e378d55..1f0c2c0 100755 --- a/src/mario.c +++ b/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) - { - if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9); - else boxJump(&mario.p, 8); + bool jump=0; // will he jump ? - 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 + // 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; } - if (jump_buffering) jump_buffering--; - - for (int i=0; i=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 }