Compare commits

...

49 Commits

Author SHA1 Message Date
Milang 47529dd99c Delete unused pictures 2020-04-04 14:57:25 +02:00
Milang 2a85f98b93 add spikes (25%) 2020-04-03 19:20:03 +02:00
Milang 14caa99616 updated coyote time code
(cleaning some code to add functionnalities later)
2020-04-03 14:43:45 +02:00
Milang 1a877773f7 opimisations about mario 2020-03-14 15:02:12 +01:00
Milang 86286e4b29 new brick behaviour when destroying 2020-03-13 13:10:01 +01:00
Milang 0eaaac1a9c fix flour bug
this bug permitted to throw bullets without being big, when you are small and take a flower
2020-03-13 12:10:06 +01:00
Milang 0f6f429514 completed level 3
(some adjustements may come)
2020-03-13 10:55:17 +01:00
Milang 21734f0765 completing lvl 1- 3
adding items for 1-3
to be continued...
2020-03-11 11:41:59 +01:00
Milang e06d2eb947 update build 2020-03-11 11:29:22 +01:00
Milang b6ae4b8cc9 plante piranha completée 2020-03-10 19:34:09 +01:00
Milang eb1e3e1fc6 completing piranha plants 2020-03-10 19:20:06 +01:00
Milang 9476c81e50 level changes
currently adding plants (part 1)
2020-03-07 15:22:39 +01:00
Milang 35c1214270 Fixed camera 2020-03-07 15:22:07 +01:00
Milang 23b98fd3d4 fix minor camera "bugs"
&correct error provided by previour commit
2020-03-04 15:08:35 +01:00
milang 13872b3dcb reduce koopa code
merge code from KOOPA_V & KOOPA_R
2020-02-29 19:15:09 +01:00
milang 5f9791f6aa optimized ennemi behaviour (to be tested)
replace ennemies specific behaviours by a switch => means less duplicated code
2020-02-29 19:01:17 +01:00
milang 1b3acce432 update ennemi functions
use `ennemi_t const * ` instead of `ennemi_t *` in display methods
2020-02-29 18:24:33 +01:00
Milang 6a744b0547 clean code & prepare to add piranha plants 2020-02-25 18:42:40 +01:00
Milang 76fe4d2e3f improve time & score displaying 2020-02-25 17:35:06 +01:00
Milang 9760257d76 fallback to getkey after gint's getkey improvements 2020-02-23 13:50:59 +01:00
Milang 7c9da97baf last chance to fix timer bug 2020-02-22 17:56:09 +01:00
Milang 98ff078150 fix second timer bug 2020-02-20 18:24:40 +01:00
Milang da4d716878 Fix timer bug reported by @Calcloverhk 2020-02-20 15:45:41 +01:00
Milang a2754a92fd fix flag drawing 2 2020-02-18 14:35:26 +01:00
Milang 3c467a5c5b correct flag drawing 2020-02-18 14:32:44 +01:00
Milang 2547765eef add commands for the camera & slow down ennemies to their initial speed 2020-02-18 13:47:44 +01:00
Milang 8306be7e7a minimize ram use due to a lack of ram 2020-02-18 13:03:57 +01:00
Milang f739816d03 clean bullets & correct special brick bug 2020-02-17 19:16:50 +01:00
Milang 7475d478f5 some code cleaning 2020-02-17 18:43:16 +01:00
Milang 5aeb14b1c6 fix minor brick display bug 2020-02-17 17:53:37 +01:00
Milang 72d1ce0255 clean mario.c source code 2020-02-17 14:49:03 +01:00
Milang 27a22209e3 fix minor hitbox bug when conflict with platform & blocs 2020-02-17 10:45:11 +01:00
Milang 7138dd442c global code cleaning, especially with function names 2020-02-16 20:43:35 +01:00
Milang 0c527962ab clear world.c code 2020-02-16 18:47:20 +01:00
Milang de30485e46 add left animation for pipes 2020-02-16 15:20:35 +01:00
Milang 45a70614a0 fix coyote time bug and change a little hitboxes 2020-02-16 13:32:16 +01:00
Milang 99120d5299 new pipe sprite 2020-02-16 12:53:02 +01:00
Milang 6d29add2da new mario hit box => reduced width 2020-02-16 12:51:27 +01:00
Milang 4fb0254dba update textures, animations & add new keyboard keys for debug 2020-02-16 11:49:01 +01:00
Milang ef10b6c6e6 fix time over bug 2020-02-16 11:14:53 +01:00
Milang e2b6eac34b fix keyboard bug, lighten interface & clean some parts of the code 2020-02-15 19:35:49 +01:00
Milang d9d6648a17 clean ingame interface -> score & coins are hidden, and are shown only when they change 2020-02-15 14:40:01 +01:00
Milang 8ab8a4cd7a add fx9860g emulator integrated to the folder
clean LaunchUI() func (proper switch etc..)
2020-02-15 13:41:50 +01:00
Milang fae77016d5 add a new camera system (experimental) 2020-02-07 10:40:24 +01:00
Milang 1aa5edd231 add coyote time & jump buffering 2020-02-07 10:39:43 +01:00
Milang 4ed9222790 correct fire bullet speed 2020-02-07 10:39:21 +01:00
Milang e6ed094095 add specific comportement when a plateform is could pass trough mario 2020-02-04 20:34:30 +01:00
Milang 48625d4ce4 update start coords 2020-02-04 20:15:36 +01:00
Milang a6bb83f355 add plateforms as complete physical objects
there are no max coordinates any longer, but now thay can fall, and there is a better support with mario (not complete yet)
2020-02-04 20:12:17 +01:00
73 changed files with 1667 additions and 1615 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
build-fx/*
build-cg/*
build-cg/*
INIT/CasioRAM.mem
SuperCbr.dlw

12
AddinInfo.txt Normal file
View File

@ -0,0 +1,12 @@
//------------------------------------------------------------------
// Addin-Application header control file, created with the CASIO SDK
//------------------------------------------------------------------
[OUTPUT] : "SUPERCBR.G1A"
[BINDATA] : "FXADDINror.bin"
[DISPNAME] : "SuperCbr"
[APPNAME] : "@SUPERCB"
[VERSION] : "01.00.0000"
[APL_ICON] : "MainIcon.bmp"
[MODULE_NUM] : 0
[MOD1_TITLE] : "SuperCbr"
[MOD1_ICON] : "eActivityIcon.bmp"

BIN
INIT/CasioRAM.mem Normal file

Binary file not shown.

BIN
INIT/CasioRAMCPU.mem Normal file

Binary file not shown.

BIN
MainIcon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

1
SuperCbr.dlr Normal file
View File

@ -0,0 +1 @@
[DLSimRunSpace]

112
SuperCbr.dlw Normal file
View File

@ -0,0 +1,112 @@
[DLSimWorkSpace]
[_1]
Type=5
Order=0
Top=15
Left=2235
Height=4740
Width=5565
State=0
Flags=00000020
OptionA=0
[_2]
Type=1
Order=1
Top=15
Left=7800
Height=6885
Width=8400
State=0
Flags=00000001
OptionA=15
OptionB=15
[_3]
Type=6
Order=2
Top=4035
Left=2715
Height=6390
Width=5535
State=0
Flags=00000001
OptionA=0
[_4]
Type=7
Order=6
Top=4740
Left=2220
Height=3165
Width=5565
State=0
Flags=00000000
OptionA=0
[_5]
Type=8
Order=5
Top=7905
Left=2220
Height=3225
Width=5580
State=0
Flags=00000000
OptionA=0
[_6]
Type=3
Order=9
Top=0
Left=10788
Height=6348
Width=2232
State=16
Flags=00000000
OptionA=0
[_7]
Type=2
Order=8
Top=6348
Left=7800
Height=3588
Width=5220
State=16
Flags=00000000
OptionA=0
[_8]
Type=17
Order=4
Top=15
Left=-15
Height=11115
Width=2235
State=0
Flags=00000000
OptionA=0
[_9]
Type=15
Order=3
Top=4740
Left=2235
Height=6345
Width=5595
State=0
Flags=00000000
OptionA=0
[_32]
Type=16
Order=7
Top=0
Left=2208
Height=4584
Width=5592
State=16
Flags=00000020
OptionA=0

Binary file not shown.

12
SuperCbr.g1w Normal file
View File

@ -0,0 +1,12 @@
[DLSimProject]
Name=SuperCbr
Version=1.00.0000
Model=:fx-9860G.dlm
SourcePath=SRC
MemoryPath=INIT
MemCardPath=SDCard
[Program1]
Program=SUPERCBR.G1A
Debug=Debug\FXADDINror.dbg
LoadAddress=80000000:90100000

Binary file not shown.

BIN
assets-fx/bin/lvl_1_3.png Normal file

Binary file not shown.

BIN
assets-fx/bin/lvl_1_4.png Normal file

Binary file not shown.

Binary file not shown.

BIN
assets-fx/icon-fx.png~ Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 616 B

After

Width:  |  Height:  |  Size: 616 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
assets-fx/img/plante.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
assets-fx/img/spikes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 756 B

BIN
eActivityIcon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

View File

@ -1,5 +1,5 @@
#ifndef BASE_FUNCTIONS_H
#define BASE_FUNCTIONS_H
#define BASE_FUNCTIONS_H
// On va essayer de grapiller quelques octets d'executable avec ça
@ -9,8 +9,10 @@ int min(const int x, const int y);
int sgn(const int x);
void* malloc_prof(int size);
int abs(const int x);
void free_prof(void * p);
void* mallocProf(const int size);
#endif
void freeProf(void * const 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 const t, int const x, int const 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,13 @@ 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);
void boxMove(box_t * b);
void box_jump(box_t * b, int height);
bool boxContact(box_t const * b1, box_t const * b2);
#endif
void boxJump(box_t * b, int height, bool floor_needed);
#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,11 +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;
extern int frame_id;
#endif // CONSTANTS_H

View File

@ -1,33 +1,37 @@
#ifndef ENNEMI_H
#define ENNEMI_H
#define ENNEMI_H
#include <box.h>
#define ALIVE 1
#define DEAD 0
#include "box.h"
#define NOMBRE_ENNEMIS 6
#define NOMBRE_ENNEMIS 7
extern const int ennemi_widths[NOMBRE_ENNEMIS];
extern const int ennemi_heights[NOMBRE_ENNEMIS];
#define NONE 0
#define GOOMBA_ID 1
#define KOOPA_V_ID 2
#define CARAPACE_VERTE 3
#define KOOPA_R_ID 4
#define CARAPACE_ROUGE 5
#define CARAPACE_ROUGE 5
#define PLANTE_ID 6
#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}
#define KOOPA_R(x,y,dir) {KOOPA_R_ID,{x,y,ennemi_widths[KOOPA_R_ID],ennemi_heights[KOOPA_R_ID],dir,0,0,1},1,0,dir}
#define GOOMBA(x,y,dir) {GOOMBA_ID,{x,y,ennemi_widths[GOOMBA_ID],ennemi_heights[GOOMBA_ID],dir,0,0,1},ALIVE,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},ALIVE,0,dir}
#define KOOPA_R(x,y,dir) {KOOPA_R_ID,{x,y,ennemi_widths[KOOPA_R_ID],ennemi_heights[KOOPA_R_ID],dir,0,0,1},ALIVE,0,dir}
#define DEAD 0
// Dimensions pr les boites
#define PLANTE(x,y) {PLANTE_ID,{x,y,ennemi_widths[PLANTE_ID],ennemi_heights[PLANTE_ID],0,0,0,0},ALIVE,0,0}
// pour plante ID, ymin est associé à p1=0
typedef struct
#define PLANTE_NLAPS 99
typedef struct
{
int type :8;
box_t b;
@ -36,14 +40,17 @@ typedef struct
int p1 :14;
} ennemi_t;
void display_ennemi(ennemi_t * e);
void ennemiDisplay(ennemi_t const * e);
extern ennemi_t * ennemis_global;
extern int ennemis_global_size;
void display_ennemi_table();
int ennemiesNumber();
void move_ennemi(ennemi_t *e);
void ennemiesDisplay();
void init_ennemi(ennemi_t * table, int s);
void ennemiMove(ennemi_t * e);
#endif
void ennemiesInit(ennemi_t * table, int s);
void plante_tour(ennemi_t *e);
#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

@ -1,10 +1,10 @@
// v0.3
#ifndef MARIO_KEYBOARD_H
#define MARIO_KEYBOARD_H
#define MARIO_KEYBOARD_H
#define KONAMI
/* Reduced keyboard
/* Reduced keyboard
It simulates a nes controller */
typedef enum
{
@ -12,10 +12,10 @@ typedef enum
MK_LEFT=0,
MK_RIGHT,
MK_DOWN,
MK_UP,
MK_UP,
MK_JUMP, // Shift
MK_RUN // Alpha
} mkb_t;
MK_RUN // Alpha
} MKB_t;
/* This function has been coded to replace the following array
`extern mkey_t keys[6];`
@ -23,17 +23,17 @@ typedef enum
2=newly pressed
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
#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 launch_ui();
void launchUI();
#endif
#endif

View File

@ -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
@ -10,43 +10,34 @@
#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"
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;
void mario_draw();
//void mario_physics();
void mario_jump();
void mario_move();
void mario_bigger();
void mario_smaller();
void marioDraw();
void marioResetJump(); // resets coyote time & jump buffering (used by teleporters)
void marioMove();
void marioBigger();
void marioSmaller();
extern int global_quit;
extern int numero_frame;
extern int mario_x_max;
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;
#endif
#endif

View File

@ -5,16 +5,13 @@
#define P_MOVING_H 1
#define P_MOVING_V 2
#include <box.h>
typedef struct
typedef struct
{
unsigned type;
int xinit, yinit;
int x, y;
int width; // height fixed to 3
int v, vinit;
union
{
@ -27,29 +24,27 @@ typedef struct
int ymax;
};
int counter;
} plateforme_t;
box_t b;
} plateform_t;
#define PLATEFORME_HEIGHT 3
#define PLATEFORME_FALLING(x,y,w) {P_FALLING,x,y,x,y,w,0,0,.xmin=0,.xmax=0,0}
#define PLATEFORME_MOVING_H(x,y,w,v,x0,x1) {P_MOVING_H,x,y,x,y,w,0,v,.xmin=x0,.xmax=x1,0}
#define PLATEFORME_MOVING_V(x,y,w,v,y0,y1) {P_MOVING_V,x,y,x,y,w,0,v,.ymin=y0,.ymax=y1,0}
// 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, 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, int score);
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, 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);
int get_progress_status();
unsigned int saveGetProgressStatus();
#endif
#endif

View File

@ -6,20 +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 lifes_get();
void lifes_lose();
void lifes_add();
int coinsGet();
void coinAdd();
int get_time_spent();
int scoreGet();
void scoreReset();
void scoreAdd(int);
void scoreDisplay(); // display time, score & coins
void levelNew();
void gameNew();
int getTimeSpent();
/* lifes Management */
int lifesGet();
void lifesSet(int);
void lifesAdd(int);
#endif

