global code cleaning, especially with function names

This commit is contained in:
Milang 2020-02-16 20:43:35 +01:00
parent 0c527962ab
commit 7138dd442c
39 changed files with 597 additions and 658 deletions

Binary file not shown.

View File

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

View File

@ -1,6 +1,5 @@
// v0.3
#ifndef BONUS_H
#define BONUS_H
#define BONUS_H
#include <box.h>
@ -16,17 +15,17 @@ typedef enum
BONUS_STAR
} bonus_id; // TODO add fragment
typedef struct
typedef struct
{
int type;
box_t b;
int p1;
} bonus_t;
void bonus_set(bonus_id t, int x, int y);
void bonusSet(bonus_id t, int x, int y);
void bonus_draw();
void bonusDraw();
void bonus_move();
void bonusMove();
#endif
#endif

View File

@ -1,7 +1,8 @@
// v0.3
#ifndef BOX_H
#define BOX_H
#include <stdbool.h>
// Box type
// Used to simulate gravity and collides
@ -17,11 +18,11 @@ typedef struct
int vy :8;
int last_vy :8;
int gravity :8;
//int is_mario;
//int isMario;
} box_t;
void box_move(box_t * b);
int BoxContact(box_t const * b1, box_t const * b2);
void box_jump(box_t * b, int height);
void boxMove(box_t * b);
bool boxContact(box_t const * b1, box_t const * b2);
void boxJump(box_t * b, int height);
#endif

View File

@ -1,4 +1,3 @@
// v0.3
#ifndef BULLETS_H
#define BULLETS_H
@ -6,10 +5,13 @@
// two maximum on the screen (static)
// destroys ennemies, and is destroyed when it hits a wall
void bullet_throw();
// if there are less than two fire bullets on the screen, create a new bullet
void bulletThrow();
void bullet_display();
// draw bullets on the screen
void bulletsDraw();
void bullet_move();
// move bullets and check collisions
void bulletsMove();
#endif
#endif

View File

@ -2,19 +2,19 @@
#define CAMERA_H
// Top left corner coordinates
int camera_x();
int camera_y();
int cameraX();
int cameraY();
/* Auto track mario,
The delay is custom:
/* Auto track mario,
The delay is custom:
0 default
1 to follow perfectly mario, no delay
the higher the delay is, the longest time the camera takes to go to mario (recommended as inferior to 6)
*/
void camera_move(int delay);
void cameraMove();
void camera_reset(); // Reset camera to (0,0)
void cameraReset(); // Reset camera to (0,0)
void camera_adjust(); // Set camera on mario -> useful when there is a pipe, for example
void cameraAdjust(); // Set camera on mario -> useful when there is a pipe, for example
#endif
#endif

View File

@ -1,3 +1,7 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
#define TILE_W 8
#define TILE_H 8
@ -5,7 +9,9 @@
#define SCREEN_H 64
#include <stdbool.h>
extern bool dark_theme_enable;
extern bool is_in_water;
//extern bool dark_theme_enable;
//extern bool is_in_water;
extern int frame_id;
extern int frame_id;
#endif // CONSTANTS_H

View File

@ -1,8 +1,5 @@
#ifndef ENNEMI_H
#define ENNEMI_H
#define ENNEMI_H
#include "box.h"
#define NOMBRE_ENNEMIS 6
@ -16,7 +13,7 @@ extern const int ennemi_heights[NOMBRE_ENNEMIS];
#define KOOPA_V_ID 2
#define CARAPACE_VERTE 3
#define KOOPA_R_ID 4
#define CARAPACE_ROUGE 5
#define CARAPACE_ROUGE 5
#define GOOMBA(x,y,dir) {GOOMBA_ID,{x,y,ennemi_widths[GOOMBA_ID],ennemi_heights[GOOMBA_ID],dir,0,0,1},1,0,dir}
#define KOOPA_V(x,y,dir) {KOOPA_V_ID,{x,y,ennemi_widths[KOOPA_V_ID],ennemi_heights[KOOPA_V_ID],dir,0,0,1},1,0,dir}
@ -27,7 +24,7 @@ extern const int ennemi_heights[NOMBRE_ENNEMIS];
// Dimensions pr les boites
typedef struct
typedef struct
{
int type :8;
box_t b;
@ -36,14 +33,14 @@ typedef struct
int p1 :14;
} ennemi_t;
void display_ennemi(ennemi_t * e);
void ennemiDisplay(ennemi_t * e);
extern ennemi_t * ennemis_global;
extern int ennemis_global_size;
void display_ennemi_table();
void ennemiesDisplay();
void move_ennemi(ennemi_t *e);
void ennemiMove(ennemi_t *e);
void init_ennemi(ennemi_t * table, int s);
void EnnemiesInit(ennemi_t * table, int s);
#endif
#endif

View File

@ -1,12 +1,12 @@
#ifndef FRAMERATE_H
#define FRAMERATE_H
#define FRAMERATE_H
// Defined to 20 FPS, constant
void init_refresh();
void initRefreshTimer();
void quit_refresh();
void quitRefreshTimer();
void wait_next_frame();
void waitNextFrame();
#endif
#endif

View File

@ -15,7 +15,7 @@ typedef enum
MK_UP,
MK_JUMP, // Shift
MK_RUN // Alpha
} mkb_t;
} MKB_t;
/* This function has been coded to replace the following array
`extern mkey_t keys[6];`
@ -24,16 +24,16 @@ typedef enum
1=currently down
0=up
*/
int mkb_getstate(mkb_t const k);
int MKB_getKeyState(MKB_t const k);
// Update the keyboard, should be called at each frame
void mkb_update();
void MKB_update();
// Reset followed keys' states
void mkb_clear();
void MKB_clear();
// Experimental getkey, designed to compensate for a strange bug introduced by original getkey
// /!\ return gint keycodes
int mkb_getkey();
int MKB_getkey();
#endif

View File

@ -1,26 +1,26 @@
#ifndef LEVEL_H
#define LEVEL_H
#define LEVEL_H
// Utilitaire de décompression de level
#include <stdint.h>
typedef struct
typedef struct
{
uint8_t width;
uint8_t width;
uint8_t height;
uint8_t data[]; // rough data
} packed_level_t;
//void unpack_level(packed_level_t const * const packed_level_t);
//void unpackLevel(packed_level_t const * const packed_level_t);
void set_level(int w, int l); // Configures the level
void setLevel(int w, int l); // Configures the level
void get_lvl_id(int w, int l, char * str); // Retruns level ID into a char [4]
void getLevelID(int w, int l, char * str); // Retruns level ID into a char [4]
void malloc_error();
void mallocError();
#endif
#endif

View File

@ -1,6 +1,6 @@
#ifndef LEVEL_CHANGE_H
#define LEVEL_CHANGE_H
void LaunchUI();
void launchUI();
#endif
#endif

View File

@ -10,8 +10,11 @@
#define M_RIGHT2 3
#define M_WALK 0
#define M_LITTLE 1
#define M_SWIM 2
//#define M_LITTLE 1
//#define M_SWIM 2
#define MARIO_IMMUNITY_TIME 60
// 60/20 seconds = 3 seconds
#include "box.h"
@ -26,27 +29,28 @@ typedef struct
extern pnj mario;
extern int coins;
void mario_draw();
void marioDraw();
//void mario_physics();
void mario_jump();
void marioJump();
void resetMarioJump(); // resets coyote time & jump buffering (used by teleporters)
void mario_move();
void ResetMarioJump();
void mario_bigger();
void marioMove();
void mario_smaller();
void marioBigger();
void marioSmaller();
extern int global_quit;
extern int numero_frame;
extern int mario_x_max;
extern int mario_xMax;
extern int mario_dead;
extern int id_frame;
extern int mario_immunity;
extern int mario_has_bullets;
extern int last_vx_sign;
extern int mario_star_mode;
extern int mario_starMode;
#endif

View File

@ -8,7 +8,7 @@
#include <box.h>
typedef struct
typedef struct
{
unsigned type;
int xinit, yinit;
@ -25,29 +25,26 @@ typedef struct
};
int counter;
box_t b;
} plateforme_t;
} plateform_t;
#define PLATEFORME_HEIGHT 3
// Init macros
#define PLATEFORME_FALLING(x,y,w) {P_FALLING,x,y,.xmin=0,.xmax=0,0, {x,y,w,3, 0,0, 0,0}}
#define PLATEFORME_MOVING_H(x,y,w,v,x0,x1) {P_MOVING_H,x,y,.xmin=x0,.xmax=x1,0, {x,y,w,3, v,0, 0,0}}
#define PLATEFORME_MOVING_V(x,y,w,v,y0,y1) {P_MOVING_V,x,y,.ymin=y0,.ymax=y1,0, {x,y,w,3, 0,v, 0,0}}
//void reset_plateforme(plateforme_t* p);
void platformsMove();
void platformsDraw();
int platformsCollisionTest(int x, int y);
//void move_plateforme(plateforme_t* p); // touch mario stuff
void platformsInit(plateform_t * table, int s);
void move_plateformes();
/*
extern int plateform_table_size;
extern plateform_t* plateformes;
*/
void display_plateformes();
int plateforme_check_collide(int x, int y);
void init_plateformes(plateforme_t * table, int s);
extern int plateforme_table_size;
extern plateforme_t* plateformes;
#endif
#endif

View File

@ -4,19 +4,19 @@
#define WORLD_RUN_ENTRY 9 // 8 niveaux + mode run
#define NB_MONDES 5
void load_save(); // Ho calme toi pas tt de suite ! Utilisera BFile lorsque le header de gint sera complété
void flash_save(); // Non plus :E
void saveLoad(); // Not yet ! will use BFile
void saveWrite(); // neither :E
int get_highscore(int world, int level);
void set_highscore(int world, int level, unsigned int score);
int saveGetScore(int world, int level); // return the highest score for the correspondig challenge
void saveSetScore(int world, int level, unsigned int score);
int get_best_time(int world, int level);
void set_best_time(int world, int level, unsigned int time);
int saveGetTime(int world, int level); // return the lowest time for the corresponding challenge
void saveSetTime(int world, int level, unsigned int time);
int get_highcoins(int world, int level);
void set_highcoins(int world, int level, unsigned int coins);
int saveGetCoins(int world, int level); // return the highest number of coins for the correspondig challenge
void saveSetCoins(int world, int level, unsigned int coins);
unsigned int GetProgressStatus();
unsigned int saveGetProgressStatus();
#endif