View File

@ -14,6 +14,7 @@ typedef struct
} tileset_t;
extern const tileset_t tuyau;
extern const tileset_t arbre;
extern const tileset_t brick;
extern const tileset_t earth;
extern const tileset_t gift;
@ -24,7 +25,7 @@ extern const tileset_t buisson;
extern const tileset_t colline;
extern const tileset_t castle;
extern const tileset_t end_level;
extern const tileset_t spikes;
extern const tileset_t champi;
extern const tileset_t fleur;
extern const tileset_t life_1up;
@ -39,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,10 +8,24 @@
#define W_SIZE_X 160
#define W_SIZE_Y 16
typedef enum
{
EMPTY=0,
EARTH,
BRICK,
BLOC,
END_LEVEL,
TUYAU,
ARBRE,
GIFT,
COIN,
SPIKES,
NUAGE,
BUISSON,
COLLINE,
CASTLE,
} cell_id;
#define EMPTY 0
#define EARTH 1 // X, Y, _ (XY tileset)
typedef struct
{
unsigned type :8;
@ -20,7 +34,6 @@ typedef struct
unsigned y :4;
} earth_t;
#define BRICK 2
typedef struct
{
unsigned type :8;
@ -31,14 +44,12 @@ typedef struct
unsigned number :4;
} brick_t;
#define BLOC 3
typedef struct
{
unsigned type :8;
unsigned data :24; // raw binary format
} bloc_t;
#define END_LEVEL 4
typedef struct
{
unsigned type :8;
@ -50,7 +61,6 @@ typedef struct
} end_level_t;
#define TUYAU 5 // X, Y, _ (XY tileset)
typedef struct
{
unsigned type :8;
@ -59,7 +69,15 @@ typedef struct
unsigned y :4;
} tuyau_t;
#define GIFT 6 // s, t, n (state[hit time], type[vide=0, piece=1, ...], qté)
typedef struct
{
unsigned type :8;
unsigned empty :16;
unsigned x :4;
unsigned y :4;
} arbre_t;
typedef struct
{
unsigned type :8;
@ -70,7 +88,6 @@ typedef struct
unsigned number :4;
} gift_t;
#define COIN 7 // s, _, _ (state)
typedef struct
{
unsigned type :8;
@ -78,10 +95,6 @@ typedef struct
unsigned taken :4;
} coin_t;
#define NUAGE 8 // X, Y, _ (XY tileset)
#define BUISSON 9 // X, Y, _ (XY tileset)
#define COLLINE 10 // X, Y, _ (XY tileset)
#define CASTLE 11
typedef struct
{
unsigned type :8;
@ -90,38 +103,31 @@ typedef struct
unsigned y :4;
} deco_t;
// Generic container
// Generic container 32 bits
typedef struct
{
unsigned type :8;
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 * 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
{
@ -129,7 +135,7 @@ typedef struct
int h;
int start_x;
int start_y;
cell_t data[];
cell_t* data;
}map_t;
extern map_t * map_current;

BIN
levelconverter/1-3.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
levelconverter/1_1.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
levelconverter/1_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
levelconverter/1_3.png~ Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

BIN
levelconverter/1_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

View File

@ -13,17 +13,17 @@ 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)
koopa_vert = (25, 127, 0)
koopa_rouge = (127, 0, 0)
mario_start = (108, 81, 47)
nuage = (127, 127, 127)
arbre_tronc = (74,35,18)
arbre_feuilles = (0,86,0)
plante = (102,0,127)
def color_compare(color1, color2):
if color1[0] == color2[0] and color1[1] == color2[1] and color1[2] == color2[2]:
@ -54,19 +54,19 @@ pixels = img.load()
for x in range(0,img.size[0]):
for i in range(0, img.size[1]):
y=img.size[1]-i-1
if color_compare(pixels[x,y],empty):
code += write_char(0)
elif color_compare(pixels[x,y], pierre):
code += write_char(1)
elif color_compare(pixels[x,y], piece):
code += write_char(2)
elif color_compare(pixels[x,y], brique):
code += write_char(3)
elif color_compare(pixels[x,y],brique_piece):
code += write_char(4)
@ -75,14 +75,14 @@ for x in range(0,img.size[0]):
elif color_compare(pixels[x,y],boite_champi):
code += write_char(6)
elif color_compare(pixels[x,y],beton):
code += write_char(7)
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):
@ -103,8 +103,18 @@ for x in range(0,img.size[0]):
elif color_compare(pixels[x,y], nuage):
code += write_char(15)
elif color_compare(pixels[x,y], arbre_tronc):
code += write_char(16)
elif color_compare(pixels[x,y], arbre_feuilles):
code += write_char(17)
elif color_compare(pixels[x,y], plante):
code += write_char(18)
else:
code += write_char(0)
print("Warning: unknown type at", x, y, "with pixel color: ", pixels[x,y])
f = open("../assets-fx/bin/lvl_"+filename, 'wb')

View File

@ -82,4 +82,4 @@ LDFLAGS_CG += -Wl,-Map=build-cg/map
# font name "hexa.png", you might write:
#
# FONT.hexa.png = charset:print grid:size:3x5 grid.padding:1
FONT.mario.png = charset:print grid.size:5x5 grid.padding:1 proportional:true
FONT.mario.png = charset:print grid.size:5x5 grid.padding:1 proportional:true

View File

@ -14,17 +14,20 @@ int min(const int x, const int y)
int sgn(const int x)
{
if (x>0)
return 1;
else if (x<0)
return -1;
else
return 0;
if (x>0) return 1;
else if (x<0) return -1;
else return 0;
}
static int ram_used=0;
int abs(const int x)
{
if (x>0) return x;
else return -x;
}
void* malloc_prof(int size)
static int ram_used=0;
void* mallocProf(int const size)
{
void* p=malloc(size);
if (p)
@ -32,19 +35,16 @@ void* malloc_prof(int size)
ll_sendp(LEVEL_INFO, "\n[std] malloc %d OK", size);
ram_used++;
ll_sendp(LEVEL_INFO, "\n[std] number of zones %d", ram_used);
return p;
}
if (p)
{
ll_sendp(LEVEL_CRITICAL, "\n[std] malloc %d FAILED", size);
return p;
}
else ll_sendp(LEVEL_CRITICAL, "\n[std] malloc %d FAILED", size);
return p;
}
void free_prof(void * p)
void freeProf(void * p)
{
free(p);
ll_sendp(LEVEL_INFO, "\n[std] free called");
ram_used--;
ll_sendp(LEVEL_INFO, "\n[std] number of zones %d", ram_used);
}
}

View File

@ -1,101 +1,98 @@
#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 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)
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;
}
void bonus_move() //+collision
{
if (bonus.type==BONUS_NONE)
return;
#include <score.h> // bonus en cas de prise
if (bonus.type==BONUS_STAR)
void bonusMove() //+collision
{
if (bonus.type == BONUS_NONE) return;
// animation de l'objet
boxMove(&bonus.b);
switch (bonus.type)
{
box_jump(&bonus.b,4);
}
box_move(&bonus.b);
if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR)
{
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)
bonus_set(BONUS_NONE,0,0);
bonusSet(BONUS_NONE,0,0);
}
bool x_collide= (mario.p.x<=bonus.b.x && bonus.b.x<mario.p.x+mario.p.w) || (mario.p.x<=bonus.b.x+bonus.b.w-1 && bonus.b.x+bonus.b.w<mario.p.x+mario.p.w);
bool y_collide= (mario.p.y<=bonus.b.y && bonus.b.y<mario.p.y+mario.p.h) || (mario.p.y<=bonus.b.y+bonus.b.h-1 && bonus.b.y+bonus.b.h<mario.p.y+mario.p.h);
if (x_collide&&y_collide)
if (bonus.type!=BONUS_NONE && boxContact(&mario.p, &bonus.b))
{
if (bonus.type==BONUS_CHAMPI)
switch (bonus.type)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
mario_bigger();
}
if (bonus.type==BONUS_FLEUR)
{
bonus_set(BONUS_NONE,0,0);
mario_has_bullets=1;
score_add(1000);
}
if (bonus.type==BONUS_1UP)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
lifes_add();
}
if (bonus.type==BONUS_STAR)
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
mario_star_mode=1;
case BONUS_CHAMPI:
case BONUS_FLEUR:
if (mario.p.h==M_SMALL) marioBigger();
else mario.bullets=1;
break;
case BONUS_1UP:
lifesAdd(1);
break;
case BONUS_STAR:
bonusSet(BONUS_NONE,0,0);
mario.starMode=1;
}
scoreAdd(1000);
bonusSet(BONUS_NONE,0,0);
}
}
void bonus_draw()
#include <camera.h>
#include <tile.h>
void bonusDraw()
{
//bonus_move();
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);
if (bonus.type==BONUS_FLEUR)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &fleur, 0,0);
if (bonus.type==BONUS_1UP)
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &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);
}
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);
}

128
src/box.c
View File

@ -7,17 +7,16 @@
int check_collision(box_t *b)
{
for (int i=0; i<ennemis_global_size; i++)
{
box_t* t=&ennemis_global[i].b;
if (t!=b)
{
int x_collide= (t->x<=b->x && b->x<t->x+t->w) || (t->x<=b->x+b->w-1 && b->x+b->w<t->x+t->w);
int y_collide= (t->y<=b->y && b->y<t->y+t->h) || (t->y<=b->y+b->h-1 && b->y+b->h<t->y+t->h);
if (x_collide&&y_collide)
return 1;
}
}
for (int i=0; i<ennemiesNumber(); i++) if (boxContact(&ennemis_global[i].b,b)) return 1;
return 0;
}
bool boxContact(box_t const * b1, box_t const * b2)
{
if (b1==b2) return 0;
int x_collide= (b2->x >= b1->x && b2->x < b1->x+b1->w) || (b1->x >= b2->x && b1->x < b2->x + b2->w);
int y_collide= (b2->y >= b1->y && b2->y < b1->y+b1->h) || (b1->y >= b2->y && b1->y < b2->y + b2->h);
if (x_collide&&y_collide) return 1;
return 0;
}
@ -27,26 +26,24 @@ static void move_x(box_t * b)
{
int sgn_vx=sgn(b->vx);
int t_vx=((sgn_vx*b->vx+time_id%2)/2)*sgn_vx;
int t_vx=((sgn_vx*b->vx+time_id%2)/2)*sgn_vx; // si n impair, alterne entre n+1 n-1
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)
coef=2;
if (frame_id%coef)
return;
int coef=1;// move each frame
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER) coef=2; //slow down in water
if (time_id%coef) return; // move 1 frame of 2 when in water ~to be improved
if (sgn_vx)
{
for (int i=sgn_vx; i<=sgn_vx*t_vx; i++)
for (int i=1; i<=sgn_vx*t_vx; i++)
{
for (int j=0; j<b->h; j++)
{
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;
@ -66,12 +63,12 @@ static void move_y(box_t * b)
{
b->last_vy=b->vy;
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)
coef=2;// 0.5
if (frame_id%coef)
return;
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;// 0.5
if (time_id%coef)
return;
if (sgn_vy)
{
@ -81,27 +78,48 @@ 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)
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)
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)
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)
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)
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)
b->x--;
{ // contournement du coin si seul le coin touche
box_t temp_hitbox=*b;
int sgn_vx=0;
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)
sgn_vx++;
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)
sgn_vx++;
if (worldGetCellCategory(b->x, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
sgn_vx++;
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)
sgn_vx--;
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)
sgn_vx--;
int fail=0;
for (int i=0; i<abs(sgn_vx); i++)
{
for (int j=0; j<b->h; j++) // test de validité
{
int typetemp;
if (sgn_vx>0) typetemp=worldGetCellCategory(temp_hitbox.x+temp_hitbox.w-1+i*sgn_vx,temp_hitbox.y+j);
else typetemp=worldGetCellCategory(temp_hitbox.x+i*sgn_vx,temp_hitbox.y+j);
if (typetemp==CTG_SOIL) fail=1;
}
temp_hitbox.x+=sgn(sgn_vx);
}
if (!fail) *b=temp_hitbox;
}
if (old==b->x)
{
b->y+=(i-1)*sgn_vy;
@ -121,35 +139,33 @@ static void move_y(box_t * b)
}
b->y+=b->vy;
}
//if (b->vy>=-6)
//if (b->vy>=-6)
b->vy-=b->gravity;
}
void box_move(box_t * b)
void boxMove(box_t * b)
{
//velx
//velx
move_x(b);
move_y(b);
}
void box_jump(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=world_get_ctg(b->x+j ,b->y+sgn_vy);
if (typetemp==CTG_SOIL)
sol++;
if (typetemp==CTG_WATER)
eau++;
}
if (sol)
b->vy=height;
else if (eau)
b->vy+=height/2;
return;
}
}
}
}

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++)
{
@ -24,56 +24,42 @@ void bullet_throw()
bullets[i].type=1;
bullets[i].b.x=mario.p.x;
bullets[i].b.y=mario.p.y+8;
if (last_vx_sign==0)
bullets[i].b.vx=-6;
else
bullets[i].b.vx=6;
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;
}
}
}
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);
}
for (int i=0; i<2; i++) if (bullets[i].type==1) 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++)
for (int i=0; i<2; i++) if (bullets[i].type) // bullet active
{
if (bullets[i].type==1)
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
if (bullets[i].b.y<0) bullets[i].type=0; // delete a bullet if it is out of the map
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+127) bullets[i].type=0; // delete a bullet if it is out of the screen
// contact with ennemies
for (int a=0; a<ennemiesNumber(); a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
{
box_jump(&bullets[i].b,4);
box_move(&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)
bullets[i].type=0;
for (int a=0; a<ennemis_global_size; a++)
{
ennemi_t* t=&ennemis_global[a];
if (t->discovered && t->type!=NONE)
{
bool x_collide= (bullets[i].b.x<=t->b.x && t->b.x<bullets[i].b.x+bullets[i].b.w) || (bullets[i].b.x<=t->b.x+t->b.w-1 && t->b.x+t->b.w<bullets[i].b.x+bullets[i].b.w);
bool y_collide= (bullets[i].b.y<=t->b.y && t->b.y<bullets[i].b.y+bullets[i].b.h) || (bullets[i].b.y<=t->b.y+t->b.h-1 && t->b.y+t->b.h<bullets[i].b.y+bullets[i].b.h);
if (x_collide&& y_collide)
{
t->life=DEAD;
bullets[i].type=0;
score_add(KILL_ENNEMI);
break;
}
}
}
ennemis_global[a].life=DEAD;
bullets[i].type=0;
scoreAdd(KILL_ENNEMI);
break;
}
}
}
}

View File