View File

@ -6,24 +6,27 @@
//extern int score;
//extern int lifes;
extern int finish_level; // si ==-1, continue, si 0==retry, si ==1 ou + next
extern int time_id;
extern unsigned int time_id;
int get_score();
int get_coins();
void score_reset();
void score_add(int);
void score_display();
void score_add_coin();
void new_level();
void new_game();
int coinsGet();
void coinAdd();
int scoreGet();
void scoreReset();
void scoreAdd(int);
void scoreDisplay(); // display time, score & coins
void levelNew();
void gameNew();
int get_time_spent();
int getTimeSpent();
/* Lifes Management */
/* lifes Management */
int LifesGet();
void LifesSet(int);
void LifesAdd(int);
int lifesGet();
void lifesSet(int);
void lifesAdd(int);
#endif

View File

@ -40,6 +40,6 @@ extern const tileset_t mario_big;
extern const tileset_t tplateforme;
void draw_tile(int sx, int sy, tileset_t const * const set, int x, int y);
void tileDraw(int sx, int sy, tileset_t const * const set, int x, int y);
#endif

View File

@ -1,15 +1,15 @@
#ifndef TUYAU_H
#define TUYAU_H
#define TUYAU_H
typedef struct
typedef struct
{
int x, y; // En cases de 8*8
int tx, ty; // Targeted coords
int key; // Key used (may be -1 if the user doesn't have to press any key)
} teleport_t;
void set_teleporteurs(teleport_t const * const t, int const n);
void teleportersSet(teleport_t const * const t, unsigned int const n);
void teleport_active(); // Activation des teleporteurs à chaque frame
void teleportersActive(); // Activation des teleporteurs à chaque frame
#endif
#endif

View File

@ -8,7 +8,7 @@
#define W_SIZE_X 160
#define W_SIZE_Y 16
typedef enum
typedef enum
{
EMPTY=0,
EARTH,
@ -109,31 +109,24 @@ typedef struct
unsigned data :24; // raw binary format
} cell_t;
int world_get_width();
int worldGetWidth();
cell_t* world_get(int x, int y);
cell_t* worldGetCell(int x, int y);
void display_cell(int cx, int cy, int sx, int sy, int plan);
void cellDraw(int cx, int cy, int sx, int sy, int plan);
void world_set(int w, int h, int x, int y, cell_t const * a);
void worldSet(int w, int h, int x, int y, cell_t const * a);
void world_draw();
void world_move();
void worldDraw();
void worldMove();
int world_get_real_x0();
int world_get_real_y0();
void world_reset();
void worldReset();
#define CTG_SOIL 1
#define CTG_EMPTY 2
#define CTG_WATER 3
#define CTG_DEATH 4
int world_get_ctg(int x, int y);
void reset_camera();
void init_level(int w, int h, int x, int y, cell_t const * a);
int worldGetCellCategory(int x, int y);
typedef struct
{

View File

@ -13,7 +13,7 @@ boite_piece = (255, 153, 0)
boite_champi = (204, 0, 255)
brique_piece = (101, 127, 0)
beton = (84, 84, 84)
tuyau_milieu = (0, 255, 102)
tuyauMilieu = (0, 255, 102)
tuyau_bout = (50, 255, 0)
drapeau = (0, 255, 216)
goomba = (127, 76, 0)
@ -82,7 +82,7 @@ for x in range(0,img.size[0]):
elif color_compare(pixels[x,y],tuyau_bout):
code += write_char(8)
elif color_compare(pixels[x,y], tuyau_milieu):
elif color_compare(pixels[x,y], tuyauMilieu):
code += write_char(9)
elif color_compare(pixels[x,y], drapeau):

View File

@ -27,7 +27,7 @@ int abs(const int x)
static int ram_used=0;
void* malloc_prof(int size)
void* mallocProf(int size)
{
void* p=malloc(size);
if (p)
@ -41,7 +41,7 @@ void* malloc_prof(int size)
return p;
}
void free_prof(void * p)
void freeProf(void * p)
{
free(p);
ll_sendp(LEVEL_INFO, "\n[std] free called");

View File

@ -12,7 +12,7 @@
static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 0};
void bonus_set(bonus_id t, int x, int y)
void bonusSet(bonus_id t, int x, int y)
{
bonus.type=t;
if (mario.size==M_BIG && t==BONUS_CHAMPI)
@ -24,16 +24,16 @@ void bonus_set(bonus_id t, int x, int y)
bonus.p1=0;
}
void bonus_move() //+collision
void bonusMove() //+collision
{
if (bonus.type==BONUS_NONE)
return;
if (bonus.type==BONUS_STAR)
{
box_jump(&bonus.b,4);
boxJump(&bonus.b,4);
}
box_move(&bonus.b);
boxMove(&bonus.b);
if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR)
{
@ -51,50 +51,50 @@ void bonus_move() //+collision
}
}
if (bonus.b.y<0)
bonus_set(BONUS_NONE,0,0);
bonusSet(BONUS_NONE,0,0);
}
int collide=BoxContact(&mario.p, &bonus.b);
int collide=boxContact(&mario.p, &bonus.b);
if (collide)
{
if (bonus.type==BONUS_CHAMPI)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
mario_bigger();
bonusSet(BONUS_NONE,0,0);
scoreAdd(1000);
marioBigger();
}
if (bonus.type==BONUS_FLEUR)
{
bonus_set(BONUS_NONE,0,0);
bonusSet(BONUS_NONE,0,0);
mario_has_bullets=1;
score_add(1000);
scoreAdd(1000);
}
if (bonus.type==BONUS_1UP)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
LifesAdd(1);
bonusSet(BONUS_NONE,0,0);
scoreAdd(1000);
lifesAdd(1);
}
if (bonus.type==BONUS_STAR)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
mario_star_mode=1;
bonusSet(BONUS_NONE,0,0);
scoreAdd(1000);
mario_starMode=1;
}
}
}
void bonus_draw()
void bonusDraw()
{
//bonus_move();
//bonusMove();
if (bonus.type==BONUS_NONE)
return;
if (bonus.type==BONUS_CHAMPI)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &champi, 0,0);
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &champi, 0,0);
if (bonus.type==BONUS_FLEUR)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &fleur, 0,0);
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &fleur, 0,0);
if (bonus.type==BONUS_1UP)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &life_1up, 0,0);
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &life_1up, 0,0);
if (bonus.type==BONUS_STAR)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &mario_starman, 0,0);
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &mario_starman, 0,0);
}

View File

@ -7,11 +7,11 @@
int check_collision(box_t *b)
{
for (int i=0; i<ennemis_global_size; i++) if (BoxContact(&ennemis_global[i].b,b)) return 1;
for (int i=0; i<ennemis_global_size; i++) if (boxContact(&ennemis_global[i].b,b)) return 1;
return 0;
}
int BoxContact(box_t const * b1, box_t const * b2)
bool boxContact(box_t const * b1, box_t const * b2)
{
if (b1==b2) return 0;/*
bool x_collide= (mario.p.x<=e->b.x && e->b.x<=mario.p.x+mario.p.w-1) || (mario.p.x<=e->b.x+e->b.w-1 && e->b.x+e->b.w-1<=mario.p.x+mario.p.w-1);
@ -34,7 +34,7 @@ static void move_x(box_t * b)
sgn_vx=sgn(t_vx);
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;//ralentir dans l'eau
if (frame_id%coef)
return;
@ -47,9 +47,9 @@ static void move_x(box_t * b)
{
int typetemp;
if (sgn_vx>0)
typetemp=world_get_ctg(b->x+b->w-1+i*sgn_vx,b->y+j);
typetemp=worldGetCellCategory(b->x+b->w-1+i*sgn_vx,b->y+j);
else
typetemp=world_get_ctg(b->x+i*sgn_vx,b->y+j);
typetemp=worldGetCellCategory(b->x+i*sgn_vx,b->y+j);
if (typetemp==CTG_SOIL)
{
b->x+=(i-1)*sgn_vx;
@ -71,7 +71,7 @@ static void move_y(box_t * b)
int sgn_vy=sgn(b->vy);
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;// 0.5
if (frame_id%coef)
return;
@ -84,26 +84,26 @@ static void move_y(box_t * b)
{
int typetemp;
if (sgn_vy>0)
typetemp=world_get_ctg(b->x+j ,b->y+b->h-1+i);
typetemp=worldGetCellCategory(b->x+j ,b->y+b->h-1+i);
else
typetemp=world_get_ctg(b->x+j ,b->y-i);
typetemp=worldGetCellCategory(b->x+j ,b->y-i);
if (typetemp==CTG_SOIL)
{
if (b->vy>0)
{
int old=b->x;
if (world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
if (worldGetCellCategory(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (old==b->x)
{
@ -129,14 +129,14 @@ static void move_y(box_t * b)
}
void box_move(box_t * b)
void boxMove(box_t * b)
{
//velx
move_x(b);
move_y(b);
}
void box_jump(box_t * b, int height)
void boxJump(box_t * b, int height)
{
int sgn_vy=-1*sgn(height);
if (sgn_vy)
@ -144,7 +144,7 @@ void box_jump(box_t * b, int height)
int sol=0, eau=0;
for (int j=0; j<b->w; j++)
{
int typetemp=world_get_ctg(b->x+j ,b->y+sgn_vy);
int typetemp=worldGetCellCategory(b->x+j ,b->y+sgn_vy);
if (typetemp==CTG_SOIL)
sol++;
if (typetemp==CTG_WATER)

View File

@ -15,7 +15,7 @@ static bonus_t bullets[2] =
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0}
};
void bullet_throw()
void bulletThrow()
{
for (int i=0; i<2; i++)
{
@ -35,28 +35,28 @@ void bullet_throw()
}
}
void bullet_display()
void bulletsDraw()
{
for (int i=0; i<2; i++)
{
if (bullets[i].type==1)
draw_tile(bullets[i].b.x-camera_x(), bullets[i].b.y-camera_y(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
tileDraw(bullets[i].b.x-cameraX(), bullets[i].b.y-cameraY(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
}
}
void bullet_move()
void bulletsMove()
{
for (int i=0; i<2; i++)
{
if (bullets[i].type==1)
{
box_jump(&bullets[i].b,4);
box_move(&bullets[i].b);
boxJump(&bullets[i].b,4);
boxMove(&bullets[i].b);
if (bullets[i].b.vx==0)
bullets[i].type=0;
if (bullets[i].b.y<0)
bullets[i].type=0;
if (bullets[i].b.x<=camera_x()-bullets[i].b.w || bullets[i].b.x>=camera_x()+127)
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+127)
bullets[i].type=0;
for (int a=0; a<ennemis_global_size; a++)
{
@ -69,7 +69,7 @@ void bullet_move()
{
t->life=DEAD;
bullets[i].type=0;
score_add(KILL_ENNEMI);
scoreAdd(KILL_ENNEMI);
break;
}
}

View File

@ -5,40 +5,40 @@
static int y=0;
int camera_x() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int camera_y() {return max(y-32,0);}
int cameraX() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int cameraY() {return max(y-32,0);}
static int immobile=0;
static int last_vy=0;
static int distance=0;
void camera_move(int delay) // movement vertical seulement
void cameraMove() // movement vertical seulement
{
/* static int is_moving=0;
/* static int isMoving=0;
static int ref_y=0;
if (mario.p.y-camera_y()<16 || mario.p.y-camera_y()>56)
if (mario.p.y-cameraY()<16 || mario.p.y-cameraY()>56)
{
is_moving=1;
isMoving=1;
ref_y=mario.p.y;
}
if (is_moving)
if (isMoving)
{
for (int i=0; i<9; i++)
y+=sgn(mario.p.y-y);
if (y==ref_y)
is_moving=0;
isMoving=0;
}
*/
*/
static int camera_vy=0;
if (mario.p.y==last_vy) // mario arrêté
immobile++;
else
else
{
last_vy=mario.p.y;
immobile=0;
}
if (mario.p.y-camera_y()-mario.p.h<16 || mario.p.y-camera_y()>54)
if (mario.p.y-cameraY()-mario.p.h<16 || mario.p.y-cameraY()>54)
{
y+=5*sgn(mario.p.y-y);
}
@ -68,17 +68,17 @@ void camera_move(int delay) // movement vertical seulement
}
else
y+=(camera_vy*sgn(mario.p.y-y))/2;
}
last_vy=mario.p.y;
}
void camera_adjust()
void cameraAdjust()
{
y=mario.p.y;
}
void camera_reset()
void cameraReset()
{
y=0;
}
}