@ -1,26 +1,68 @@
#include <camera.h>
#include <mario.h>
#include <world.h>
#include <base.h>
#include <keyboard.h>
static int y=0;
static int last_vy=0;
static int immobile=0;
static int distance=0;
static int delta_y=0; // the player can choose the y positionning of the camera with arrows
int camera_x() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int camera_y() {return max(y-24,0);}
int cameraX() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
int cameraY() {return max(max(y-32,0)-delta_y,0);}
void camera_move(int delay)
void cameraMove() // only vertical movement
{
if (delay<=0)
delay=3; // on ajoute 1/3 de la distance camera mario
y+=(mario.p.y-y)/delay;
static int camera_vy=0;
if (MKB_getKeyState(MK_UP) && (abs(delta_y)<20 || delta_y>=0)) { delta_y-=4;}
if (MKB_getKeyState(MK_DOWN) && (abs(delta_y)<20 || delta_y<=0)) { delta_y+=4;}
if (!MKB_getKeyState(MK_DOWN) && !MKB_getKeyState(MK_UP)) delta_y-=4*sgn(delta_y);
if (mario.p.y==last_vy) immobile++;
else
{
last_vy=mario.p.y;
immobile=0;
}
if (mario.p.y-cameraY()-mario.p.h<16 || mario.p.y-cameraY()>54)
{
y+=4*sgn(mario.p.y-y);
}
if (immobile>=2)
{
//y+=(mario.p.y-y)/3;
if (camera_vy==0) distance=2*(mario.p.y-y)*sgn(mario.p.y-y);
//décéleration après avoir parvouru la moitié de la distance, sinon acceleration
if (camera_vy*(camera_vy+1)>distance) camera_vy--;
else camera_vy++;
//y++;
if (camera_vy<0) camera_vy=0;
if (((y+camera_vy*sgn(mario.p.y-y)/2)-(mario.p.y))*sgn(mario.p.y-y)>0)
{
y=mario.p.y;
camera_vy=0;
}
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

@ -1,35 +1,15 @@
#include "config.h"
#include <config.h>
#include <keyboard.h>
#include <liblog.h>
#include <gint/display.h>
#include <keyboard.h>
#include <gint/keyboard.h>
extern image_t img_tickbox;
char loglevels[6][14]={"--all","--information","--warning","--critical","--fatal","--mute"};
void configmenu()
{
mkb_clear();
font_t const * const f=dfont(0);
while (1)
{
dclear(C_WHITE);
drect(0,0,128,7,C_BLACK);
dtext(0,0,"Configuration Menu : ", C_WHITE, C_NONE);
dtext(0,9," > LOG", C_BLACK, C_NONE);
dtext(0,17," ", C_BLACK, C_NONE);
dtext(40,9,&loglevels[ll_get_level()][0],C_BLACK,C_NONE);
dupdate();
ll_pause();
int key=mkb_getkey();
if (key==KEY_EXIT)
break;
}
mkb_clear();
dfont(f);
}
MKB_clear();
ll_pause();
MKB_clear();
}

View File

@ -4,130 +4,180 @@
#include "tile.h"
#include "world.h"
#include "score.h"
#include <base.h>
#include <camera.h>
#include <level.h>
#include <gint/std/string.h>
#include <constants.h>
#include <stdbool.h>
static int sgn(int x)
/** properties **/
const int ennemi_widths [NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8 , 8, 8};
const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8, 8, 8};
/** ram storage **/
ennemi_t * ennemis_global=0;
static int ennemis_global_size=0;
int ennemiesNumber() { return ennemis_global_size; }
void ennemiesInit(ennemi_t * table, int s)
{
if (x==0)
return 0;
else if (x>0)
return 1;
return -1;
if (ennemis_global) freeProf(ennemis_global);
ennemis_global_size = ennemis_global = 0; // reset
if (s==0) return;
int const size = sizeof(ennemi_t) * s;
if ((ennemis_global = mallocProf(size)) == 0) mallocError();
ennemis_global_size = s;
memcpy(ennemis_global, table, size);
}
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 const * e)
{
if (e->life==0)
if (e->type == NONE) return;
if (e->b.x <= cameraX(0) - e->b.w || e->b.x >= cameraX(0) + 127) return; // do not draw if out of the screen
{// draw
int tx=0, ty=0, dsx=0, dsy=0;
tileset_t t={0, ennemi_widths[e->type], ennemi_heights[e->type], 1};
switch (e->type)
{
case GOOMBA_ID:
{
extern image_t img_goomba;
t.sheet=&img_goomba;
tx = e->life*(1+(time_id/10)%2);
}
break;
case KOOPA_V_ID:
{
extern image_t img_koopa_verte;
t.sheet=&img_koopa_verte;
t.height=ennemi_heights[KOOPA_V_ID]+ennemi_heights[KOOPA_V_ID]/2;
tx = (1+e->p1)+(time_id/8)%2;
}
break;
case KOOPA_R_ID:
{
extern image_t img_koopa_rouge;
t.sheet=&img_koopa_rouge;
t.height=ennemi_heights[KOOPA_R_ID]+ennemi_heights[KOOPA_R_ID]/2;
tx = (1+e->p1)+(time_id/8)%2;
}
break;
case CARAPACE_VERTE:
{
extern image_t img_carapace_verte;
t.sheet=&img_carapace_verte;
t.height=ennemi_heights[CARAPACE_VERTE]+ennemi_heights[CARAPACE_VERTE]/8;
}
break;
case CARAPACE_ROUGE:
{
extern image_t img_carapace_rouge;
t.sheet=&img_carapace_rouge;
t.height=ennemi_heights[CARAPACE_ROUGE]+ennemi_heights[CARAPACE_ROUGE]/8;
}
break;
case PLANTE_ID:
{
extern image_t img_plante;
t.sheet=&img_plante;
t.width*=2;
dsx=-4;
}
}
tileDraw(e->b.x-cameraX(0)+dsx, e->b.y-cameraY(mario.p.y)+dsy, &t, tx, ty);
}
}
void plante_tour(ennemi_t *e)
{
if (e->type==PLANTE_ID)
{
e->p1++;
e->p1%=PLANTE_NLAPS;
// En attente
if (0<=e->p1 && e->p1<35) if (abs(mario.p.x-e->b.x)<15) e->p1=0;
if (35<=e->p1 && e->p1<58)
{
if ((e->p1+1)%3==0) e->b.y++;
}
if (58 <= e->p1 && e->p1 < 75){} // plante en attente en haut
if (75 <= e->p1 && e->p1 < 98)
{
if (e->p1%3==0) e->b.y--;
}
}
}
bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p)); }
void hurtMario()
{
if (mario.p.h==M_SMALL && mario.immunity==0)
{mario.dead=1;finish_level=0;}
else marioSmaller();
}
void ennemiMove(ennemi_t *e)
{
if (!(e->b.x<=cameraX(0)-e->b.w || e->b.x>=cameraX(0)+127)) e->discovered=1; // for security, tag as discover all drawed ennemies
if (e->life==DEAD && e->type!=NONE) // dying animation
{
if (e->p1==0)
{
e->b.vx*=-1;
e->b.vx=2*sgn(e->b.vx);
e->b.vy=5;
}
e->p1++;
e->b.vy--;
e->b.y+=e->b.vy;
e->b.x+=e->b.vx;
if (e->p1==30)
e->type=NONE;
}
if (e->type==NONE)
return;
if (e->b.x<=camera_x(0)-e->b.w || e->b.x>=camera_x(0)+127)
return;
else
e->discovered=1;
if (e->type==GOOMBA_ID)
{
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);
if (e->life==0)
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(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);
}
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);
}
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);
}
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);
if (e->p1>=30) e->type=NONE; // died 1.5 sec before
}
}
bool ennemi_check_collision(ennemi_t *e)
{ 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);
bool y_collide= (mario.p.y<=e->b.y && e->b.y<=mario.p.y+mario.p.h-1) || (mario.p.y<=e->b.y+e->b.h-1 && e->b.y+e->b.h-1<=mario.p.y+mario.p.h-1);
return (x_collide&&y_collide);
}
void hurt_mario()
{ if (mario.size==M_SMALL && mario_immunity==0)
{mario_dead=1;finish_level=0;}
else
mario_smaller();
}
void move_ennemi(ennemi_t *e)
{
if (e->b.x<camera_x()+128+30 && e->b.x>camera_x()-30)
e->discovered=1;
//if (e->b.x+e->b.w<=world_get_real_x0())
if (e->b.x<cameraX()+128+30 && e->b.x>cameraX()-30)
e->discovered=1;
//if (e->b.x+e->b.w<=worldGetCell_real_x0())
// e->type=NONE;
if (e->discovered==0)
return;
return;
if (e->life==DEAD)
return;
return;
// e->type=NONE;
if (e->type==NONE)
return;
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(KILL_ENNEMI);
return;
}
for (int i=0; i<ennemis_global_size; i++)
for (int i=0; i<ennemis_global_size; i++) // physique des carapaces (collisions avec les autres)
{
ennemi_t* t=&ennemis_global[i];
if (t!=e && t->discovered && t->type!=NONE)
if (t->type!=NONE)
{
bool x_collide= (t->b.x<=e->b.x+e->b.vx && e->b.x+e->b.vx<t->b.x+t->b.w) || (t->b.x<=e->b.x+e->b.w-1+e->b.vx && e->b.x+e->b.w+e->b.vx<t->b.x+t->b.w);
bool y_collide= (t->b.y<=e->b.y+e->b.vy && e->b.y+e->b.vy<t->b.y+t->b.h) || (t->b.y<=e->b.y+e->b.h-1+e->b.vy && e->b.y+e->b.h+e->b.vy<t->b.y+t->b.h);
if (x_collide&&y_collide && t->life!=DEAD)
e->b.x+=sgn(e->b.vx)*(abs(e->b.vx)+(time_id%2))/2;
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)
{
if (e->type!=CARAPACE_VERTE && e->type!=CARAPACE_ROUGE)
{
@ -145,155 +195,58 @@ void move_ennemi(ennemi_t *e)
{
t->life=DEAD;
t->p1=0;
score_add(200);
scoreAdd(KILL_ENNEMI);
}
}
}
}
}
int previous_case=-5;
for (int j=0; j<e->b.h; j++)
{
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);
e->life=e->p1=DEAD;
scoreAdd(KILL_ENNEMI);
break;
}
}
}
if (e->b.y<0) e->type=NONE;
const bool mario_fatal_hit = (mario.p.last_vy<=-2 || mario.p.vy<=-2);
if (e->type==GOOMBA_ID)
switch (e->type) // move
{
box_move(&e->b);
if (e->b.vx==0)
{
if (e->p1==0)
{
e->b.vx=-1;
e->p1=-1;
}
else
{
e->p1*=-1;
e->b.vx=e->p1;
}
}
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
{
if (mario_fatal_hit)
{
e->life=DEAD;
e->p1=0;
score_add(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[GOOMBA_ID]+1;
}
else
hurt_mario();
}
return;
}
if (e->type==KOOPA_V_ID)
{
box_move(&e->b);
if (e->b.vx==0)
{
if (e->p1==0)
{
e->b.vx=-1;
e->p1=-1;
}
else
{
e->p1*=-1;
e->b.vx=e->p1;
}
}
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
{
if (mario_fatal_hit)
{
e->type=CARAPACE_VERTE;
e->b.h=ennemi_heights[CARAPACE_VERTE];
e->p1=2;
e->b.vx=0;
score_add(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
}
else
hurt_mario();
}
return;
}
if (e->type==KOOPA_R_ID)
{
box_move(&e->b);
if (e->b.vx==0)
{
if (e->p1==0)
{
e->b.vx=-1;
e->p1=-1;
}
else
{
e->p1*=-1;
e->b.vx=e->p1;
}
}
else
{ // demi tour automatique
case KOOPA_R_ID:
boxMove(&e->b);
if (e->b.vx)
{ // demi tour si au dessus du vide
int s=-1;
if (e->b.vx>0)
s=e->b.w;
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))
{
e->p1*=-1;
e->b.vx=e->p1;
}
if (worldGetCellCategory(e->b.x+s, e->b.y-1)==CTG_EMPTY && sgn(e->b.vx)==sgn(s)) e->b.vx=(e->p1*=-1);
}
if (e->b.y<0)
e->type=NONE;
if (e_hit_mario)
// fall through
case GOOMBA_ID:
case KOOPA_V_ID:
if (e->type!=KOOPA_R_ID) boxMove(&e->b);
if (e->b.vx==0) // demi tour si mur
{
if (mario_fatal_hit)
{
e->type=CARAPACE_ROUGE;
e->b.h=ennemi_heights[CARAPACE_ROUGE];
e->p1=2;
e->b.vx=0;
score_add(200);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_ROUGE]+1;
}
else
hurt_mario();
if (e->p1==0) e->b.vx=e->p1=-1;
else e->b.vx=(e->p1*=-1);
}
return;
}
break;
if (e->type==CARAPACE_VERTE || e->type==CARAPACE_ROUGE)
{
case CARAPACE_VERTE:
case CARAPACE_ROUGE:
boxMove(&e->b);
if (e->b.vx==0)
{
if (e->p1<2)
@ -302,93 +255,105 @@ void move_ennemi(ennemi_t *e)
e->b.vx=6*e->p1;
}
}
if (e->b.y<0)
e->type=NONE;
if (e->p1>=2)
{
e->p1++;
if (e->p1==80)
{
if (e->type==CARAPACE_VERTE)
e->type=KOOPA_V_ID;
else
e->type=KOOPA_R_ID;
if ((e->p1++)==80)
{ // transformation carapace->koopa
e->type--;
e->b.h=ennemi_heights[e->type];
e->p1=0;
e->b.vx=0;
e->p1=e->b.vx=0;
}
}
break;
if (e_hit_mario)
case PLANTE_ID:
plante_tour(e);
}
if (e_hitMario && mario_fatal_hit) switch (e->type) // mario attacks
{
case GOOMBA_ID:
e->life=DEAD;
e->p1=0;
scoreAdd(KILL_ENNEMI);
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[e->type]+1;
break;
case KOOPA_V_ID:
case KOOPA_R_ID:
e->type++;
e->b.h=ennemi_heights[e->type];
e->p1=2;
e->b.vx=0;
scoreAdd(KILL_ENNEMI);
mario.p.vy=6;
mario.p.y=e->b.y+ennemi_heights[e->type]+1;
break;
case CARAPACE_VERTE:
case CARAPACE_ROUGE:
if (e->p1==0 || e->p1>=2)
{
if (e->p1==0 || e->p1>=2)
if (mario.p.x>=e->b.x) e->p1=-1;
if (mario.p.x<=e->b.x) e->p1=1;
e->b.vx=6*e->p1;
mario.p.vy=6;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE];
}
else
{
e->p1=e->b.vx=mario.p.vx=0;
mario.p.vy=6;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
}
break;
case PLANTE_ID:
hurtMario();
break;
}
else if (e_hitMario) switch (e->type) // hurt mario
{
case GOOMBA_ID:
case KOOPA_V_ID:
case KOOPA_R_ID:
hurtMario();
break;
case CARAPACE_VERTE:
case CARAPACE_ROUGE:
if (e->p1==0 || e->p1>=2)
{
if (mario.p.x>=e->b.x) e->p1=-1;
else e->p1=1;
e->b.vx=6*e->p1;
if (mario_fatal_hit)
{
if (mario.p.x>=e->b.x)
e->p1=-1;
if (mario.p.x<=e->b.x)
e->p1=1;
e->b.vx=6*e->p1;
if (mario_fatal_hit)
{
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE];
}
else
{
if (mario.p.x>=e->b.x)
mario.p.x=e->b.x+e->b.w;
if (mario.p.x<=e->b.x)
mario.p.x=e->b.x-mario.p.w;
}
mario.p.vy=6;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE];
}
else
{
if (mario_fatal_hit)
{
e->p1=0;
e->b.vx=0;
mario.p.vy=4;
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
}
else
hurt_mario();
{ // mario bounce
if (mario.p.x>=e->b.x) mario.p.x=e->b.x+e->b.w;
else mario.p.x=e->b.x-mario.p.w;
mario.p.vx=0;
}
}
box_move(&e->b);
return;
}
else hurtMario();
break;
}
ennemi_t * ennemis_global=0;
int ennemis_global_size=0;
void display_ennemi_table()
{
for (int i=0; i<ennemis_global_size; i++)
{
display_ennemi(&ennemis_global[i]);
case PLANTE_ID:
hurtMario();
break;
}
}
void init_ennemi(ennemi_t * table, int s)
void ennemiesDisplay()
{
ennemis_global_size=0;
if (ennemis_global)
{
free_prof(ennemis_global);
ennemis_global=0;
}
if (0==s)
return;
int size=sizeof(ennemi_t)*s;
ennemis_global=malloc_prof(size);
if (ennemis_global==0)
malloc_error();
ennemis_global_size=s;
memcpy(ennemis_global, table, size);
}
for (int i=0; i<ennemis_global_size; i++) ennemiDisplay(&ennemis_global[i]);
}

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,40 +8,41 @@
#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];
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;
keys[i]=0;
clearevents();
}
int mkb_getkey()
int MKB_getkey()
{
mkb_clear();
MKB_clear();
/*
while (1)
{
key_event_t const e=pollevent();
if (e.key==KEY_ARROW)
ll_pause();
ll_pause();
if (e.type==KEYEV_DOWN) // Returns only whan a key is down
return e.key;
return e.key;
else
sleep(); // Processor friendly :)
sleep(); // Processor friendly :)
}
*/
return getkey_opt(GETKEY_REP_ARROWS,0).key;
}
static int menu_pause() // 1 exit, 0 continue
{
{
extern image_t img_menu_pause;
extern image_t img_select_arrow;
@ -52,14 +53,14 @@ static int menu_pause() // 1 exit, 0 continue
int x=64-img_menu_pause.width/2;
int y=32-img_menu_pause.height/2;
for (int i=0; i<6; i++)
keys[i]=0;
keys[i]=0;
while (1)
{
dimage(x,y,&img_menu_pause);
dimage(x+2, y+2+7*choice, &img_select_arrow);
dupdate();
switch (mkb_getkey())
switch (MKB_getkey())
{
case KEY_EXIT:
return 0;
@ -67,24 +68,22 @@ static int menu_pause() // 1 exit, 0 continue
case KEY_MENU:
return 1;
case KEY_OPTN:
choice=2;
// fall through
case KEY_EXE:
if (choice==2)
configmenu();
configmenu();
return choice & 1;
case KEY_UP:
if (choice>0)
choice--;
choice--;
break;
case KEY_DOWN:
if (choice<2)
choice++;
choice++;
break;
#ifdef KONAMI
#ifdef KONAMI
case KEY_F1:
for (int a=0; a<10; a++)
@ -94,16 +93,16 @@ static int menu_pause() // 1 exit, 0 continue
{
static int const konami[]={KEY_UP,KEY_UP,KEY_DOWN,KEY_DOWN,KEY_LEFT,KEY_RIGHT,KEY_LEFT,KEY_RIGHT,KEY_ALPHA,KEY_SHIFT};
if (e.key!=konami[a])
break;
break;
}
if (keydown(KEY_EXIT))
break;
break;
if (a==10) // Cheat code
{
mario_bigger();
mario_has_bullets=1;
for (int i=0; i<20; i++)
lifes_add();
marioBigger();
mario.bullets=1;
lifesAdd(20);
extern image_t img_dev;
dimage(0,0,&img_dev);
dupdate();
@ -111,45 +110,48 @@ static int menu_pause() // 1 exit, 0 continue
return 0;
}
else
e=pollevent();
e=pollevent();
}
#endif
#endif
}
}
}
void mkb_update()
void MKB_update()
{
key_event_t e;
e=pollevent();
int menu=0, log=0;
for (int i=0; i<6; i++)
if (keys[i]==2) keys[i]=1;
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;
k=MK_LEFT;
if(e.key==KEY_RIGHT)
k=MK_RIGHT;
k=MK_RIGHT;
if(e.key==KEY_SHIFT)
k=MK_JUMP;
k=MK_JUMP;
if(e.key==KEY_COS)
k=MK_JUMP;
if(e.key==KEY_UP)
k=MK_UP;
k=MK_UP;
if(e.key==KEY_DOWN)
k=MK_DOWN;
k=MK_DOWN;
if(e.key==KEY_ALPHA)
k=MK_RUN;
if(e.key==KEY_XOT)
k=MK_RUN;
if(e.key==KEY_OPTN)
k=MK_RUN;
if(keydown(KEY_EXIT))
menu=1; // Displays menu after updating the keyboard
menu=1; // Displays menu after updating the keyboard
if (e.key==KEY_ARROW)
log=1;
log=1;
if (k!=MK_NONE)
{
@ -168,14 +170,9 @@ void mkb_update()
{
int t=menu_pause();
if (t==1)
finish_level=-1; // Exits the level
finish_level=-1; // Exits the level
return;
}
if (log)
ll_pause();
ll_pause();
}

View File

@ -14,6 +14,7 @@
#include <gint/std/string.h>
#include <gint/std/stdio.h>
#include <liblog.h>
#include <base.h>
#define PACKED_EMPTY 0
#define PACKED_STONE 1
@ -31,44 +32,39 @@
#define PACKED_KOOPA_ROUGE 13
#define PACKED_MARIO_START 14
#define PACKED_NUAGE 15
#define PACKED_ARBRE_TRONC 16
#define PACKED_ARBRE_FEUILLES 17
#define PACKED_PLANTE 18
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
@ -81,16 +77,16 @@ 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
ennemi_t ennemis[20]={0};
ennemi_t ennemis[30]={0};
int nombre_ennemis=0;
@ -98,7 +94,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)
{
@ -110,16 +106,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};
@ -161,40 +157,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;
@ -206,15 +202,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
{
@ -223,15 +219,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
{
@ -247,20 +243,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;
}
@ -268,19 +264,39 @@ 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;
}
else if (contents==PACKED_ARBRE_TRONC)
{
cell_t t={ARBRE,0x11};
cell = t;
}
else if (contents==PACKED_ARBRE_FEUILLES)
{
int px=0;
if (packAccess(p,x+1,y)==PACKED_ARBRE_FEUILLES)
{
if (packAccess(p,x-1,y)==PACKED_ARBRE_FEUILLES)
px=1;
else
px=0;
}
else
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);
@ -303,6 +319,12 @@ static void unpack_level(packed_level_t * p)
ennemis[nombre_ennemis]=e;
nombre_ennemis++;
}
else if (contents==PACKED_PLANTE)
{
ennemi_t e=PLANTE(8*x+4,8*y-8);
ennemis[nombre_ennemis]=e;
nombre_ennemis++;
}
if (contents==PACKED_MARIO_START)
{
@ -312,39 +334,41 @@ 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);
// Don't free c, it will be automatically managed by the worldSet function
//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[]=
{
@ -353,18 +377,30 @@ 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;
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 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

@ -17,98 +17,92 @@
#include <camera.h>
#include <bonus.h>
static void levelchanger(int w)
int PlayLevel(int, int); // déclaration de la fonction codée plus bas
static void LevelChanger(int world)
{
int play_level(int w, int l);
extern image_t img_levelchanger;
int choice=0;
// x y, first button coordinates and size
const int xt = 19, yt = 7, wt = 6, ht = 6;
MKB_clear(); // clear keyboard
unsigned int choice=0;
while (1)
{
mkb_clear();
dimage(0,0,&img_levelchanger);
drect(xt+(2+wt)*choice, yt, xt+(wt+2)*choice+wt,yt+ht, C_INVERT);
extern image_t img_levelchanger;
dimage(0,0,&img_levelchanger); // Draw menu
drect(19+8*choice, 7, 25+8*choice, 13, C_INVERT); // Invert color of selected level
char str[8];
if (choice != 8)
{
{
sprintf(str, "%d", choice+1);
dtext(45,19, str, C_BLACK, C_WHITE);
}
else
{
dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
dtext(45,19, str, C_BLACK, C_WHITE); // Maybe later replace it by level names
}
else dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
if (get_best_time(w,choice))
if (saveGetTime(world,choice))
{
sprintf(str, "%d", get_best_time(w,choice));
sprintf(str, "%d", saveGetTime(world,choice));
int i=0;
while (str[i])
i++;
i++;
dtext(99-6*i, 53, str, C_BLACK, C_WHITE);
}
sprintf(str, "%d", get_highscore(w,choice));
int i=0;
while (str[i])
if (saveGetScore(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);
dtext(99-6*i, 45, str, C_BLACK, C_WHITE);
}
sprintf(str, "%d", get_highcoins(w,choice));
i=0;
while (str[i])
if (saveGetCoins(world,choice))
{
sprintf(str, "%d", saveGetCoins(world,choice));
int i=0;
while (str[i])
i++;
dtext(90-6*i, 37, str, C_BLACK, C_WHITE);
dtext(90-6*i, 37, str, C_BLACK, C_WHITE);
}
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=mkb_getkey();
if (key==KEY_LEFT && choice>0)
choice--;
if (key==KEY_RIGHT && choice<8)
choice++;
if (key==KEY_EXE || key==KEY_SHIFT)
switch (MKB_getkey())
{
case KEY_LEFT:
if (choice) /* >0 */ choice--;
break;
case KEY_RIGHT:
if (choice!=8) /* <8 */ choice++;
break;
case KEY_EXE:
// fall through
case KEY_SHIFT:
if (choice==8)
{
new_game();
mario_smaller();
mario_immunity=0;
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(w, i, lvl);
getLevelID(world, i, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes_get());
sprintf(lvl, "%d", lifesGet());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
int a=play_level(w, i);
if (a==0)
lifes_lose();
if (a==1)
i++;
if (a==-1)
break;
if (lifes_get()==0)
int a=PlayLevel(world, i);
if (a==0) lifesAdd(-1);
if (a==1) i++;
if (a==-1) break;
if (lifesGet()==0)
{
extern image_t img_game_over;
dimage(0,0,&img_game_over);
@ -118,64 +112,72 @@ static void levelchanger(int w)
break;
}
}
set_highscore(w, 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(w, choice, lvl);
getLevelID(world, choice, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes_get());
sprintf(lvl, "%d", lifesGet());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
while (1)
playagain:
gameNew();
switch (PlayLevel(world, choice))
{
new_game();
mario_smaller();
mario_immunity=0;
int s=play_level(w, choice);
if (s==1)
{
set_best_time(w, choice, get_time_spent());
}
set_highscore(w, choice, get_score());
set_highcoins(w, choice, get_coins());
if (s)
break;
case 1: // if level completed
saveSetTime(world, choice, getTimeSpent());
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
break; // go back to menu
case 0: // save score anyways
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
goto playagain;
break;
case -1:
saveSetScore(world, choice, scoreGet());
saveSetCoins(world, choice, coinsGet());
break; // do not play again
}
}
}
if (key==KEY_EXIT || key==KEY_MENU)
break;
}
case KEY_EXIT:
// fall through
case KEY_MENU:
return;
}
}
}
void launch_ui()
void launchUI() // Main Menu
{
extern image_t img_mainmenu;
const int xt=17,yt=9;
int choice_x=0, choice_y=0;
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 (get_progress_status())
switch (saveGetProgressStatus())
{
case 4:
dimage(xt, yt+24, &img_w5);
@ -193,114 +195,124 @@ void launch_ui()
dimage(xt, yt, &img_w1);
}
// invert color of selected world
drect(xt+24*choice_x,yt+24*choice_y, xt+24*choice_x+20,yt+24*choice_y+20, C_INVERT);
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=mkb_getkey();
if (key==KEY_UP && choice_y>0)
choice_y--;
if (key==KEY_LEFT && choice_x>0)
choice_x--;
if (key==KEY_DOWN && choice_y<1)
choice_y++;
if (key==KEY_RIGHT && choice_x<3)
choice_x++;
if (key==KEY_EXE || key==KEY_SHIFT)
switch (MKB_getkey())
{
// Determine mode
if (choice_x==3 && choice_y==1)
break;
if (choice_x==2 && choice_y==1)
{
configmenu();
}
if (choice_y*choice_x==0)
{
int world_chosen=0;
if (choice_y==1)
world_chosen=4;
else
world_chosen=choice_x;
if (world_chosen<=get_progress_status())
levelchanger(world_chosen);
}
}
if (key==KEY_EXIT || key==KEY_MENU)
case KEY_UP:
if (choice_y) // >0
choice_y--;
break;
case KEY_LEFT:
if (choice_x) // >0
choice_x--;
break;
case (KEY_DOWN):
if (!choice_y) // ==0
choice_y++;
break;
case (KEY_RIGHT):
if (choice_x!=3) // <3
choice_x++;
break;
case KEY_EXE:
// fall through
case KEY_SHIFT:
switch (4*choice_y+choice_x)
{
case 5: // No idea yet !
break;
case 6:
configmenu();
break;
case 7:
return;
default:
if (4*choice_y+choice_x<=saveGetProgressStatus())
LevelChanger(4*choice_y+choice_x);
}
break;
case KEY_EXIT:
// fall through
case KEY_MENU:
return;
}
}
}
int frame_id;
int play_level(int w, int l)
int PlayLevel(int w, int l)
{
init_refresh();
time_id=0;
initRefreshTimer();
//int finish_status=0; // FAil
finish_level=0; mario_dead=0;
set_level(w, l);
finish_level=0; mario.dead=0;
setLevel(w, l);
if (map_current==0)
{
timer_stop(0);
return -1;
}
camera_adjust();
bonus_set(0, 0, 0);
cameraAdjust();
bonusSet(0, 0, 0);
mario.last_vx_sgn=1;
while(global_quit==0)
{
wait_next_frame();
frame_id++;
//mario_move();
waitNextFrame();
world_move();
//marioMove();
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)
if (mario.dead)
{
mario_immunity=0;
mario.immunity=0;
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();
// TODO ajouter temps au score etc
if (finish_level==1)
sleep_ms(3,3000);
quitRefreshTimer();
// TODO ajouter temps au score etc
if (finish_level==1) sleep_ms(3,3000); // win
return finish_level;
}
}
return 0;
}
}

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);
launch_ui();
launchUI();
return 1;
}

View File

@ -1,4 +1,5 @@
#include "mario.h"
#include <mario.h>
#include "tile.h"
#include "world.h"
#include <gint/display.h>
@ -8,285 +9,198 @@
#include "bonus.h"
#include <bullets.h>
#include <camera.h>
static int sgn(int x)
{
if (x>0)
return 1;
else if (x<0)
return -1;
else
return 0;
}
int id_frame=0;
#include <base.h>
pnj mario=
{
{26,17,8,8,0,0,0,1},
M_SMALL,
M_RIGHT1, M_WALK,
{26,17,6,8,0,0,0,1},
0
};
int mario_x_max=0;
int mario_has_bullets=0;
static int mario_time_accel=0;
int mario_dead=0;
//static int mario_coins=0;
int last_vx_sign=1;
//static int last_bonus=0;
static int mario_accel=0;
int mario_immunity=0;
int mario_star_mode=0;
void mario_bigger()
void marioBigger()
{
mario.p.h=16;
mario.size=M_BIG;
mario_has_bullets=0;
mario.p.h=M_BIG;
mario.bullets=0;
}
void mario_smaller()
void marioSmaller()
{
mario.p.h=8;
mario.size=M_SMALL;
mario_has_bullets=0;
if (mario_immunity==0)
mario_immunity=1;
//mario.p.vy=5;
mario.p.h=M_SMALL;
mario.bullets=0;
if (mario.immunity==0) mario.immunity=1;
}
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)
{
if (mario.size==M_SMALL)
const int mx=mario.p.x-cameraX(mario.p.x)-1;
const int my=mario.p.y-cameraY(mario.p.y);
if (mario.p.h==M_SMALL)
{
if (mario.p.vx*sgn(mario.p.vx)>=3)
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
else if (mario.p.vx*sgn(mario.p.vx)>=1)
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
else
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &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 (mario.p.vx*sgn(mario.p.vx)>=3)
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
else if (mario.p.vx*sgn(mario.p.vx)>=1)
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
else
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &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);
}
}
}
int test_sol_le_plus_proche(int x, int y)
{
int distance=0;
int t=0;
while (t==0)
{
int type_sol = world_get_ctg(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);
if (type_sol==CTG_SOIL)
t=1;
if (type_sol==CTG_DEATH)
return distance+1;
y--;
distance++;
}
return distance;
#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_input = 0;
}
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;
{ // Mario star mode & immunity counters
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++;
}
id_frame++;
if (mario_has_bullets==1 && mkb_getstate(MK_RUN)==2)
{
bullet_throw();
}
if (mario.bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
if (mkb_getstate(MK_JUMP)==2) //|| keys[MK_JUMP2]==2)
{
if (mario.p.vx*sgn(mario.p.vx)>=6)
box_jump(&mario.p, 9);
else
box_jump(&mario.p, 8);
}
else if (mario.p.vy>=2 && mkb_getstate(MK_JUMP)==0)
mario.p.vy--;
{ // Jump (with coyote time & jump buffering)
bool jump=0; // will he jump ?
int vx=sgn(mkb_getstate(MK_RIGHT) - mkb_getstate(MK_LEFT));
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*/);
if (vx)
{
if (vx==sgn(mario.p.vx) || vx==0)
mario_time_accel++;
else if (vx==-sgn(mario.p.vx))
mario_time_accel=0;
mario_time_accel%=2;
if (mario_time_accel==0)
// coyote time
for (int i = 0; i < mario.p.w; i++) if (worldGetCellCategory(mario.p.x + i, mario.p.y - 1)==CTG_SOIL)
{
if (mkb_getstate(MK_RUN) && (c1==CTG_SOIL || c2==CTG_SOIL))
{
if(mario.p.vx*sgn(mario.p.vx)<=8)
mario.p.vx+=vx;
}
else
{
if (mario.p.vx*vx<4)
mario.p.vx+=vx;
if (jump_input>0) jump=1;
else jump_input=-COYOTE_INTERVAL;
break;
}
}
if (mkb_getstate(MK_RUN)==0)
// jump buffering
if (MKB_getKeyState(MK_JUMP)==2)
{
if (jump_input<0) jump = 1; // break the rules
else jump_input = 1;
}
if (jump_input) jump_input++;
if (jump_input==COYOTE_INTERVAL+1) jump_input=0;
if (jump)
{
if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9, 0);
else boxJump(&mario.p, 8, 0);
}
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
}
{ // Lateral move
int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows)
// cells next to mario
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*/);
static int mario_timeAccel=0;
mario_timeAccel=1-mario_timeAccel; // increments & %2
if (vx!=sgn(mario.p.vx)) mario_timeAccel=1; // reverse direction means deceleration which is 2 times faster
if (mario_timeAccel)
{
if (vx)
{
if (mario.p.vx*vx>4)
mario.p.vx-=vx;
// sprinte et est sur le sol
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_getKeyState(MK_RUN)==0 && abs(mario.p.vx)>4) mario.p.vx-=sgn(mario.p.vx);
}
else mario.p.vx-=sgn(mario.p.vx);
}
{ // last vx sign determination
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
{
mario.p.vx=0;
mario.p.x=cameraX(mario.p.x);
}
}
else
{
if (mario.p.vx)
{
if (mario_accel)
{
mario_time_accel++;
mario_time_accel%=4;
if (mario_time_accel==0)
{
mario.p.vx-=sgn(mario.p.vx);
mario_accel=-sgn(mario.p.vx);
}
}
else
{
mario.p.vx-=sgn(mario.p.vx);
mario_accel=-sgn(mario.p.vx);
}
boxMove(&mario.p); // apply gravity
if (mario.p.y<0) mario.dead=1; // die if out of the map
{// take coins that mario touchs
coin_t* c;
c=(coin_t*)worldGetCell(mario.p.x, mario.p.y);
if (c->type==COIN && c->taken==0) {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) {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) {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) {coinAdd();c->taken=1;}
}
{// End level flag detection
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;
scoreAdd(400*e1->bonus);
}
else
mario_time_accel=0;
}
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 (mario.p.x+mario.p.vx<camera_x(mario.p.x))
{
mario.p.vx=0;
mario.p.x=camera_x(mario.p.x);
}
//teleporteurs_check();
box_move(&mario.p); // <-> + gravity
if (mario.p.y<0)
mario_dead=1;
if (mario.p.vx==0)
mario_time_accel=0;
// coins
coin_t* c;
c=(coin_t*)world_get(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);
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);
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);
if (c->type==COIN && c->taken==0)
{score_add_coin();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);
if (e1->type==END_LEVEL)
{
finish_level=1;
score_add(400*e1->bonus);
}
if (e2->type==END_LEVEL)
{
finish_level=1;
score_add(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);
if (t->type==GIFT || t->type==BRICK)
{
brick_t *c=(brick_t*)t;
if (c->time_hit_id==0 && mario.p.last_vy>0)
if (e2->type==END_LEVEL)
{
if (c->content==0 || c->number)
finish_level=1;
scoreAdd(400*e2->bonus);
}
}
{// mario box auto hit
gift_t* c=(gift_t*)worldGetCell((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h);
if ((c->type==GIFT || c->type==BRICK) && (c->time_hit_id==0 && mario.p.last_vy>0))
{
c->hidden=0;
mario.p.last_vy=0;
if (c->number)
{
c->time_hit_id=1;
mario.p.last_vy=0;
}
switch (c->content)
{
case 1: c->number--; coinAdd(); break;
if (c->content==1 && c->number)
{
c->number--;
score_add_coin();
score_add(200);
case 2: c->number--; bonusSet(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8); break;
case 3: c->number--; bonusSet(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8); break;
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==2 && c->number)
else if (c->content==0 && mario.p.h==M_BIG && c->type==BRICK)
{
c->number--;
bonus_set(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
c->state=c->time_hit_id=1;
mario.p.vy=3;
}
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);
}
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);
}
else if (c->content==0 && mario.size==M_BIG && c->type==BRICK)
{
c->state=1;
mario.p.vy=0;
}
c->hidden=0;
else if (c->content==0 && c->type==BRICK) c->time_hit_id=1;
}
}
//}
}