View File

@ -11,7 +11,7 @@ char loglevels[6][14]={"--all","--information","--warning","--critical","--fatal
void configmenu()
{
mkb_clear();
MKB_clear();
font_t const * const f=dfont(0);
while (1)
{
@ -25,11 +25,11 @@ void configmenu()
dtext(40,9,&loglevels[ll_get_level()][0],C_BLACK,C_NONE);
dupdate();
ll_pause();
int key=mkb_getkey();
int key=MKB_getkey();
if (key==KEY_EXIT)
break;
}
mkb_clear();
MKB_clear();
dfont(f);
}

View File

@ -14,7 +14,7 @@
const int ennemi_widths [NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8 , 8};
const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 12, 9, 12, 9};
void display_ennemi(ennemi_t * e)
void ennemiDisplay(ennemi_t * e)
{
if (e->life==0)
{
@ -32,7 +32,7 @@ void display_ennemi(ennemi_t * e)
}
if (e->type==NONE)
return;
if (e->b.x<=camera_x(0)-e->b.w || e->b.x>=camera_x(0)+127)
if (e->b.x<=cameraX(0)-e->b.w || e->b.x>=cameraX(0)+127)
return;
else
e->discovered=1;
@ -42,54 +42,54 @@ void display_ennemi(ennemi_t * e)
extern image_t img_goomba;
tileset_t goomba={&img_goomba, ennemi_widths[GOOMBA_ID], ennemi_heights[GOOMBA_ID], 1};
if (e->life==1)
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
if (e->life==0)
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &goomba, 0, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &goomba, 0, 0);
}
if (e->type==KOOPA_V_ID)
{
extern image_t img_koopa_verte;
tileset_t koopa_verte={&img_koopa_verte, ennemi_widths[KOOPA_V_ID], ennemi_heights[KOOPA_V_ID], 1};
if (e->life==1)
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &koopa_verte, (1+e->p1)+(time_id/8)%2, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &koopa_verte, (1+e->p1)+(time_id/8)%2, 0);
}
if (e->type==KOOPA_R_ID)
{
extern image_t img_koopa_rouge;
tileset_t koopa_rouge={&img_koopa_rouge, ennemi_widths[KOOPA_R_ID], ennemi_heights[KOOPA_R_ID], 1};
if (e->life==1)
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &koopa_rouge, (1+e->p1)+(time_id/8)%2, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &koopa_rouge, (1+e->p1)+(time_id/8)%2, 0);
}
if (e->type==CARAPACE_VERTE)
{
extern image_t img_carapace_verte;
tileset_t carapace_verte={&img_carapace_verte, ennemi_widths[CARAPACE_VERTE], ennemi_heights[CARAPACE_VERTE], 1};
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &carapace_verte, 0, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &carapace_verte, 0, 0);
}
if (e->type==CARAPACE_ROUGE)
{
extern image_t img_carapace_rouge;
tileset_t carapace_rouge={&img_carapace_rouge, ennemi_widths[CARAPACE_ROUGE], ennemi_heights[CARAPACE_ROUGE], 1};
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &carapace_rouge, 0, 0);
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &carapace_rouge, 0, 0);
}
}
bool ennemi_check_collision(ennemi_t *e) { return (BoxContact(&e->b, &mario.p)); }
bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p)); }
void hurt_mario()
void hurtMario()
{ if (mario.size==M_SMALL && mario_immunity==0)
{mario_dead=1;finish_level=0;}
else
mario_smaller();
marioSmaller();
}
void move_ennemi(ennemi_t *e)
void ennemiMove(ennemi_t *e)
{
if (e->b.x<camera_x()+128+30 && e->b.x>camera_x()-30)
if (e->b.x<cameraX()+128+30 && e->b.x>cameraX()-30)
e->discovered=1;
//if (e->b.x+e->b.w<=world_get_real_x0())
//if (e->b.x+e->b.w<=worldGetCell_real_x0())
// e->type=NONE;
if (e->discovered==0)
return;
@ -99,12 +99,12 @@ void move_ennemi(ennemi_t *e)
if (e->type==NONE)
return;
bool e_hit_mario=ennemi_check_collision(e);
if (e_hit_mario&&mario_star_mode)
bool e_hitMario=ennemi_check_collision(e);
if (e_hitMario&&mario_starMode)
{
e->life=DEAD;
e->p1=0;
score_add(200);
scoreAdd(200);
return;
}
@ -114,7 +114,7 @@ void move_ennemi(ennemi_t *e)
if (t->type!=NONE)
{
e->b.x+=sgn(e->b.vx)*(abs(e->b.vx)+(time_id%2))/2;
const int contact=BoxContact(&e->b, &t->b);
const int contact=boxContact(&e->b, &t->b);
e->b.x-=sgn(e->b.vx)*(abs(e->b.vx)+(time_id%2))/2;
if (contact && t->life!=DEAD)
{
@ -134,7 +134,7 @@ void move_ennemi(ennemi_t *e)
{
t->life=DEAD;
t->p1=0;
score_add(200);
scoreAdd(200);
}
}
}
@ -146,12 +146,12 @@ void move_ennemi(ennemi_t *e)
if ((e->b.x+j)/8!=previous_case)
{
previous_case=(e->b.x+j)/8;
gift_t * c=(gift_t*)world_get(e->b.x+j ,e->b.y-1);
gift_t * c=(gift_t*)worldGetCell(e->b.x+j ,e->b.y-1);
if ((c->type==GIFT || c->type==BRICK) && (c->time_hit_id || c->state) && e->life!=DEAD)
{
e->life=DEAD;
e->p1=0;
score_add(100);
scoreAdd(100);
break;
}
}
@ -161,7 +161,7 @@ void move_ennemi(ennemi_t *e)
if (e->type==GOOMBA_ID)
{
box_move(&e->b);
boxMove(&e->b);
if (e->b.vx==0)
{
@ -178,25 +178,25 @@ void move_ennemi(ennemi_t *e)
}
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
if (e_hitMario)
{
if (mario_fatal_hit)
{
e->life=DEAD;
e->p1=0;
score_add(200);
scoreAdd(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[GOOMBA_ID]+1;
}
else
hurt_mario();
hurtMario();
}
return;
}
if (e->type==KOOPA_V_ID)
{
box_move(&e->b);
boxMove(&e->b);
if (e->b.vx==0)
{
if (e->p1==0)
@ -212,7 +212,7 @@ void move_ennemi(ennemi_t *e)
}
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
if (e_hitMario)
{
if (mario_fatal_hit)
{
@ -220,19 +220,19 @@ void move_ennemi(ennemi_t *e)
e->b.h=ennemi_heights[CARAPACE_VERTE];
e->p1=2;
e->b.vx=0;
score_add(200);
scoreAdd(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
}
else
hurt_mario();
hurtMario();
}
return;
}
if (e->type==KOOPA_R_ID)
{
box_move(&e->b);
boxMove(&e->b);
if (e->b.vx==0)
{
if (e->p1==0)
@ -252,7 +252,7 @@ void move_ennemi(ennemi_t *e)
if (e->b.vx>0)
s=e->b.w;
if (world_get_ctg(e->b.x+s, e->b.y-1)==CTG_EMPTY && sgn(e->b.vx)==sgn(s))
if (worldGetCellCategory(e->b.x+s, e->b.y-1)==CTG_EMPTY && sgn(e->b.vx)==sgn(s))
{
e->p1*=-1;
e->b.vx=e->p1;
@ -262,7 +262,7 @@ void move_ennemi(ennemi_t *e)
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
if (e_hitMario)
{
if (mario_fatal_hit)
{
@ -270,12 +270,12 @@ void move_ennemi(ennemi_t *e)
e->b.h=ennemi_heights[CARAPACE_ROUGE];
e->p1=2;
e->b.vx=0;
score_add(200);
scoreAdd(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_ROUGE]+1;
}
else
hurt_mario();
hurtMario();
}
return;
}
@ -307,7 +307,7 @@ void move_ennemi(ennemi_t *e)
}
}
if (e_hit_mario)
if (e_hitMario)
{
if (e->p1==0 || e->p1>=2)
{
@ -339,11 +339,11 @@ void move_ennemi(ennemi_t *e)
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
}
else
hurt_mario();
hurtMario();
}
}
box_move(&e->b);
boxMove(&e->b);
return;
}
@ -354,29 +354,29 @@ void move_ennemi(ennemi_t *e)
ennemi_t * ennemis_global=0;
int ennemis_global_size=0;
void display_ennemi_table()
void ennemiesDisplay()
{
for (int i=0; i<ennemis_global_size; i++)
{
display_ennemi(&ennemis_global[i]);
ennemiDisplay(&ennemis_global[i]);
}
}
void init_ennemi(ennemi_t * table, int s)
void EnnemiesInit(ennemi_t * table, int s)
{
ennemis_global_size=0;
if (ennemis_global)
{
free_prof(ennemis_global);
freeProf(ennemis_global);
ennemis_global=0;
}
if (0==s)
return;
int size=sizeof(ennemi_t)*s;
ennemis_global=malloc_prof(size);
ennemis_global=mallocProf(size);
if (ennemis_global==0)
malloc_error();
mallocError();
ennemis_global_size=s;
memcpy(ennemis_global, table, size);
}

View File

@ -11,18 +11,18 @@ int callback(volatile void *arg)
return 0;
}
void init_refresh()
void initRefreshTimer()
{
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
timer_start(0);
}
void quit_refresh()
void quitRefreshTimer()
{
timer_stop(0);
}
void wait_next_frame()
void waitNextFrame()
{
while (1)
{

View File

@ -8,24 +8,24 @@
#include <config.h>
#include <liblog.h>
static mkb_t keys[6]={0};
static MKB_t keys[6]={0};
int mkb_getstate(mkb_t const k)
int MKB_getKeyState(MKB_t const k)
{
if (k!=MK_NONE) return keys[k];
return 0;
}
void mkb_clear()
void MKB_clear()
{
for (int i=0; i<6; i++)
keys[i]=0;
clearevents();
}
int mkb_getkey()
int MKB_getkey()
{
mkb_clear();
MKB_clear();
while (1)
{
@ -58,7 +58,7 @@ static int menu_pause() // 1 exit, 0 continue
dimage(x+2, y+2+7*choice, &img_select_arrow);
dupdate();
switch (mkb_getkey())
switch (MKB_getkey())
{
case KEY_EXIT:
return 0;
@ -97,10 +97,10 @@ static int menu_pause() // 1 exit, 0 continue
break;
if (a==10) // Cheat code
{
mario_bigger();
marioBigger();
mario_has_bullets=1;
LifesAdd(20);
lifesAdd(20);
extern image_t img_dev;
dimage(0,0,&img_dev);
dupdate();
@ -115,7 +115,7 @@ static int menu_pause() // 1 exit, 0 continue
}
}
void mkb_update()
void MKB_update()
{
key_event_t e;
e=pollevent();
@ -123,7 +123,7 @@ void mkb_update()
for (int i=0; i<6; i++) if (keys[i]==2) keys[i]=1; else if (keys[i]<0 || keys[i]>2) keys[i]=0;
while(e.type!=KEYEV_NONE)
{
mkb_t k = MK_NONE;
MKB_t k = MK_NONE;
if(e.key==KEY_LEFT)
k=MK_LEFT;

View File

@ -35,43 +35,35 @@
#define PACKED_ARBRE_TRONC 16
#define PACKED_ARBRE_FEUILLES 17
void malloc_error()
void mallocError()
{
extern image_t img_ram;
timer_stop(0);
dimage(0,0,&img_ram);
dupdate();
while (1)
mkb_getkey();
while (1) MKB_getkey();
}
static uint8_t pack_access(packed_level_t const * const p, unsigned int x, unsigned int y)
static uint8_t packAccess(packed_level_t const * const p, unsigned int x, unsigned int y)
{
if (x<p->width && y<p->height)
{
return p->data[x*p->height+y];
}
else
{
return PACKED_EMPTY;
}
if (x<p->width && y<p->height) return p->data[x*p->height+y];
else return PACKED_EMPTY;
}
static void cell_set(cell_t *const array, unsigned int w, unsigned int h, unsigned int x, unsigned int y, cell_t const cell)
static void cellSet(cell_t *const array, unsigned int w, unsigned int h, unsigned int x, unsigned int y, cell_t const cell)
{
if (x<w && y<h)
array[x*h+y] = cell;
if (x<w && y<h) array[x*h+y] = cell;
}
static void unpack_level(packed_level_t * p)
static void unpackLevel(packed_level_t * p)
{
unsigned int w = p->width;
unsigned int h = p->height;
ll_sendp(LEVEL_INFO, "\nUnpacking level %dx%d", w,h);
cell_t * c = (cell_t *) malloc_prof(sizeof(cell_t) * w * h);
cell_t * c = (cell_t *) mallocProf(sizeof(cell_t) * w * h);
ll_sendp(LEVEL_INFO, "\n[i]malloc %d", sizeof(cell_t) * w * h);
if (c==0)
{ // overriding parameters
@ -84,12 +76,12 @@ static void unpack_level(packed_level_t * p)
p->width=w;
p->height=h;
cell_t * c = (cell_t *) malloc_prof(sizeof(cell_t) * w * h);
cell_t * c = (cell_t *) mallocProf(sizeof(cell_t) * w * h);
if (c==0)
malloc_error();
mallocError();
}
//ll_set_level(LEVEL_WARNING);
//ll_setLevel(LEVEL_WARNING);
int sx=0, sy=p->height; // Mario start coords
@ -101,7 +93,7 @@ static void unpack_level(packed_level_t * p)
{
for (unsigned int y=0; y<h; y++)
{
unsigned int contents = pack_access(p,x,y);
unsigned int contents = packAccess(p,x,y);
cell_t cell = {0,0};
if (contents==PACKED_EMPTY)
{
@ -113,16 +105,16 @@ static void unpack_level(packed_level_t * p)
int props=0;
{ // determiner x
int px=1;
if (pack_access(p,x-1,y)!=PACKED_STONE)
px=0;
if (pack_access(p,x+1,y)!=PACKED_STONE)
px=2;
if (packAccess(p,x-1,y)!=PACKED_STONE)
px=0;
if (packAccess(p,x+1,y)!=PACKED_STONE)
px=2;
props+=16*px;
}
{ // determiner y
int py=1;
if (pack_access(p,x,y+1)!=PACKED_STONE)
py=0;
if (packAccess(p,x,y+1)!=PACKED_STONE)
py=0;
props+=py;
}
cell_t t={EARTH,props};
@ -164,40 +156,40 @@ static void unpack_level(packed_level_t * p)
int props=0;
{ // haut du tuyau horizontal
if (pack_access(p,x-1,y)==PACKED_TUYAU_BOUT)
if (packAccess(p,x-1,y)==PACKED_TUYAU_BOUT)
{
px=1;
if (pack_access(p,x,y-1)==PACKED_TUYAU_MIDDLE)
py=2;
if (pack_access(p,x,y+1)==PACKED_TUYAU_MIDDLE)
py=4;
if (packAccess(p,x,y-1)==PACKED_TUYAU_MIDDLE)
py=2;
if (packAccess(p,x,y+1)==PACKED_TUYAU_MIDDLE)
py=4;
}
if (pack_access(p,x+1,y)==PACKED_TUYAU_BOUT)
if (packAccess(p,x+1,y)==PACKED_TUYAU_BOUT)
{
px=0;
if (pack_access(p,x,y-1)==PACKED_TUYAU_MIDDLE)
py=2;
if (pack_access(p,x,y+1)==PACKED_TUYAU_MIDDLE)
py=4;
if (packAccess(p,x,y-1)==PACKED_TUYAU_MIDDLE)
py=2;
if (packAccess(p,x,y+1)==PACKED_TUYAU_MIDDLE)
py=4;
}
}
{ // bout de tuyau vertical
if (pack_access(p,x,y-1)==PACKED_TUYAU_BOUT)
if (packAccess(p,x,y-1)==PACKED_TUYAU_BOUT)
{
py=0;
if (pack_access(p,x+1,y)==PACKED_TUYAU_MIDDLE)
px=0;
if (pack_access(p,x-1,y)==PACKED_TUYAU_MIDDLE)
px=2;
if (packAccess(p,x+1,y)==PACKED_TUYAU_MIDDLE)
px=0;
if (packAccess(p,x-1,y)==PACKED_TUYAU_MIDDLE)
px=2;
}
if (pack_access(p,x,y+1)==PACKED_TUYAU_BOUT)
if (packAccess(p,x,y+1)==PACKED_TUYAU_BOUT)
{
py=1;
if (pack_access(p,x+1,y)==PACKED_TUYAU_MIDDLE)
px=0;
if (pack_access(p,x-1,y)==PACKED_TUYAU_MIDDLE)
px=2;
if (packAccess(p,x+1,y)==PACKED_TUYAU_MIDDLE)
px=0;
if (packAccess(p,x-1,y)==PACKED_TUYAU_MIDDLE)
px=2;
}
}
props=16*px+py;
@ -209,15 +201,15 @@ static void unpack_level(packed_level_t * p)
int px=0, py=0;
int props=0;
if (/*pack_access(p,x-1,y)==PACKED_TUYAU_MIDDLE && */pack_access(p,x+1,y)!=PACKED_TUYAU_MIDDLE)
if (/*packAccess(p,x-1,y)==PACKED_TUYAU_MIDDLE && */packAccess(p,x+1,y)!=PACKED_TUYAU_MIDDLE)
{
if (pack_access(p,x+1,y)==PACKED_TUYAU_BOUT)
if (packAccess(p,x+1,y)==PACKED_TUYAU_BOUT)
{
px=1;
if (pack_access(p,x,y+1)!=PACKED_TUYAU_MIDDLE)
py=0;
if (packAccess(p,x,y+1)!=PACKED_TUYAU_MIDDLE)
py=0;
else
py=1;
py=1;
}
else
{
@ -226,15 +218,15 @@ static void unpack_level(packed_level_t * p)
}
}
if (/*pack_access(p,x+1,y)==PACKED_TUYAU_MIDDLE && */pack_access(p,x-1,y)!=PACKED_TUYAU_MIDDLE)
if (/*packAccess(p,x+1,y)==PACKED_TUYAU_MIDDLE && */packAccess(p,x-1,y)!=PACKED_TUYAU_MIDDLE)
{
if (pack_access(p,x-1,y)==PACKED_TUYAU_BOUT)
if (packAccess(p,x-1,y)==PACKED_TUYAU_BOUT)
{
px=1;
if (pack_access(p,x,y+1)!=PACKED_TUYAU_MIDDLE)
py=0;
if (packAccess(p,x,y+1)!=PACKED_TUYAU_MIDDLE)
py=0;
else
py=1;
py=1;
}
else
{
@ -250,20 +242,20 @@ static void unpack_level(packed_level_t * p)
else if (contents==PACKED_FLAG)
{
int props=0;
if (pack_access(p,x,y+1)!=PACKED_FLAG)
props=0x1400;
else if (pack_access(p,x,y+2)!=PACKED_FLAG)
props=0x1401;
else if (pack_access(p,x,y+3)!=PACKED_FLAG)
props=0x1302;
else if (pack_access(p,x,y+4)!=PACKED_FLAG)
props=0x1302;
else if (pack_access(p,x,y+5)!=PACKED_FLAG)
props=0x1202;
else if (pack_access(p,x,y+6)!=PACKED_FLAG)
props=0x1202;
if (packAccess(p,x,y+1)!=PACKED_FLAG)
props=0x1400;
else if (packAccess(p,x,y+2)!=PACKED_FLAG)
props=0x1401;
else if (packAccess(p,x,y+3)!=PACKED_FLAG)
props=0x1302;
else if (packAccess(p,x,y+4)!=PACKED_FLAG)
props=0x1302;
else if (packAccess(p,x,y+5)!=PACKED_FLAG)
props=0x1202;
else if (packAccess(p,x,y+6)!=PACKED_FLAG)
props=0x1202;
else
props=0x1102;
props=0x1102;
cell_t t={END_LEVEL,props};
cell = t;
}
@ -271,13 +263,13 @@ static void unpack_level(packed_level_t * p)
{
int px=1, py=0;
if (pack_access(p,x,y+1)==PACKED_NUAGE)
py=1;
if (packAccess(p,x,y+1)==PACKED_NUAGE)
py=1;
if (pack_access(p,x-1,y)!=PACKED_NUAGE)
px=0;
if (pack_access(p,x+1,y)!=PACKED_NUAGE)
px=2;
if (packAccess(p,x-1,y)!=PACKED_NUAGE)
px=0;
if (packAccess(p,x+1,y)!=PACKED_NUAGE)
px=2;
cell_t t={NUAGE,16*px+py};
cell = t;
@ -290,20 +282,20 @@ static void unpack_level(packed_level_t * p)
else if (contents==PACKED_ARBRE_FEUILLES)
{
int px=0;
if (pack_access(p,x+1,y)==PACKED_ARBRE_FEUILLES)
if (packAccess(p,x+1,y)==PACKED_ARBRE_FEUILLES)
{
if (pack_access(p,x-1,y)==PACKED_ARBRE_FEUILLES)
px=1;
if (packAccess(p,x-1,y)==PACKED_ARBRE_FEUILLES)
px=1;
else
px=0;
px=0;
}
else
px=2;
px=2;
cell_t t={ARBRE,16*px};
cell = t;
}
cell_set(c,w,h,x,y,cell);
cellSet(c,w,h,x,y,cell);
@ -335,39 +327,39 @@ static void unpack_level(packed_level_t * p)
}
}
ll_sendp(LEVEL_INFO, "\n[i]Converted!\n[i]Sending to level zone...", w,h);
world_set(w, h, sx, sy, c);
worldSet(w, h, sx, sy, c);
ll_sendp(LEVEL_INFO, "\n[i]Achieved unpacking", w,h);
free_prof(c);
freeProf(c);
init_ennemi(ennemis, nombre_ennemis);
EnnemiesInit(ennemis, nombre_ennemis);
}
void set_level(int w, int l)
void setLevel(int w, int l)
{
new_level();
set_teleporteurs(0,0);
world_set(0,0,0,0,0);
init_ennemi(0, 0);
init_plateformes(0, 0);
levelNew();
teleportersSet(0,0);
worldSet(0,0,0,0,0);
EnnemiesInit(0, 0);
platformsInit(0, 0);
if (w+1==1 && l+1==1) // 1-2
{
extern packed_level_t bin_lvl_1_1;
unpack_level(&bin_lvl_1_1);
unpackLevel(&bin_lvl_1_1);
teleport_t t[]=
{
{57,6, 215,12, MK_DOWN},
{227,2, 179,3, MK_RIGHT}
};
set_teleporteurs(t, sizeof(t)/sizeof(teleport_t));
teleportersSet(t, sizeof(t)/sizeof(teleport_t));
}
if (w+1==1 && l+1==2) // 1-2
{
extern packed_level_t bin_lvl_1_2;
unpack_level(&bin_lvl_1_2);
unpackLevel(&bin_lvl_1_2);
teleport_t t[]=
{
@ -376,24 +368,24 @@ void set_level(int w, int l)
{197,2, 118,4, MK_RIGHT},
{180,5, 206,2, MK_RIGHT},
};
set_teleporteurs(t, sizeof(t)/sizeof(teleport_t));
teleportersSet(t, sizeof(t)/sizeof(teleport_t));
plateforme_t plateforme0[]=
plateform_t plateforme0[]=
{
PLATEFORME_MOVING_H(8*144,6*8+5,32,1,8*142,8*150)
};
init_plateformes(plateforme0,sizeof(plateforme0)/sizeof(plateforme_t));
platformsInit(plateforme0,sizeof(plateforme0)/sizeof(plateform_t));
}
if (w+1==1 && l+1==3) // 1-2
{
extern packed_level_t bin_lvl_1_3;
unpack_level(&bin_lvl_1_3);
unpackLevel(&bin_lvl_1_3);
}
}
void get_lvl_id(int w, int l, char * str)
void getLevelID(int w, int l, char * str)
{
str[3]='\0';
sprintf(str, "%d-%d", w+1, l+1);
}
}

View File

@ -21,7 +21,7 @@ int PlayLevel(int, int); // déclaration de la fonction codée plus bas
static void LevelChanger(int world)
{
mkb_clear(); // clear keyboard
MKB_clear(); // clear keyboard
unsigned int choice=0;
while (1)
@ -38,27 +38,27 @@ static void LevelChanger(int world)
}
else dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
if (get_best_time(world,choice))
if (saveGetTime(world,choice))
{
sprintf(str, "%d", get_best_time(world,choice));
sprintf(str, "%d", saveGetTime(world,choice));
int i=0;
while (str[i])
i++;
dtext(99-6*i, 53, str, C_BLACK, C_WHITE);
}
if (get_highscore(world,choice))
if (saveGetScore(world,choice))
{
sprintf(str, "%d", get_highscore(world,choice));
sprintf(str, "%d", saveGetScore(world,choice));
int i=0;
while (str[i])
i++;
dtext(99-6*i, 45, str, C_BLACK, C_WHITE);
}
if (get_highcoins(world,choice))
if (saveGetCoins(world,choice))
{
sprintf(str, "%d", get_highcoins(world,choice));
sprintf(str, "%d", saveGetCoins(world,choice));
int i=0;
while (str[i])
i++;
@ -68,7 +68,7 @@ static void LevelChanger(int world)
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
switch (mkb_getkey())
switch (MKB_getkey())
{
case KEY_LEFT:
if (choice) /* >0 */ choice--;
@ -83,26 +83,26 @@ static void LevelChanger(int world)
case KEY_SHIFT:
if (choice==8)
{
new_game();
gameNew();
for (int i=0; i<7; i+=0)
{
extern image_t img_new_level;
dimage(0,0,&img_new_level);
char lvl[4];
get_lvl_id(world, i, lvl);
getLevelID(world, i, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", LifesGet());
sprintf(lvl, "%d", lifesGet());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
int a=PlayLevel(world, i);
if (a==0) LifesAdd(-1);
if (a==0) lifesAdd(-1);
if (a==1) i++;
if (a==-1) break;
if (LifesGet()==0)
if (lifesGet()==0)
{
extern image_t img_game_over;
dimage(0,0,&img_game_over);
@ -112,40 +112,40 @@ static void LevelChanger(int world)
break;
}
}
set_highscore(world, choice, get_score());
saveSetScore(world, choice, scoreGet());
}
else
{
extern image_t img_new_level;
dimage(0,0,&img_new_level);
char lvl[4];
get_lvl_id(world, choice, lvl);
getLevelID(world, choice, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", LifesGet());
sprintf(lvl, "%d", lifesGet());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
playagain:
new_game();
gameNew();
switch (PlayLevel(world, choice))
{
case 1: // if level completed
set_best_time(world, choice, get_time_spent());
set_highscore(world, choice, get_score());
set_highcoins(world, choice, get_coins());
saveSetTime(world, choice, getTimeSpent());
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
break; // go back to menu
case 0: // save score anyways
set_highscore(world, choice, get_score());
set_highcoins(world, choice, get_coins());
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
goto playagain;
break;
case -1:
set_highscore(world, choice, get_score());
set_highcoins(world, choice, get_coins());
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
break; // do not play again
}
}
@ -162,7 +162,7 @@ static void LevelChanger(int world)
void LaunchUI() // Main Menu
void launchUI() // Main Menu
{
extern image_t img_mainmenu;
@ -170,14 +170,14 @@ void LaunchUI() // Main Menu
unsigned int choice_x=0, choice_y=0;
while (1)
{
mkb_clear();
MKB_clear();
dimage(0,0,&img_mainmenu);
// Draw world images, but only unlocked ones
//Show unlocked worlds
extern image_t img_w1, img_w2, img_w3, img_w4, img_w5;
switch (GetProgressStatus())
switch (saveGetProgressStatus())
{
case 4:
dimage(xt, yt+24, &img_w5);
@ -201,7 +201,7 @@ void LaunchUI() // Main Menu
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
switch (mkb_getkey())
switch (MKB_getkey())
{
case KEY_UP:
if (choice_y) // >0
@ -239,7 +239,7 @@ void LaunchUI() // Main Menu
return;
default:
if (4*choice_y+choice_x<=GetProgressStatus())
if (4*choice_y+choice_x<=saveGetProgressStatus())
LevelChanger(4*choice_y+choice_x);
}
break;
@ -259,32 +259,32 @@ int frame_id;
int PlayLevel(int w, int l)
{
init_refresh();
initRefreshTimer();
//int finish_status=0; // FAil
finish_level=0; mario_dead=0;
set_level(w, l);
setLevel(w, l);
if (map_current==0)
{
timer_stop(0);
return -1;
}
camera_adjust();
bonus_set(0, 0, 0);
cameraAdjust();
bonusSet(0, 0, 0);
while(global_quit==0)
{
wait_next_frame();
waitNextFrame();
frame_id++;
//mario_move();
//marioMove();
world_move();
worldMove();
dclear(C_WHITE);
world_draw(mario.p.x,mario.p.y);
score_display();
worldDraw(mario.p.x,mario.p.y);
scoreDisplay();
dupdate();
if (mario_dead)
@ -293,25 +293,25 @@ int PlayLevel(int w, int l)
int i=6;
while(mario.p.y>=0)
{
wait_next_frame();
waitNextFrame();
mario.p.y+=i;
dclear(C_WHITE);
world_draw(mario.p.x,mario.p.y);
mario_draw();
score_display();
worldDraw(mario.p.x,mario.p.y);
marioDraw();
scoreDisplay();
dupdate();
i--;
}
sleep_ms(3,1000);
quit_refresh();
quitRefreshTimer();
return 0;
}
if (finish_level)
{
quit_refresh();
quitRefreshTimer();
// TODO ajouter temps au score etc
if (finish_level==1) sleep_ms(3,3000); // win
return finish_level;

View File

@ -28,9 +28,9 @@ int main(void)
sleep_ms(3,1200);
//gint_panic_set(system_error);
ll_set_panic();
//ll_set_level(LEVEL_QUIET);
//ll_setLevel(LEVEL_QUIET);
LaunchUI();
launchUI();
return 1;
}

View File

@ -10,6 +10,7 @@
#include <camera.h>
#include <base.h>
int id_frame=0;
pnj mario=
@ -19,26 +20,28 @@ pnj mario=
M_RIGHT1, M_WALK,
0
};
int mario_x_max=0;
int mario_has_bullets=0;
static int mario_time_accel=0;
static int mario_timeAccel=0;
int mario_dead=0;
//static int mario_coins=0;
// Used to draw mario (mario direction)
int last_vx_sign=1;
//static int last_bonus=0;
static int mario_accel=0;
// After he becomes little
int mario_immunity=0;
int mario_star_mode=0;
void mario_bigger()
int mario_starMode=0;
void marioBigger()
{
mario.p.h=16;
mario.size=M_BIG;
mario_has_bullets=0;
}
void mario_smaller()
void marioSmaller()
{
mario.p.h=8;
mario.size=M_SMALL;
@ -48,23 +51,23 @@ void mario_smaller()
//mario.p.vy=5;
}
void mario_draw()
void marioDraw()
{
if ( (mario_immunity==0 || (mario_immunity/7)%2==0) && (mario_star_mode/2)%2==0)
if ( (mario_immunity==0 || (mario_immunity/7)%2==0) && (mario_starMode/2)%2==0)
{
const int mx=mario.p.x-camera_x(mario.p.x)-1;
const int my=mario.p.y-camera_y(mario.p.y);
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 (abs(mario.p.vx)>=3) draw_tile(mx, my, &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
else if (abs(mario.p.vx)>=1) draw_tile(mx, my, &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
else draw_tile(mx, my, &mario_small, 2*last_vx_sign, 0);
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);
}
else
{
if (abs(mario.p.vx)>=3) draw_tile(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
else if (abs(mario.p.vx)>=1) draw_tile(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
else draw_tile(mx, my, &mario_big, 3*last_vx_sign, mario_has_bullets);
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);
}
}
}
@ -75,12 +78,12 @@ int test_sol_le_plus_proche(int x, int y)
int t=0;
while (t==0)
{
int type_sol = world_get_ctg(x, y-1);
int type_sol = worldGetCellCategory(x, y-1);
if (type_sol==CTG_SOIL)
t=1;
if (type_sol==CTG_DEATH)
return distance+1;
type_sol = world_get_ctg(x+7, y-1);
type_sol = worldGetCellCategory(x+7, y-1);
if (type_sol==CTG_SOIL)
t=1;
if (type_sol==CTG_DEATH)
@ -94,52 +97,44 @@ int test_sol_le_plus_proche(int x, int y)
static int jump_buffering=0;
static int coyote_time=5;
void ResetMarioJump()
void resetMarioJump()
{
jump_buffering=0;
coyote_time=5;
}
int global_quit=0;
void mario_move()
void marioMove()
{
if (mario_star_mode)
{
mario_star_mode++;
if (mario_star_mode==200)
mario_star_mode=0;
}
if (mario_immunity)
{
mario_immunity++;
if (mario_immunity==60)
mario_immunity=0;
}
id_frame++;
if (mario_has_bullets==1 && mkb_getstate(MK_RUN)==2) bullet_throw();
if (mario_starMode==200) mario_starMode=0;
else if (mario_starMode) mario_starMode++;
if (mkb_getstate(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
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 (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.vx*sgn(mario.p.vx)>=6) box_jump(&mario.p, 9);
else box_jump(&mario.p, 8);
if (mario.p.vy<=0 && mkb_getstate(MK_JUMP)==2 && coyote_time<4) // n'a pas sauté alors que la touche était enfoncée et coyote time
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;
}
else if (mario.p.vy<=0 && mkb_getstate(MK_JUMP)==2) // n'a pas sauté alors que la touche était enfoncée
jump_buffering=5;
// 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
}
if (jump_buffering)
jump_buffering--;
if (jump_buffering) jump_buffering--;
for (int i=0; i<mario.p.w; i++)
{
if (world_get_ctg(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
{
coyote_time=0;
break;
@ -147,25 +142,24 @@ void mario_move()
}
coyote_time++;
if (mario.p.vy>=2 && mkb_getstate(MK_JUMP)==0)
mario.p.vy-=2;
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
int vx=sgn(mkb_getstate(MK_RIGHT) - mkb_getstate(MK_LEFT));
int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows)
int c1=world_get_ctg(mario.p.x, mario.p.y-1/*+mario.p.h*/);
int c2=world_get_ctg(mario.p.x+mario.p.w-1, mario.p.y-1/*+mario.p.h*/);
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*/);
mario_time_accel=1-mario_time_accel;
if (vx==-sgn(mario.p.vx)) mario_time_accel=1;
if (mario_time_accel)
mario_timeAccel=1-mario_timeAccel;
if (vx==-sgn(mario.p.vx)) mario_timeAccel=1;
if (mario_timeAccel)
{
if (vx)
{
// sprinte et est sur le sol
if (mkb_getstate(MK_RUN) && (c1==CTG_SOIL || c2==CTG_SOIL) && (abs(mario.p.vx)<=7 || sgn(mario.p.vx)!=vx)) mario.p.vx+=vx;
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_getstate(MK_RUN)==0 && abs(mario.p.vx)>4) mario.p.vx-=sgn(mario.p.vx);
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);
}
@ -175,50 +169,50 @@ void mario_move()
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL))
last_vx_sign=0;
if (mario.p.x+mario.p.vx<camera_x(mario.p.x))
if (mario.p.x+mario.p.vx<cameraX(mario.p.x))
{
mario.p.vx=0;
mario.p.x=camera_x(mario.p.x);
mario.p.x=cameraX(mario.p.x);
}
//teleporteurs_check();
box_move(&mario.p); // <-> + gravity
boxMove(&mario.p); // <-> + gravity
if (mario.p.y<0)
mario_dead=1;
if (mario.p.vx==0)
mario_time_accel=0;
mario_timeAccel=0;
// coins
coin_t* c;
c=(coin_t*)world_get(mario.p.x, mario.p.y);
c=(coin_t*)worldGetCell(mario.p.x, mario.p.y);
if (c->type==COIN && c->taken==0)
{score_add_coin();c->taken=1;}
c=(coin_t*)world_get(mario.p.x+mario.p.w-1, mario.p.y);
{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)
{score_add_coin();c->taken=1;}
c=(coin_t*)world_get(mario.p.x, mario.p.y+mario.p.h-1);
{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)
{score_add_coin();c->taken=1;}
c=(coin_t*)world_get(mario.p.x+mario.p.w-1, mario.p.y+mario.p.h-1);
{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)
{score_add_coin();c->taken=1;}
{coinAdd();c->taken=1;}
end_level_t *e1=(end_level_t*)world_get(mario.p.x, mario.p.y), *e2=(end_level_t*)world_get(mario.p.x+mario.p.w-1, mario.p.y);
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;
score_add(400*e1->bonus);
scoreAdd(400*e1->bonus);
}
if (e2->type==END_LEVEL)
{
finish_level=1;
score_add(400*e2->bonus);
scoreAdd(400*e2->bonus);
}
//if ((mario.p.x+mario.p.w/2)/8==(mario.p.x+mario.p.w/2-1)/8)
//{
gift_t* t=(gift_t*)world_get((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h);
gift_t* t=(gift_t*)worldGetCell((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h);
if (t->type==GIFT || t->type==BRICK)
{
@ -234,22 +228,22 @@ void mario_move()
if (c->content==1 && c->number)
{
c->number--;
score_add_coin();
coinAdd();
}
else if (c->content==2 && c->number)
{
c->number--;
bonus_set(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
bonusSet(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
}
else if (c->content==3 && c->number)
{
c->number--;
bonus_set(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
bonusSet(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
}
else if (c->content==4 && c->number)
{
c->number--;
bonus_set(BONUS_STAR,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
bonusSet(BONUS_STAR,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
}
else if (c->content==0 && mario.size==M_BIG && c->type==BRICK)
{

View File

@ -10,16 +10,16 @@
#include <gint/std/stdlib.h>
#include <base.h>
int plateforme_table_size=0;
plateforme_t* plateformes=0;
int plateform_table_size=0;
plateform_t* plateformes=0;
void reset_plateforme(plateforme_t* p)
void reset_plateforme(plateform_t* p)
{
p->b.x=p->xinit;
p->b.y=p->yinit;
}
void move_plateforme(plateforme_t* p)
void move_plateforme(plateform_t* p)
{
// Si mario et la plateforme vont se chevaucher, la plateforme est immobilisée
{
@ -34,7 +34,7 @@ void move_plateforme(plateforme_t* p)
box_t temp=p->b;
box_move(&p->b);
boxMove(&p->b);
// Si mario est sur la plateforme, il bouge avec
if (((mario.p.x<p->b.x+p->b.w && mario.p.x>=p->b.x) || (mario.p.x+mario.p.w<p->b.x+p->b.w && mario.p.x+mario.p.w>=p->b.x)) && (mario.p.y-3==p->b.y))
@ -42,7 +42,7 @@ void move_plateforme(plateforme_t* p)
box_t mario_clone=mario.p;
mario_clone.vx=temp.vx;
mario_clone.vy=temp.vy;
box_move(&mario_clone);
boxMove(&mario_clone);
mario.p.x=mario_clone.x;
mario.p.y=mario_clone.y;
}
@ -57,39 +57,39 @@ void move_plateforme(plateforme_t* p)
p->b.vy=-temp.vy;
}
void display_plateformes()
void platformsDraw()
{
if (plateformes==0 || plateforme_table_size==0)
if (plateformes==0 || plateform_table_size==0)
return;
plateforme_t * p=0;
for (int i=0; i<plateforme_table_size; i++)
plateform_t * p=0;
for (int i=0; i<plateform_table_size; i++)
{
p=&plateformes[i];
for (int j=p->b.x; j < p->b.x+p->b.w; j+=3)
draw_tile(j-camera_x(),p->b.y-camera_y(), &tplateforme, 0,0);
//drect(p->b.x-world_get_real_x0(),64-(p->b.y-world_get_real_y0()),p->b.x-world_get_real_x0()+p->b.w,64-(p->b.y-world_get_real_y0()-3), C_BLACK);
tileDraw(j-cameraX(),p->b.y-cameraY(), &tplateforme, 0,0);
//drect(p->b.x-worldGetCell_real_x0(),64-(p->b.y-worldGetCell_real_y0()),p->b.x-worldGetCell_real_x0()+p->b.w,64-(p->b.y-worldGetCell_real_y0()-3), C_BLACK);
}
}
void move_plateformes()
void platformsMove()
{
if (plateformes==0 || plateforme_table_size==0)
if (plateformes==0 || plateform_table_size==0)
return;
plateforme_t * p=0;
for (int i=0; i<plateforme_table_size; i++)
plateform_t * p=0;
for (int i=0; i<plateform_table_size; i++)
{
p=&plateformes[i];
move_plateforme(p);
}
}
int plateforme_check_collide(int x, int y)
int platformsCollisionTest(int x, int y)
{
if (plateformes==0 || plateforme_table_size==0)
if (plateformes==0 || plateform_table_size==0)
return 0;
for (int i=0; i<plateforme_table_size; i++)
for (int i=0; i<plateform_table_size; i++)
{
plateforme_t * p=&plateformes[i];
plateform_t * p=&plateformes[i];
if (p->b.x<=x && p->b.x+p->b.w>x && p->b.y<=y && p->b.y+3>y)
return 1;
}
@ -97,20 +97,20 @@ int plateforme_check_collide(int x, int y)
}
void init_plateformes(plateforme_t * table, int s)
void platformsInit(plateform_t * table, int s)
{
plateforme_table_size=0;
plateform_table_size=0;
if (plateformes)
{
free_prof(plateformes);
freeProf(plateformes);
plateformes=0;
}
if (0==table)
return;
int size=sizeof(plateforme_t)*s;
plateformes=malloc_prof(size);
int size=sizeof(plateform_t)*s;
plateformes=mallocProf(size);
if (plateformes==0)
malloc_error();
plateforme_table_size=s;
mallocError();
plateform_table_size=s;
memcpy(plateformes, table, size);
}

View File

@ -16,45 +16,45 @@ static uint32_t checksum1;
static uint32_t const file_size = sizeof(level_scores)+sizeof(level_times)+sizeof(progress_status)+sizeof(checksum1);
void load_save(){};
void flash_save(){};
void saveLoad(){};
void saveWrite(){};
int get_highscore(int world, int level)
int saveGetScore(int world, int level)
{
return level_scores[world%NB_MONDES][level%WORLD_RUN_ENTRY];
}
void set_highscore(int world, int level, unsigned int score)
void saveSetScore(int world, int level, unsigned int score)
{
if (score>level_scores[world%NB_MONDES][level%WORLD_RUN_ENTRY])
level_scores[world%NB_MONDES][level%WORLD_RUN_ENTRY]=score;
}
int get_highcoins(int world, int level)
int saveGetCoins(int world, int level)
{
return level_coins[world%NB_MONDES][level%WORLD_RUN_ENTRY];
}
void set_highcoins(int world, int level, unsigned int coins)
void saveSetCoins(int world, int level, unsigned int coins)
{
if (coins>level_coins[world%NB_MONDES][level%WORLD_RUN_ENTRY])
level_coins[world%NB_MONDES][level%WORLD_RUN_ENTRY]=coins;
}
int get_best_time(int world, int level)
int saveGetTime(int world, int level)
{
return level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY];
}
void set_best_time(int world, int level, unsigned int time)
void saveSetTime(int world, int level, unsigned int time)
{
if (level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]==0 || time<level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY])
level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]=time;
}
unsigned int GetProgressStatus()
unsigned int saveGetProgressStatus()
{
return progress_status;
}

View File

@ -15,13 +15,13 @@ int combo_id=-10;
static int pieces=0;
static unsigned int time_last_piece=0;
int time_id=0;
unsigned int time_id=0;
int time_left=0;
int time_spent=0;
int finish_level=0;
void new_game()
void gameNew()
{
lifes=3;
@ -29,49 +29,49 @@ void new_game()
score=0;
combo=0;
combo_id=-10;
mario_smaller();
marioSmaller();
mario_immunity=0;
new_level();
levelNew();
time_spent=0;
}
void new_level()
void levelNew()
{
finish_level=0;
time_left=400;
time_id=0;
}
int get_score()
int scoreGet()
{
return score;
}
int get_coins()
int coinsGet()
{
return pieces;
}
void score_reset()
void scoreReset()
{
score=0;
combo=0;
combo_id=-10;
}
void score_add_coin()
void coinAdd()
{
pieces++;
time_last_piece=time_id;
score_add(200);
scoreAdd(200);
}
void score_add(int i)
void scoreAdd(int i)
{
if (i==0)
return;
if (time_id-combo_id<=12 && time_id-combo_id>=0 && combo)
if (time_id-combo_id<=12 && combo)
{
score+=i;
combo_id=time_id;
@ -85,12 +85,12 @@ void score_add(int i)
}
}
void score_display()
void scoreDisplay()
{
char str[10];
if (time_id-combo_id<=8 && time_id-combo_id>=0 && combo) // displays score & combo only when there is a combo
if (time_id-combo_id<=8 && combo) // displays score & combo only when there is a combo
{
sprintf(str, "%d", score);
dtext(0,0,str, C_BLACK, C_WHITE);
@ -131,15 +131,15 @@ void score_display()
}
}
int get_time_spent()
int getTimeSpent()
{
return time_spent;
}
int LifesGet() { return lifes; }
int lifesGet() { return lifes; }
void LifesSet(int l) { lifes = l; }
void lifesSet(int l) { lifes = l; }
void LifesAdd(int l) { lifes += l; }
void lifesAdd(int l) { lifes += l; }

View File

@ -62,7 +62,7 @@ extern image_t img_plateforme;
const tileset_t tplateforme={&img_plateforme, 3, 3, 0};
void draw_tile(int sx, int sy, tileset_t const * const set, int x, int y)
void tileDraw(int sx, int sy, tileset_t const * const set, int x, int y)
{
// if (dark_theme==0)
dsubimage(sx, 64-sy-set->height,

View File

@ -5,80 +5,56 @@
#include <framerate.h>
#include <camera.h>
#include <gint/std/string.h>
#include <base.h>
static teleport_t teleporteurs[6]={0}; // 6 max
static int nombre_teleporteurs=0; // Nombre d'entités utilisés dans le niveau actuel
void set_teleporteurs(teleport_t const * const t, int const n)
void teleportersSet(teleport_t const * const t, unsigned int const n)
{
nombre_teleporteurs=0;
if (t)
{
if (n>6)
nombre_teleporteurs=6;
else
nombre_teleporteurs=n;
if (nombre_teleporteurs)
{
memcpy(teleporteurs, t, sizeof(teleport_t)*n);
}
nombre_teleporteurs=min(n,6);
if (nombre_teleporteurs) memcpy(teleporteurs, t, sizeof(teleport_t)*nombre_teleporteurs);
}
else nombre_teleporteurs=0;
}
void teleport_active()
void teleportersActive()
{
for (int i=0; i<nombre_teleporteurs; i++)
{
teleport_t const t = teleporteurs[i];
if ((t.x==mario.p.x/8) && (t.y*8==mario.p.y || t.y*8==mario.p.y+mario.p.h))
{
if (!mkb_getstate(t.key)) continue;
if (!MKB_getKeyState(t.key)) continue;
// Animation section
if (t.key==MK_DOWN)
/* Animation section */
if (t.key==MK_DOWN) while (mario.p.y+mario.p.h>=8*t.y)
{
while (mario.p.y+mario.p.h>=8*t.y)
{
dclear(C_WHITE);
world_draw(0,0);
dupdate();
wait_next_frame(); // 10 fps
wait_next_frame();
mario.p.y--;
}
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame(); // 20/2 = 10 fps
mario.p.y--;
}
if (t.key==MK_RIGHT)
if (t.key==MK_RIGHT) while (mario.p.x-mario.p.w<=8*t.x)
{
while (mario.p.x-mario.p.w<=8*t.x)
{
dclear(C_WHITE);
world_draw(0,0);
dupdate();
wait_next_frame(); // 10 fps
wait_next_frame();
mario.p.x++;
}
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x++;
}
if (t.key==MK_LEFT)
if (t.key==MK_LEFT) while (mario.p.x+mario.p.w>=8*t.x)
{
while (mario.p.x+mario.p.w>=8*t.x)
{
dclear(C_WHITE);
world_draw(0,0);
dupdate();
wait_next_frame(); // 10 fps
wait_next_frame();
mario.p.x--;
}
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x--;
}
/* End of animated section */
ResetMarioJump();
resetMarioJump();
mario.p.x=t.tx*8+4; mario.p.y=t.ty*8; // Move Mario
mario.p.vx=0; mario.p.vy=0; // Disables every move of mario
camera_adjust();
cameraAdjust();
}
}
}

View File

@ -19,14 +19,14 @@
map_t * map_current=0;
int world_get_width()
int worldGetWidth()
{
return map_current->w*8;
}
cell_t death={0,0};
cell_t* world_get(int x, int y)
cell_t* worldGetCell(int x, int y)
{
x/=8;
y/=8;
@ -38,9 +38,9 @@ cell_t* world_get(int x, int y)
}
}
void display_cell(int cx, int cy, int sx, int sy, int plan)
void cellDraw(int cx, int cy, int sx, int sy, int plan)
{
const cell_t * cell=world_get(cx,cy);
const cell_t * cell=worldGetCell(cx,cy);
if (cell==0)
return;
if (plan==1)
@ -48,29 +48,29 @@ void display_cell(int cx, int cy, int sx, int sy, int plan)
if (cell->type==TUYAU)
{
tuyau_t* i=(tuyau_t*)cell;
draw_tile(sx, sy, &tuyau, i->x, i->y);
tileDraw(sx, sy, &tuyau, i->x, i->y);
}
if (cell->type==ARBRE)
{
arbre_t* i=(arbre_t*)cell;
draw_tile(sx, sy, &arbre, i->x, i->y);
tileDraw(sx, sy, &arbre, i->x, i->y);
}
if (cell->type==EARTH)
{
earth_t* i=(earth_t*)cell;
draw_tile(sx, sy, &earth, i->x, i->y);
tileDraw(sx, sy, &earth, i->x, i->y);
}
if (cell->type==BLOC)
{
draw_tile(sx, sy, &bloc, 0, 0);
tileDraw(sx, sy, &bloc, 0, 0);
}
if (cell->type==BLOC)
{
draw_tile(sx, sy, &bloc, 0, 0);
tileDraw(sx, sy, &bloc, 0, 0);
}
if (cell->type==BRICK)
@ -88,11 +88,11 @@ void display_cell(int cx, int cy, int sx, int sy, int plan)
if (i->hidden==0)
{
if (i->time_hit_id || i->content==0 || i->number>0)
draw_tile(sx, sy, &brick, 0, i->state);
tileDraw(sx, sy, &brick, 0, i->state);
else
draw_tile(sx, sy, &gift, 1, 0);
tileDraw(sx, sy, &gift, 1, 0);
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
draw_tile(sx, sy+8, &coin, 0, 0);
tileDraw(sx, sy+8, &coin, 0, 0);
}
}
@ -109,11 +109,11 @@ void display_cell(int cx, int cy, int sx, int sy, int plan)
if (i->hidden==0)
{
if (i->time_hit_id || i->number)
draw_tile(sx, sy, &gift, 0, 0);
tileDraw(sx, sy, &gift, 0, 0);
else
draw_tile(sx, sy, &gift, 1, 0);
tileDraw(sx, sy, &gift, 1, 0);
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
draw_tile(sx, sy+8, &coin, 0, 0);
tileDraw(sx, sy+8, &coin, 0, 0);
}
}
}
@ -122,34 +122,34 @@ void display_cell(int cx, int cy, int sx, int sy, int plan)
if (cell->type==COIN)
{
coin_t const * i=(coin_t*)cell;
draw_tile(sx, sy, &coin, i->taken, 0);
tileDraw(sx, sy, &coin, i->taken, 0);
}
if (cell->type==BUISSON || cell->type==NUAGE || cell->type==COLLINE || cell->type==CASTLE || cell->type==END_LEVEL)
{
deco_t* i=(deco_t*)cell;
if (i->type==BUISSON)
draw_tile(sx, sy, &buisson, i->x, i->y);
tileDraw(sx, sy, &buisson, i->x, i->y);
if (i->type==NUAGE)
draw_tile(sx, sy, &nuage, i->x, i->y);
tileDraw(sx, sy, &nuage, i->x, i->y);
if (i->type==COLLINE)
draw_tile(sx, sy, &colline, i->x, i->y);
tileDraw(sx, sy, &colline, i->x, i->y);
if (i->type==CASTLE)
draw_tile(sx, sy, &castle, i->x, i->y);
tileDraw(sx, sy, &castle, i->x, i->y);
if (i->type==END_LEVEL)
draw_tile(sx-8, sy, &end_level, 0, i->y);
tileDraw(sx-8, sy, &end_level, 0, i->y);
}
}
}
int world_get_ctg(int x, int y)
int worldGetCellCategory(int x, int y)
{
cell_t *c=world_get(x,y);
cell_t *c=worldGetCell(x,y);
if (c==0)
{
return CTG_DEATH;
}
if (plateforme_check_collide(x,y))
if (platformsCollisionTest(x,y))
return CTG_SOIL;
if (c->type==ARBRE)
{
@ -171,73 +171,48 @@ int world_get_ctg(int x, int y)
}
}
void world_draw()
void worldDraw()
{
camera_move(0);
//camera_adjust();
int mx0=camera_x();
int my0=camera_y();
cameraMove(0);
//cameraAdjust();
int mx0=cameraX();
int my0=cameraY();
int sx0=mx0%8;
int sy0=my0%8;
//int mx=mx0;
int mx, my;
for (int i=0, mx=mx0; i<=17; i++, mx+=8)
{
//int my=my0;
for (int j=0, my=my0; j<=9; j++, my+=8)
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0,0); //ap
//my+=8;
}
//mx+=8;
}
bonus_draw();
display_ennemi_table();
//background tiles
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,0);
bullet_display();
display_plateformes();
mario_draw();
bonusDraw();
ennemiesDisplay();
//int mx, my;
bulletsDraw();
platformsDraw();
marioDraw();
//foreground tiles
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);
mx=mx0;
for (int i=0; i<=17; i++)
{
int my=my0;
for (int j=0; j<=9; j++)
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0,1); //pp
my+=8;
}
mx+=8;
}
//teleporteurs_display();
//dvline(teleporteurs[0].x-world_get_real_x0(),C_BLACK);
/*
if (mkb_getstate(MK_JUMP)) drect(1,60,6,63,C_BLACK);
if (mkb_getstate(MK_RUN)) drect(8,60,13,63,C_BLACK);
*/
// draw immunity remaining time
if (mario_immunity) drect(0,4+mario_immunity,2,64, C_BLACK);
// It's a progress bar on the left side
if (mario_immunity) drect(0,64-MARIO_IMMUNITY_TIME+mario_immunity,2,64, C_BLACK);
}
void world_move()
void worldMove()
{
mkb_update();
MKB_update();
for (int i=0; i<ennemis_global_size; i++)
{
move_ennemi(&ennemis_global[i]);
ennemiMove(&ennemis_global[i]);
}
bonus_move();
bullet_move();
move_plateformes();
mario_move();
teleport_active();
bonusMove();
bulletsMove();
platformsMove();
marioMove();
teleportersActive();
}
void world_set(int w, int h, int x, int y, cell_t const * a)
void worldSet(int w, int h, int x, int y, cell_t const * a)
{
// Resets mario's vx
mario.p.vx=0; mario.p.vy=0;
@ -245,7 +220,7 @@ void world_set(int w, int h, int x, int y, cell_t const * a)
// Free the previous map
if (map_current)
{
free_prof(map_current);
freeProf(map_current);
map_current=0;
}
@ -257,7 +232,7 @@ void world_set(int w, int h, int x, int y, cell_t const * a)
int size= 4*sizeof(int) + sizeof(cell_t)*w*h;
// Copy map into ram
map_current=(map_t*)malloc_prof(size); if (map_current==0) malloc_error();
map_current=(map_t*)mallocProf(size); if (map_current==0) mallocError();
// Copy the map to ram
map_current->w = w;