View File

@ -10,133 +10,107 @@
#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->x=p->xinit;
p->y=p->yinit;
p->v=p->vinit;
p->b.x=p->xinit;
p->b.y=p->yinit;
}
void move_plateforme(plateforme_t* p)
{/*
if (p->x+p->width-world_get_real_x0()<-50)
void move_plateforme(plateform_t* p)
{
// Si mario et la plateforme vont se chevaucher, la plateforme est immobilisée
{
box_t b = p->b;
b.x+=b.vx;
b.y+=b.vy;
int x_collide= (mario.p.x<=b.x && b.x<mario.p.x+mario.p.w) || (mario.p.x<=b.x+b.w-1 && b.x+b.w<mario.p.x+mario.p.w);
int y_collide= (mario.p.y<=b.y && b.y<mario.p.y+mario.p.h) || (mario.p.y<=b.y+b.h-1 && b.y+b.h<mario.p.y+mario.p.h);
if (x_collide&&y_collide)
return;
}
box_t temp=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))
{
box_t mario_clone=mario.p;
mario_clone.vx=temp.vx;
mario_clone.vy=temp.vy;
boxMove(&mario_clone);
mario.p.x=mario_clone.x;
mario.p.y=mario_clone.y;
}
if (p->b.vx==0)
{
p->b.vx=-temp.vx;
//p->b.x -= sgn(p->b.vx);
}
if (p->b.vy==0)
p->b.vy=-temp.vy;
}
void platformsDraw()
{
if (plateformes==0 || plateform_table_size==0)
return;
if (p->x-world_get_real_x0()-128>50)
return;
if (p->y-world_get_real_y0()-64>50)
return;
if (p->y+3-world_get_real_y0()<-50)
return;
*/
int xc = (mario.p.x<p->x+p->width && mario.p.x>=p->x) || (mario.p.x+mario.p.w<p->x+p->width && mario.p.x+mario.p.w>=p->x);
int yc = (mario.p.y-3==p->y);
if (p->type==P_FALLING)
{
if (p->v)
p->v++;
p->y+=p->v/2;
}
if (p->type==P_MOVING_H)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->v==0)
p->v=p->vinit;
p->x+=t_v;
if (xc&&yc)
mario.p.x+=t_v;
if (p->x+p->width > p->xmax && p->v>0)
p->v *= -1;
if (p->x < p->xmin && p->v<0)
p->v *= -1;
}
if (p->type==P_MOVING_V)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->v==0)
p->v=p->vinit;
p->y+=t_v;
if (p->y > p->ymax || p->y+3 < p->ymin)
p->v *= -1;
}
if (xc&&yc)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->type==P_FALLING)
mario.p.y+=p->v/2;
if (p->type==P_MOVING_V)
mario.p.y+=t_v;
if (p->type==P_MOVING_H)
mario.p.x+=t_v/2;
}
}
void display_plateformes()
{
if (plateformes==0 || plateforme_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->x; j < p->x+p->width; j+=3)
draw_tile(j-camera_x(),p->y-camera_y(), &tplateforme, 0,0);
//drect(p->x-world_get_real_x0(),64-(p->y-world_get_real_y0()),p->x-world_get_real_x0()+p->width,64-(p->y-world_get_real_y0()-3), C_BLACK);
for (int j=p->b.x; j < p->b.x+p->b.w; j+=3)
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];
if (p->x<=x && p->x+p->width>x && p->y<=y && p->y+3>y)
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;
}
return 0;
}
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, 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, 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, int score)
void saveSetTime(int world, int level, unsigned int time)
{
if (level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]==0 || score<level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY])
level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]=score;
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;
}
int get_progress_status()
unsigned int saveGetProgressStatus()
{
return progress_status;
}
}

View File

@ -6,21 +6,25 @@
#include <gint/clock.h>
#include <gint/timer.h>
// displaying time for volatile counters: here=1.5sec
#define DISPLAY_TIME 30
static int score=0;
static int lifes=3;
int combo=0;
int combo_id=-10;
int pieces=0;
static int pieces=0;
static unsigned int time_last_piece=0;
int time_id=0;
int time_left=0;
unsigned int time_id=0;
static int time_left=0;
int time_spent=0;
int finish_level=0;
void new_game()
void gameNew()
{
lifes=3;
@ -28,46 +32,48 @@ void new_game()
score=0;
combo=0;
combo_id=-10;
mario_smaller();
new_level();
marioSmaller();
mario.immunity=0;
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;
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 (i==0) return;
if (time_id-combo_id<=12 && combo)
{
score+=i;
combo_id=time_id;
@ -81,64 +87,55 @@ void score_add(int i)
}
}
void score_display()
void scoreDisplay()
{
char str[10];
sprintf(str, "%d", score);
dtext(0,0,str, C_BLACK, C_WHITE);
if (time_id-combo_id<=8 && time_id-combo_id>=0 && combo)
if (time_id<=(unsigned int)(combo_id+DISPLAY_TIME) && time_id>=(unsigned int)(combo_id)) //displays score
{
sprintf(str, "%d", score);
dtext(0,0,str, C_BLACK, C_WHITE);
}
if (time_id-combo_id<=8 && combo) // & combo only when there is a combo
{
sprintf(str, "+ %d", combo);
dtext(0,6,str, C_BLACK, C_WHITE);
}
else
{
combo=0;
}
sprintf(str, "c*%d", pieces);
dtext(50,0,str, C_BLACK, C_WHITE);
else combo=0; // combo too old
time_id++;
if (time_id%8==0)
if (time_last_piece<=time_id && time_id<=time_last_piece+DISPLAY_TIME) // display pieces only when 1 is taken during 2 seconds
{
time_left--;
time_spent++;
sprintf(str, "c*%d", pieces);
dtext(50,0,str, C_BLACK, C_WHITE);
}
sprintf(str, "TIME : %d", time_left);
dtext(87-7,0,str, C_BLACK, C_WHITE);
extern image_t img_time_over;
if (time_left==0)
if ((mario.dead|finish_level)==0)
{
dimage(0,0, &img_time_over);
dupdate();
sleep_ms(3,1000);
sleep_ms(3,1000);
sleep_ms(3,1000);
finish_level=0;
mario_dead=1;
if (0==(time_id++)%8)
{
time_left--;
time_spent++;
if (time_left==0)
{
extern image_t img_time_over;
dimage(0,0, &img_time_over); dupdate();
sleep_ms(3,3000);
finish_level=2;
return;
}
}
}
sprintf(str, "%d", time_left);
int i=0; while (str[i]) i++;
dtext(128-6*i, 1, str, C_BLACK, C_WHITE);
}
int get_time_spent()
{
return time_spent;
}
int getTimeSpent(void) { return time_spent; }
int lifesGet(void) { return lifes; }
void lifesSet(int l) { lifes = l; }
int lifes_get()
{
return lifes;
}
void lifes_lose()
{
lifes --;
}
void lifes_add()
{
lifes ++;
}
void lifesAdd(int l) { lifes += l; }

View File

@ -7,6 +7,8 @@ int dark_theme=0;
extern image_t img_tuyau;
const tileset_t tuyau={&img_tuyau, TILE_W, TILE_H, 1};
extern image_t img_arbre;
const tileset_t arbre={&img_arbre, TILE_W, TILE_H, 0};
extern image_t img_brick;
const tileset_t brick={&img_brick, TILE_W, TILE_H, 1};
@ -20,6 +22,9 @@ const tileset_t gift={&img_gift, TILE_W, TILE_H, 1};
extern image_t img_coin;
const tileset_t coin={&img_coin, TILE_W, TILE_H, 1};
extern image_t img_spikes;
const tileset_t spikes={&img_spikes, TILE_W, TILE_H, 1};
extern image_t img_nuage;
const tileset_t nuage={&img_nuage, TILE_W, TILE_H, 0};
extern image_t img_buisson;
@ -44,7 +49,7 @@ extern image_t img_star;
const tileset_t mario_starman={&img_star, TILE_W, TILE_H, 0};
extern image_t img_fleur;
const tileset_t fleur={&img_fleur, TILE_W, TILE_H, 0};
const tileset_t fleur={&img_fleur, 2*TILE_W, TILE_H, 0};
extern image_t img_bullet;
const tileset_t bullet={&img_bullet, TILE_W/2, TILE_H/2, 1};
@ -60,7 +65,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,71 +5,73 @@
#include <framerate.h>
#include <camera.h>
#include <gint/std/string.h>
#include <base.h>
#include <ennemi.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 (t.key>=0)
{
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); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x++;
}
if (t.key==MK_LEFT) while (mario.p.x+mario.p.w>=8*t.x)
{
dclear(C_WHITE); worldDraw(0,0); dupdate();
waitNextFrame(); waitNextFrame();
mario.p.x--;
}
/* End of animated section */
marioResetJump();
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
cameraAdjust();
for (int j=0; j<ennemiesNumber(); j++) if (ennemis_global[j].type==PLANTE_ID) for (int k=0; k<99; k++) plante_tour(&ennemis_global[j]);
const tuyau_t c = *((tuyau_t*)worldGetCell(mario.p.x, mario.p.y));
if (c.type==TUYAU && c.y==2) // animation de sortie
{
for (int j=0; j<8; j++)
{
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.y++;
}
}
mario.p.x=t.tx*8+4; mario.p.y=t.ty*8;
mario.p.vx=0; mario.p.vy=0;
camera_adjust();
}
}
}
}

View File

@ -1,247 +1,216 @@
#include "world.h"
#include "tile.h"
#include "mario.h"
#include "ennemi.h"
#include <gint/display.h>
#include "bonus.h"
#include <liblog.h>
#include "constants.h"
#include "ennemi.h"
#include <world.h>
#include <base.h>
#include <tile.h>
#include <level.h>
#include <keyboard.h>
#include <camera.h>
#include <mario.h>
#include <bonus.h>
#include <ennemi.h>
#include <plateforme.h>
#include <tuyau.h>
#include <bullets.h>
#include <keyboard.h>
#include <base.h>
#include <camera.h>
#include <level.h>
#include <liblog.h>
#include <gint/display.h>
#include <gint/std/string.h>
#include <gint/std/stdlib.h>
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;
if (0<=x && x<map_current->w && 0<=y && y<map_current->h)
return &map_current->data[x*map_current->h+y];
return &map_current->data[x*map_current->h+y];
else
{
return &death;
}
}
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)
return;
if (plan==1) switch (cell->type)
{
if (cell->type==TUYAU)
{
tuyau_t* i=(tuyau_t*)cell;
draw_tile(sx, sy, &tuyau, i->x, i->y);
}
case TUYAU:
tileDraw(sx, sy, &tuyau, ((tuyau_t*)cell)->x, ((tuyau_t*)cell)->y);
break;
if (cell->type==EARTH)
{
earth_t* i=(earth_t*)cell;
draw_tile(sx, sy, &earth, i->x, i->y);
}
if (cell->type==BLOC)
{
draw_tile(sx, sy, &bloc, 0, 0);
}
case ARBRE:
tileDraw(sx, sy, &arbre, ((arbre_t*)cell)->x, ((arbre_t*)cell)->y);
break;
if (cell->type==BLOC)
{
draw_tile(sx, sy, &bloc, 0, 0);
}
case EARTH:
tileDraw(sx, sy, &earth, ((earth_t*)cell)->x, ((earth_t*)cell)->y);
break;
if (cell->type==BRICK)
{
brick_t* i=(brick_t*)cell;
if (i->time_hit_id)
{
i->time_hit_id++;
sy+=2+(i->time_hit_id-4)/4;
if (i->time_hit_id==8)
i->time_hit_id=0;
if (i->state==1 && i->time_hit_id==0)
i->type=0;
}
if (i->hidden==0)
{
if (i->time_hit_id || i->content==0 || i->number>0)
draw_tile(sx, sy, &brick, 0, i->state);
else
draw_tile(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);
}
}
case BLOC:
tileDraw(sx, sy, &bloc, 0, 0);
break;
if (cell->type==GIFT)
case SPIKES:
tileDraw(sx, sy, &spikes, 0, 0);
break;
case BRICK:
if (((brick_t*)cell)->time_hit_id) // calculate collision animation
{
gift_t* i=(gift_t*)cell;
if (i->time_hit_id)
{
i->time_hit_id++;
sy+=2+(i->time_hit_id-4)/4;
if (i->time_hit_id==8)
i->time_hit_id=0;
}
if (i->hidden==0)
{
if (i->time_hit_id || i->number)
draw_tile(sx, sy, &gift, 0, 0);
else
draw_tile(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);
}
((brick_t*)cell)->time_hit_id++; // Next frame for the animation
sy+=2+(((brick_t*)cell)->time_hit_id-4)/4; // For the brick coordinate
if (((brick_t*)cell)->time_hit_id==8) ((brick_t*)cell)->time_hit_id=0; // End of animation
if (((brick_t*)cell)->state==1 && ((brick_t*)cell)->time_hit_id==0) ((brick_t*)cell)->type=0; // Delete brick
}
if (!((brick_t*)cell)->hidden)
{
if (((brick_t*)cell)->time_hit_id || !((brick_t*)cell)->content || ((brick_t*)cell)->number) tileDraw(sx, sy, &brick, 0, ((brick_t*)cell)->state);
else tileDraw(sx, sy, &gift, 1, 0);
if (((brick_t*)cell)->content==1 && ((brick_t*)cell)->time_hit_id && ((brick_t*)cell)->time_hit_id<=4) tileDraw(sx, sy+8, &coin, 0, 0); // Draw a coin
}
break;
case GIFT:
if (((gift_t*)cell)->time_hit_id)
{
((gift_t*)cell)->time_hit_id++;
sy+=2+(((gift_t*)cell)->time_hit_id-4)/4;
if (((gift_t*)cell)->time_hit_id==8) ((gift_t*)cell)->time_hit_id=0;
}
if (((gift_t*)cell)->hidden==0)
{
if (((gift_t*)cell)->time_hit_id || ((gift_t*)cell)->number) tileDraw(sx, sy, &gift, 0, 0);
else tileDraw(sx, sy, &gift, 1, 0);
if (((gift_t*)cell)->content==1 && ((gift_t*)cell)->time_hit_id && ((gift_t*)cell)->time_hit_id<=4) tileDraw(sx, sy+8, &coin, 0, 0);
}
break;
}
else
else switch (cell->type)
{
if (cell->type==COIN)
{
coin_t const * i=(coin_t*)cell;
draw_tile(sx, sy, &coin, i->taken, 0);
}
case COIN:
tileDraw(sx, sy, &coin, ((coin_t*)cell)->taken, 0);
break;
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);
if (i->type==NUAGE)
draw_tile(sx, sy, &nuage, i->x, i->y);
if (i->type==COLLINE)
draw_tile(sx, sy, &colline, i->x, i->y);
if (i->type==CASTLE)
draw_tile(sx, sy, &castle, i->x, i->y);
if (i->type==END_LEVEL)
draw_tile(sx-8, sy, &end_level, 0, i->y);
}
case BUISSON:
tileDraw(sx, sy, &buisson, ((deco_t*)cell)->x, ((deco_t*)cell)->y);
break;
case NUAGE:
tileDraw(sx, sy, &nuage, ((deco_t*)cell)->x, ((deco_t*)cell)->y);
break;
case COLLINE:
tileDraw(sx, sy, &colline, ((deco_t*)cell)->x, ((deco_t*)cell)->y);
break;
case CASTLE:
tileDraw(sx, sy, &castle, ((deco_t*)cell)->x, ((deco_t*)cell)->y);
break;
case END_LEVEL:
tileDraw(sx-8, sy, &end_level, ((deco_t*)cell)->x, ((deco_t*)cell)->y);
break;
}
}
int world_get_ctg(int x, int y)
int worldGetCellCategory(int x, int y)
{
cell_t *c=world_get(x,y);
if (c==0)
{
return CTG_DEATH;
}
if (plateforme_check_collide(x,y))
return CTG_SOIL;
cell_t *c=worldGetCell(x,y); // get cell props
if (c==0) return CTG_DEATH; // out of the map
if (platformsCollisionTest(x,y)) return CTG_SOIL; // tested point is a platform
if (c->type==ARBRE && (((arbre_t*)c)->x==1&&((arbre_t*)c)->y==1)) return CTG_EMPTY; // tree trunk
switch (c->type)
{
case TUYAU:
case GIFT:
case BRICK:
case EARTH:
case BLOC:
if (((brick_t*)c)->content==0 && ((brick_t*)c)->time_hit_id && ((brick_t*)c)->state) return CTG_EMPTY;
// fall through
case TUYAU: case GIFT: case EARTH: case BLOC: case ARBRE:
return CTG_SOIL;
default:
return CTG_EMPTY;
}
}
void world_draw()
void worldDraw()
{
//camera_move(0);
camera_adjust();
int mx0=camera_x();
int my0=camera_y();
int sx0=mx0%8;
int sy0=my0%8;
int 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,0); //ap
my+=8;
}
mx+=8;
}
cameraMove();
bonus_draw();
display_ennemi_table();
const int mx0=cameraX(), my0=cameraY();
const int sx0=mx0%8, sy0=my0%8;
bullet_display();
display_plateformes();
mario_draw();
//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);
// animated items
bonusDraw();
ennemiesDisplay();
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);
// 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);
//int mx, my;
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);
}
void world_move()
void worldMove()
{
mkb_update();
for (int i=0; i<ennemis_global_size; i++)
{
move_ennemi(&ennemis_global[i]);
}
bonus_move();
bullet_move();
move_plateformes();
mario_move();
teleport_active();
MKB_update();
for (int i=0; i<ennemiesNumber(); i++) ennemiMove(&ennemis_global[i]);
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 * a)
{
// Resets mario's vx
mario.p.vx=0; mario.p.vy=0;
mario.p.vx=mario.p.vy=0;
// Free the previous map
if (map_current)
{
free_prof(map_current);
if (map_current->data) freeProf(map_current->data);
freeProf(map_current);
map_current=0;
}
// If the new map size is null => invalid map, return
if (0==w*h)
return;
if (0==w*h) return;
// Calculates the new struct size
int size= 4*sizeof(int) + sizeof(cell_t)*w*h;
map_current=(map_t*)malloc_prof(size);
if (map_current==0)
malloc_error();
// Copy map into ram
map_current=(map_t*)mallocProf(sizeof(map_t)); if (!map_current) mallocError();
// Copy the map to ram
map_current->w = w;
map_current->h = h;
mario.p.x = map_current->start_x = x;
mario.p.y = map_current->start_y = y;
memcpy(map_current->data, a, sizeof(cell_t)*w*h);
}
map_current->data=a;
//memcpy(map_current->data, a, sizeof(cell_t)*w*h);
}