Compare commits
32 Commits
Author | SHA1 | Date |
---|---|---|
Milang | 47529dd99c | |
Milang | 2a85f98b93 | |
Milang | 14caa99616 | |
Milang | 1a877773f7 | |
Milang | 86286e4b29 | |
Milang | 0eaaac1a9c | |
Milang | 0f6f429514 | |
Milang | 21734f0765 | |
Milang | e06d2eb947 | |
Milang | b6ae4b8cc9 | |
Milang | eb1e3e1fc6 | |
Milang | 9476c81e50 | |
Milang | 35c1214270 | |
Milang | 23b98fd3d4 | |
milang | 13872b3dcb | |
milang | 5f9791f6aa | |
milang | 1b3acce432 | |
Milang | 6a744b0547 | |
Milang | 76fe4d2e3f | |
Milang | 9760257d76 | |
Milang | 7c9da97baf | |
Milang | 98ff078150 | |
Milang | da4d716878 | |
Milang | a2754a92fd | |
Milang | 3c467a5c5b | |
Milang | 2547765eef | |
Milang | 8306be7e7a | |
Milang | f739816d03 | |
Milang | 7475d478f5 | |
Milang | 5aeb14b1c6 | |
Milang | 72d1ce0255 | |
Milang | 27a22209e3 |
|
@ -1,2 +1,4 @@
|
|||
build-fx/*
|
||||
build-cg/*
|
||||
build-cg/*
|
||||
INIT/CasioRAM.mem
|
||||
SuperCbr.dlw
|
||||
|
|
|
@ -16,8 +16,8 @@ Type=1
|
|||
Order=1
|
||||
Top=15
|
||||
Left=7800
|
||||
Height=4740
|
||||
Width=5535
|
||||
Height=6885
|
||||
Width=8400
|
||||
State=0
|
||||
Flags=00000001
|
||||
OptionA=15
|
||||
|
@ -26,8 +26,8 @@ OptionB=15
|
|||
[_3]
|
||||
Type=6
|
||||
Order=2
|
||||
Top=4740
|
||||
Left=7800
|
||||
Top=4035
|
||||
Left=2715
|
||||
Height=6390
|
||||
Width=5535
|
||||
State=0
|
||||
|
|
BIN
SuperCbr.g1a
Before Width: | Height: | Size: 585 B |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 647 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 584 B |
Before Width: | Height: | Size: 611 B |
|
@ -11,8 +11,8 @@ int sgn(const int x);
|
|||
|
||||
int abs(const int x);
|
||||
|
||||
void* mallocProf(int size);
|
||||
void* mallocProf(const int size);
|
||||
|
||||
void freeProf(void * p);
|
||||
void freeProf(void * const p);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ typedef struct
|
|||
int p1;
|
||||
} bonus_t;
|
||||
|
||||
void bonusSet(bonus_id t, int x, int y);
|
||||
void bonusSet(bonus_id const t, int const x, int const y);
|
||||
|
||||
void bonusDraw();
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ typedef struct
|
|||
} box_t;
|
||||
|
||||
void boxMove(box_t * b);
|
||||
|
||||
bool boxContact(box_t const * b1, box_t const * b2);
|
||||
void boxJump(box_t * b, int height);
|
||||
|
||||
void boxJump(box_t * b, int height, bool floor_needed);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +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
|
||||
|
|
|
@ -1,27 +1,34 @@
|
|||
#ifndef ENNEMI_H
|
||||
#define ENNEMI_H
|
||||
|
||||
#include "box.h"
|
||||
#define NOMBRE_ENNEMIS 6
|
||||
#include <box.h>
|
||||
|
||||
#define ALIVE 1
|
||||
#define DEAD 0
|
||||
|
||||
#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 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
|
||||
#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
|
||||
|
||||
// Dimensions pr les boites
|
||||
|
||||
|
||||
#define PLANTE_NLAPS 99
|
||||
|
||||
|
||||
typedef struct
|
||||
|
@ -33,14 +40,17 @@ typedef struct
|
|||
int p1 :14;
|
||||
} ennemi_t;
|
||||
|
||||
void ennemiDisplay(ennemi_t * e);
|
||||
void ennemiDisplay(ennemi_t const * e);
|
||||
|
||||
extern ennemi_t * ennemis_global;
|
||||
extern int ennemis_global_size;
|
||||
int ennemiesNumber();
|
||||
|
||||
void ennemiesDisplay();
|
||||
|
||||
void ennemiMove(ennemi_t *e);
|
||||
void ennemiMove(ennemi_t * e);
|
||||
|
||||
void EnnemiesInit(ennemi_t * table, int s);
|
||||
void ennemiesInit(ennemi_t * table, int s);
|
||||
|
||||
void plante_tour(ennemi_t *e);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef MARIO_H
|
||||
#define MARIO_H
|
||||
|
||||
#define M_SMALL 0
|
||||
#define M_BIG 1
|
||||
#define M_SMALL 8
|
||||
#define M_BIG 16
|
||||
|
||||
#define M_LEFT1 0
|
||||
#define M_LEFT2 1
|
||||
|
@ -21,36 +21,23 @@
|
|||
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 marioDraw();
|
||||
|
||||
//void mario_physics();
|
||||
|
||||
void marioJump();
|
||||
void resetMarioJump(); // resets coyote time & jump buffering (used by teleporters)
|
||||
|
||||
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_xMax;
|
||||
extern int mario_dead;
|
||||
extern int id_frame;
|
||||
extern int mario_immunity;
|
||||
extern int mario_has_bullets;
|
||||
extern int last_vx_sign;
|
||||
|
||||
extern int mario_starMode;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -25,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;
|
||||
|
|
|
@ -19,6 +19,7 @@ typedef enum
|
|||
ARBRE,
|
||||
GIFT,
|
||||
COIN,
|
||||
SPIKES,
|
||||
NUAGE,
|
||||
BUISSON,
|
||||
COLLINE,
|
||||
|
@ -115,7 +116,7 @@ cell_t* worldGetCell(int x, int y);
|
|||
|
||||
void cellDraw(int cx, int cy, int sx, int sy, int plan);
|
||||
|
||||
void worldSet(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 worldDraw();
|
||||
void worldMove();
|
||||
|
@ -134,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;
|
||||
|
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 872 B After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 868 B |
|
@ -23,7 +23,7 @@ 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,7 +75,7 @@ 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)
|
||||
|
||||
|
@ -109,8 +109,12 @@ for x in range(0,img.size[0]):
|
|||
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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -27,7 +27,7 @@ int abs(const int x)
|
|||
|
||||
static int ram_used=0;
|
||||
|
||||
void* mallocProf(int size)
|
||||
void* mallocProf(int const size)
|
||||
{
|
||||
void* p=malloc(size);
|
||||
if (p)
|
||||
|
|
138
src/bonus.c
|
@ -1,100 +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 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;
|
||||
}
|
||||
|
||||
#include <score.h> // bonus en cas de prise
|
||||
|
||||
void bonusMove() //+collision
|
||||
{
|
||||
if (bonus.type==BONUS_NONE)
|
||||
return;
|
||||
if (bonus.type == BONUS_NONE) return;
|
||||
|
||||
if (bonus.type==BONUS_STAR)
|
||||
{
|
||||
boxJump(&bonus.b,4);
|
||||
}
|
||||
// animation de l'objet
|
||||
boxMove(&bonus.b);
|
||||
if (bonus.type==BONUS_CHAMPI || bonus.type==BONUS_1UP || bonus.type==BONUS_STAR)
|
||||
{
|
||||
|
||||
switch (bonus.type)
|
||||
{
|
||||
case BONUS_STAR:
|
||||
// bounce
|
||||
boxJump(&bonus.b, 4, true);
|
||||
|
||||
// fall through
|
||||
case BONUS_CHAMPI:
|
||||
case BONUS_1UP:
|
||||
// bounce against walls
|
||||
if (bonus.b.vx==0)
|
||||
{
|
||||
if (bonus.p1==0)
|
||||
{
|
||||
bonus.b.vx=2;
|
||||
bonus.p1=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bonus.p1*=-1;
|
||||
bonus.b.vx=2*bonus.p1;
|
||||
}
|
||||
if (bonus.p1==0) bonus.p1=1;
|
||||
else bonus.p1*=-1;
|
||||
|
||||
bonus.b.vx=2*bonus.p1;
|
||||
}
|
||||
if (bonus.b.y<0)
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
}
|
||||
|
||||
int collide=boxContact(&mario.p, &bonus.b);
|
||||
if (collide)
|
||||
if (bonus.type!=BONUS_NONE && boxContact(&mario.p, &bonus.b))
|
||||
{
|
||||
if (bonus.type==BONUS_CHAMPI)
|
||||
switch (bonus.type)
|
||||
{
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
scoreAdd(1000);
|
||||
marioBigger();
|
||||
}
|
||||
if (bonus.type==BONUS_FLEUR)
|
||||
{
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
mario_has_bullets=1;
|
||||
scoreAdd(1000);
|
||||
}
|
||||
if (bonus.type==BONUS_1UP)
|
||||
{
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
scoreAdd(1000);
|
||||
case BONUS_CHAMPI:
|
||||
case BONUS_FLEUR:
|
||||
if (mario.p.h==M_SMALL) marioBigger();
|
||||
else mario.bullets=1;
|
||||
break;
|
||||
|
||||
case BONUS_1UP:
|
||||
lifesAdd(1);
|
||||
}
|
||||
if (bonus.type==BONUS_STAR)
|
||||
{
|
||||
break;
|
||||
|
||||
case BONUS_STAR:
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
scoreAdd(1000);
|
||||
mario_starMode=1;
|
||||
mario.starMode=1;
|
||||
}
|
||||
scoreAdd(1000);
|
||||
bonusSet(BONUS_NONE,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
#include <camera.h>
|
||||
#include <tile.h>
|
||||
|
||||
void bonusDraw()
|
||||
{
|
||||
//bonusMove();
|
||||
if (bonus.type==BONUS_NONE)
|
||||
return;
|
||||
if (bonus.type==BONUS_CHAMPI)
|
||||
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &champi, 0,0);
|
||||
if (bonus.type==BONUS_FLEUR)
|
||||
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &fleur, 0,0);
|
||||
if (bonus.type==BONUS_1UP)
|
||||
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &life_1up, 0,0);
|
||||
if (bonus.type==BONUS_STAR)
|
||||
tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), &mario_starman, 0,0);
|
||||
if (bonus.type==BONUS_NONE) return;
|
||||
tileset_t const * t=0;
|
||||
switch (bonus.type)
|
||||
{
|
||||
case BONUS_CHAMPI:
|
||||
t=&champi;
|
||||
break;
|
||||
|
||||
case BONUS_FLEUR:
|
||||
t=&fleur;
|
||||
break;
|
||||
|
||||
case BONUS_1UP:
|
||||
t=&life_1up;
|
||||
break;
|
||||
|
||||
case BONUS_STAR:
|
||||
t=&mario_starman;
|
||||
break;
|
||||
}
|
||||
if (t) tileDraw(bonus.b.x-cameraX(), bonus.b.y-cameraY(), t, 0,0);
|
||||
}
|
||||
|
|
87
src/box.c
|
@ -7,17 +7,13 @@
|
|||
|
||||
int check_collision(box_t *b)
|
||||
{
|
||||
for (int i=0; i<ennemis_global_size; i++) if (boxContact(&ennemis_global[i].b,b)) return 1;
|
||||
for (int i=0; i<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;/*
|
||||
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);*/
|
||||
|
||||
|
||||
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;
|
||||
|
@ -33,11 +29,9 @@ static void move_x(box_t * b)
|
|||
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 (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
|
||||
coef=2;//ralentir dans l'eau
|
||||
if (frame_id%coef)
|
||||
return;
|
||||
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)
|
||||
{
|
||||
|
@ -73,7 +67,7 @@ static void move_y(box_t * b)
|
|||
int coef=1;//1;
|
||||
if (worldGetCellCategory(b->x, b->y)==CTG_WATER || worldGetCellCategory(b->x+b->w-1, b->y)==CTG_WATER)
|
||||
coef=2;// 0.5
|
||||
if (frame_id%coef)
|
||||
if (time_id%coef)
|
||||
return;
|
||||
|
||||
if (sgn_vy)
|
||||
|
@ -92,19 +86,40 @@ static void move_y(box_t * b)
|
|||
if (b->vy>0)
|
||||
{
|
||||
int old=b->x;
|
||||
if (worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
if (worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
if (worldGetCellCategory(b->x, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x++;
|
||||
|
||||
if (worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
if (worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
if (worldGetCellCategory(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && worldGetCellCategory(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
|
||||
b->x--;
|
||||
{ // 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;
|
||||
|
@ -136,23 +151,21 @@ void boxMove(box_t * b)
|
|||
move_y(b);
|
||||
}
|
||||
|
||||
void boxJump(box_t * b, int height)
|
||||
void boxJump(box_t * b, int height, bool floor_needed)
|
||||
{
|
||||
int sgn_vy=-1*sgn(height);
|
||||
if (!floor_needed)
|
||||
{
|
||||
b->vy=height;
|
||||
return;
|
||||
}
|
||||
|
||||
const int sgn_vy=-1*sgn(height);
|
||||
if (sgn_vy)
|
||||
{
|
||||
int sol=0, eau=0;
|
||||
for (int j=0; j<b->w; j++)
|
||||
for (int j = 0; j < b->w; j++) if (worldGetCellCategory( b->x + j, b->y + sgn_vy) == CTG_SOIL)
|
||||
{
|
||||
int typetemp=worldGetCellCategory(b->x+j ,b->y+sgn_vy);
|
||||
if (typetemp==CTG_SOIL)
|
||||
sol++;
|
||||
if (typetemp==CTG_WATER)
|
||||
eau++;
|
||||
b->vy=height;
|
||||
return;
|
||||
}
|
||||
if (sol)
|
||||
b->vy=height;
|
||||
else if (eau)
|
||||
b->vy+=height/2;
|
||||
}
|
||||
}
|
||||
|
|
60
src/bullet.c
|
@ -24,12 +24,13 @@ void bulletThrow()
|
|||
bullets[i].type=1;
|
||||
bullets[i].b.x=mario.p.x;
|
||||
bullets[i].b.y=mario.p.y+8;
|
||||
if (last_vx_sign==0)
|
||||
bullets[i].b.vx=-9; //speed = 9
|
||||
else
|
||||
bullets[i].b.vx=9;
|
||||
|
||||
if (mario.last_vx_sgn==0) bullets[i].b.vx=-9; //speed = 9
|
||||
else bullets[i].b.vx=9;
|
||||
|
||||
bullets[i].b.vy=0;
|
||||
bullets[i].p1=last_vx_sign;
|
||||
bullets[i].p1=mario.last_vx_sgn;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -37,43 +38,28 @@ void bulletThrow()
|
|||
|
||||
void bulletsDraw()
|
||||
{
|
||||
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);
|
||||
}
|
||||
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 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))
|
||||
{
|
||||
boxJump(&bullets[i].b,4);
|
||||
boxMove(&bullets[i].b);
|
||||
if (bullets[i].b.vx==0)
|
||||
bullets[i].type=0;
|
||||
if (bullets[i].b.y<0)
|
||||
bullets[i].type=0;
|
||||
if (bullets[i].b.x<=cameraX()-bullets[i].b.w || bullets[i].b.x>=cameraX()+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;
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ennemis_global[a].life=DEAD;
|
||||
bullets[i].type=0;
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
56
src/camera.c
|
@ -1,38 +1,28 @@
|
|||
#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 cameraX() {return min(max(mario.p.x-40,0),map_current->w*8-128);}
|
||||
int cameraY() {return max(y-32,0);}
|
||||
int cameraY() {return max(max(y-32,0)-delta_y,0);}
|
||||
|
||||
static int immobile=0;
|
||||
static int last_vy=0;
|
||||
|
||||
static int distance=0;
|
||||
|
||||
void cameraMove() // movement vertical seulement
|
||||
void cameraMove() // only vertical movement
|
||||
{
|
||||
/* static int isMoving=0;
|
||||
static int ref_y=0;
|
||||
if (mario.p.y-cameraY()<16 || mario.p.y-cameraY()>56)
|
||||
{
|
||||
isMoving=1;
|
||||
ref_y=mario.p.y;
|
||||
}
|
||||
if (isMoving)
|
||||
{
|
||||
for (int i=0; i<9; i++)
|
||||
y+=sgn(mario.p.y-y);
|
||||
if (y==ref_y)
|
||||
isMoving=0;
|
||||
}
|
||||
*/
|
||||
static int camera_vy=0;
|
||||
if (mario.p.y==last_vy) // mario arrêté
|
||||
immobile++;
|
||||
|
||||
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;
|
||||
|
@ -40,26 +30,20 @@ void cameraMove() // movement vertical seulement
|
|||
}
|
||||
if (mario.p.y-cameraY()-mario.p.h<16 || mario.p.y-cameraY()>54)
|
||||
{
|
||||
y+=5*sgn(mario.p.y-y);
|
||||
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);
|
||||
}
|
||||
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++;
|
||||
if (camera_vy*(camera_vy+1)>distance) camera_vy--;
|
||||
else camera_vy++;
|
||||
//y++;
|
||||
|
||||
if (camera_vy<0)
|
||||
camera_vy=0;
|
||||
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)
|
||||
{
|
||||
|
@ -67,7 +51,7 @@ void cameraMove() // movement vertical seulement
|
|||
camera_vy=0;
|
||||
}
|
||||
else
|
||||
y+=(camera_vy*sgn(mario.p.y-y))/2;
|
||||
y+=(camera_vy*sgn(mario.p.y-y))/2;
|
||||
|
||||
}
|
||||
last_vy=mario.p.y;
|
||||
|
|
32
src/config.c
|
@ -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;
|
||||
}
|
||||
ll_pause();
|
||||
MKB_clear();
|
||||
dfont(f);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
497
src/ennemi.c
|
@ -8,107 +8,168 @@
|
|||
#include <camera.h>
|
||||
#include <level.h>
|
||||
#include <gint/std/string.h>
|
||||
#include <constants.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
const int ennemi_widths [NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8 , 8};
|
||||
const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 12, 9, 12, 9};
|
||||
/** 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};
|
||||
|
||||
void ennemiDisplay(ennemi_t * e)
|
||||
/** 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 (e->life==0)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void ennemiDisplay(ennemi_t const * e)
|
||||
{
|
||||
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->p1>=30) e->type=NONE; // died 1.5 sec before
|
||||
}
|
||||
if (e->type==NONE)
|
||||
return;
|
||||
if (e->b.x<=cameraX(0)-e->b.w || e->b.x>=cameraX(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)
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
|
||||
if (e->life==0)
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &goomba, 0, 0);
|
||||
}
|
||||
if (e->type==KOOPA_V_ID)
|
||||
{
|
||||
extern image_t img_koopa_verte;
|
||||
tileset_t koopa_verte={&img_koopa_verte, ennemi_widths[KOOPA_V_ID], ennemi_heights[KOOPA_V_ID], 1};
|
||||
if (e->life==1)
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &koopa_verte, (1+e->p1)+(time_id/8)%2, 0);
|
||||
}
|
||||
if (e->type==KOOPA_R_ID)
|
||||
{
|
||||
extern image_t img_koopa_rouge;
|
||||
tileset_t koopa_rouge={&img_koopa_rouge, ennemi_widths[KOOPA_R_ID], ennemi_heights[KOOPA_R_ID], 1};
|
||||
if (e->life==1)
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &koopa_rouge, (1+e->p1)+(time_id/8)%2, 0);
|
||||
}
|
||||
if (e->type==CARAPACE_VERTE)
|
||||
{
|
||||
extern image_t img_carapace_verte;
|
||||
tileset_t carapace_verte={&img_carapace_verte, ennemi_widths[CARAPACE_VERTE], ennemi_heights[CARAPACE_VERTE], 1};
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &carapace_verte, 0, 0);
|
||||
}
|
||||
if (e->type==CARAPACE_ROUGE)
|
||||
{
|
||||
extern image_t img_carapace_rouge;
|
||||
tileset_t carapace_rouge={&img_carapace_rouge, ennemi_widths[CARAPACE_ROUGE], ennemi_heights[CARAPACE_ROUGE], 1};
|
||||
tileDraw(e->b.x-cameraX(0), e->b.y-cameraY(mario.p.y), &carapace_rouge, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p)); }
|
||||
|
||||
void hurtMario()
|
||||
{ if (mario.size==M_SMALL && mario_immunity==0)
|
||||
{mario_dead=1;finish_level=0;}
|
||||
else
|
||||
marioSmaller();
|
||||
}
|
||||
|
||||
void ennemiMove(ennemi_t *e)
|
||||
{
|
||||
|
||||
if (e->b.x<cameraX()+128+30 && e->b.x>cameraX()-30)
|
||||
e->discovered=1;
|
||||
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_hitMario=ennemi_check_collision(e);
|
||||
if (e_hitMario&&mario_starMode)
|
||||
if (e_hitMario&&mario.starMode)
|
||||
{
|
||||
e->life=DEAD;
|
||||
e->p1=0;
|
||||
scoreAdd(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->type!=NONE)
|
||||
|
@ -134,154 +195,58 @@ void ennemiMove(ennemi_t *e)
|
|||
{
|
||||
t->life=DEAD;
|
||||
t->p1=0;
|
||||
scoreAdd(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*)worldGetCell(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;
|
||||
scoreAdd(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
|
||||
{
|
||||
case KOOPA_R_ID:
|
||||
boxMove(&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_hitMario)
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
{
|
||||
e->life=DEAD;
|
||||
e->p1=0;
|
||||
scoreAdd(200);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[GOOMBA_ID]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->type==KOOPA_V_ID)
|
||||
{
|
||||
boxMove(&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_hitMario)
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
{
|
||||
e->type=CARAPACE_VERTE;
|
||||
e->b.h=ennemi_heights[CARAPACE_VERTE];
|
||||
e->p1=2;
|
||||
e->b.vx=0;
|
||||
scoreAdd(200);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->type==KOOPA_R_ID)
|
||||
{
|
||||
boxMove(&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
|
||||
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 (worldGetCellCategory(e->b.x+s, e->b.y-1)==CTG_EMPTY && sgn(e->b.vx)==sgn(s))
|
||||
{
|
||||
e->p1*=-1;
|
||||
e->b.vx=e->p1;
|
||||
}
|
||||
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_hitMario)
|
||||
// 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;
|
||||
scoreAdd(200);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[CARAPACE_ROUGE]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
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)
|
||||
|
@ -290,93 +255,105 @@ void ennemiMove(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_hitMario)
|
||||
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
|
||||
hurtMario();
|
||||
{ // 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;
|
||||
}
|
||||
|
||||
}
|
||||
boxMove(&e->b);
|
||||
return;
|
||||
}
|
||||
else hurtMario();
|
||||
break;
|
||||
|
||||
case PLANTE_ID:
|
||||
hurtMario();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ennemi_t * ennemis_global=0;
|
||||
int ennemis_global_size=0;
|
||||
void ennemiesDisplay()
|
||||
{
|
||||
for (int i=0; i<ennemis_global_size; i++)
|
||||
{
|
||||
ennemiDisplay(&ennemis_global[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EnnemiesInit(ennemi_t * table, int s)
|
||||
{
|
||||
ennemis_global_size=0;
|
||||
if (ennemis_global)
|
||||
{
|
||||
freeProf(ennemis_global);
|
||||
ennemis_global=0;
|
||||
}
|
||||
if (0==s)
|
||||
return;
|
||||
int size=sizeof(ennemi_t)*s;
|
||||
ennemis_global=mallocProf(size);
|
||||
if (ennemis_global==0)
|
||||
mallocError();
|
||||
ennemis_global_size=s;
|
||||
memcpy(ennemis_global, table, size);
|
||||
for (int i=0; i<ennemis_global_size; i++) ennemiDisplay(&ennemis_global[i]);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ void MKB_clear()
|
|||
int MKB_getkey()
|
||||
{
|
||||
MKB_clear();
|
||||
|
||||
/*
|
||||
while (1)
|
||||
{
|
||||
key_event_t const e=pollevent();
|
||||
|
@ -37,6 +37,8 @@ int MKB_getkey()
|
|||
else
|
||||
sleep(); // Processor friendly :)
|
||||
}
|
||||
*/
|
||||
return getkey_opt(GETKEY_REP_ARROWS,0).key;
|
||||
}
|
||||
|
||||
static int menu_pause() // 1 exit, 0 continue
|
||||
|
@ -98,7 +100,7 @@ static int menu_pause() // 1 exit, 0 continue
|
|||
if (a==10) // Cheat code
|
||||
{
|
||||
marioBigger();
|
||||
mario_has_bullets=1;
|
||||
mario.bullets=1;
|
||||
|
||||
lifesAdd(20);
|
||||
extern image_t img_dev;
|
||||
|
|
23
src/level.c
|
@ -34,6 +34,7 @@
|
|||
#define PACKED_NUAGE 15
|
||||
#define PACKED_ARBRE_TRONC 16
|
||||
#define PACKED_ARBRE_FEUILLES 17
|
||||
#define PACKED_PLANTE 18
|
||||
|
||||
void mallocError()
|
||||
{
|
||||
|
@ -85,7 +86,7 @@ static void unpackLevel(packed_level_t * p)
|
|||
|
||||
int sx=0, sy=p->height; // Mario start coords
|
||||
|
||||
ennemi_t ennemis[20]={0};
|
||||
ennemi_t ennemis[30]={0};
|
||||
int nombre_ennemis=0;
|
||||
|
||||
|
||||
|
@ -318,6 +319,12 @@ static void unpackLevel(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)
|
||||
{
|
||||
|
@ -329,10 +336,12 @@ static void unpackLevel(packed_level_t * p)
|
|||
ll_sendp(LEVEL_INFO, "\n[i]Converted!\n[i]Sending to level zone...", w,h);
|
||||
worldSet(w, h, sx, sy, c);
|
||||
ll_sendp(LEVEL_INFO, "\n[i]Achieved unpacking", w,h);
|
||||
freeProf(c);
|
||||
|
||||
// Don't free c, it will be automatically managed by the worldSet function
|
||||
//freeProf(c);
|
||||
|
||||
|
||||
EnnemiesInit(ennemis, nombre_ennemis);
|
||||
ennemiesInit(ennemis, nombre_ennemis);
|
||||
}
|
||||
|
||||
void setLevel(int w, int l)
|
||||
|
@ -340,7 +349,7 @@ void setLevel(int w, int l)
|
|||
levelNew();
|
||||
teleportersSet(0,0);
|
||||
worldSet(0,0,0,0,0);
|
||||
EnnemiesInit(0, 0);
|
||||
ennemiesInit(0, 0);
|
||||
platformsInit(0, 0);
|
||||
|
||||
if (w+1==1 && l+1==1) // 1-2
|
||||
|
@ -382,6 +391,12 @@ void setLevel(int w, int l)
|
|||
extern packed_level_t bin_lvl_1_3;
|
||||
unpackLevel(&bin_lvl_1_3);
|
||||
}
|
||||
|
||||
if (w+1==1 && l+1==4) // 1-2
|
||||
{
|
||||
extern packed_level_t bin_lvl_1_4;
|
||||
unpackLevel(&bin_lvl_1_4);
|
||||
}
|
||||
}
|
||||
|
||||
void getLevelID(int w, int l, char * str)
|
||||
|
|
|
@ -252,17 +252,13 @@ void launchUI() // Main Menu
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int frame_id;
|
||||
|
||||
int PlayLevel(int w, int l)
|
||||
{
|
||||
time_id=0;
|
||||
initRefreshTimer();
|
||||
|
||||
//int finish_status=0; // FAil
|
||||
finish_level=0; mario_dead=0;
|
||||
finish_level=0; mario.dead=0;
|
||||
setLevel(w, l);
|
||||
if (map_current==0)
|
||||
{
|
||||
|
@ -271,14 +267,13 @@ int PlayLevel(int w, int l)
|
|||
}
|
||||
cameraAdjust();
|
||||
bonusSet(0, 0, 0);
|
||||
|
||||
mario.last_vx_sgn=1;
|
||||
|
||||
|
||||
while(global_quit==0)
|
||||
{
|
||||
waitNextFrame();
|
||||
|
||||
frame_id++;
|
||||
//marioMove();
|
||||
|
||||
worldMove();
|
||||
|
@ -287,9 +282,9 @@ int PlayLevel(int w, int l)
|
|||
scoreDisplay();
|
||||
|
||||
dupdate();
|
||||
if (mario_dead)
|
||||
if (mario.dead)
|
||||
{
|
||||
mario_immunity=0;
|
||||
mario.immunity=0;
|
||||
int i=6;
|
||||
while(mario.p.y>=0)
|
||||
{
|
||||
|
@ -313,7 +308,7 @@ int PlayLevel(int w, int l)
|
|||
{
|
||||
quitRefreshTimer();
|
||||
// TODO ajouter temps au score etc
|
||||
if (finish_level==1) sleep_ms(3,3000); // win
|
||||
if (finish_level==1) sleep_ms(3,3000); // win
|
||||
return finish_level;
|
||||
}
|
||||
|
||||
|
|
329
src/mario.c
|
@ -1,4 +1,5 @@
|
|||
#include "mario.h"
|
||||
#include <mario.h>
|
||||
|
||||
#include "tile.h"
|
||||
#include "world.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -10,250 +11,196 @@
|
|||
#include <camera.h>
|
||||
#include <base.h>
|
||||
|
||||
|
||||
int id_frame=0;
|
||||
|
||||
pnj mario=
|
||||
{
|
||||
{26,17,6,8,0,0,0,1},
|
||||
M_SMALL,
|
||||
M_RIGHT1, M_WALK,
|
||||
0
|
||||
};
|
||||
|
||||
int mario_has_bullets=0;
|
||||
static int mario_timeAccel=0;
|
||||
int mario_dead=0;
|
||||
|
||||
// Used to draw mario (mario direction)
|
||||
int last_vx_sign=1;
|
||||
|
||||
// After he becomes little
|
||||
int mario_immunity=0;
|
||||
|
||||
|
||||
int mario_starMode=0;
|
||||
|
||||
void marioBigger()
|
||||
{
|
||||
mario.p.h=16;
|
||||
mario.size=M_BIG;
|
||||
mario_has_bullets=0;
|
||||
mario.p.h=M_BIG;
|
||||
mario.bullets=0;
|
||||
}
|
||||
|
||||
void marioSmaller()
|
||||
{
|
||||
mario.p.h=8;
|
||||
mario.size=M_SMALL;
|
||||
mario_has_bullets=0;
|
||||
if (mario_immunity==0)
|
||||
mario_immunity=1;
|
||||
//mario.p.vy=5;
|
||||
mario.p.h=M_SMALL;
|
||||
mario.bullets=0;
|
||||
if (mario.immunity==0) mario.immunity=1;
|
||||
}
|
||||
|
||||
void marioDraw()
|
||||
{
|
||||
if ( (mario_immunity==0 || (mario_immunity/7)%2==0) && (mario_starMode/2)%2==0)
|
||||
if ( (mario.immunity==0 || (mario.immunity/7)%2==0) && (mario.starMode/2)%2==0)
|
||||
{
|
||||
const int mx=mario.p.x-cameraX(mario.p.x)-1;
|
||||
const int my=mario.p.y-cameraY(mario.p.y);
|
||||
if (mario.size==M_SMALL)
|
||||
if (mario.p.h==M_SMALL)
|
||||
{
|
||||
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
|
||||
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
|
||||
else tileDraw(mx, my, &mario_small, 2*last_vx_sign, 0);
|
||||
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn+(time_id/4)%2, 0);
|
||||
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn+(time_id/8)%2, 0);
|
||||
else tileDraw(mx, my, &mario_small, 2*mario.last_vx_sgn, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs(mario.p.vx)>=3) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
|
||||
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
|
||||
else tileDraw(mx, my, &mario_big, 3*last_vx_sign, mario_has_bullets);
|
||||
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 = worldGetCellCategory(x, y-1);
|
||||
if (type_sol==CTG_SOIL)
|
||||
t=1;
|
||||
if (type_sol==CTG_DEATH)
|
||||
return distance+1;
|
||||
type_sol = worldGetCellCategory(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;
|
||||
|
||||
static int jump_buffering=0;
|
||||
static int coyote_time=5;
|
||||
|
||||
void resetMarioJump()
|
||||
{
|
||||
jump_buffering=0;
|
||||
coyote_time=5;
|
||||
void marioResetJump()
|
||||
{ // disables jump buffering & coyote time until the next time mario hits the ground
|
||||
jump_input = 0;
|
||||
}
|
||||
|
||||
int global_quit=0;
|
||||
void marioMove()
|
||||
{
|
||||
id_frame++;
|
||||
{ // Mario star mode & immunity counters
|
||||
if (mario.starMode==200) mario.starMode=0;
|
||||
else if (mario.starMode) mario.starMode++;
|
||||
|
||||
if (mario_starMode==200) mario_starMode=0;
|
||||
else if (mario_starMode) mario_starMode++;
|
||||
|
||||
if (mario_immunity==60) mario_immunity=0;
|
||||
else if (mario_immunity) mario_immunity++;
|
||||
|
||||
if (mario_has_bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
|
||||
|
||||
if (MKB_getKeyState(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9);
|
||||
else boxJump(&mario.p, 8);
|
||||
|
||||
if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2 && coyote_time<4) // n'a pas sauté alors que la touche était enfoncée et coyote time =4 frames = 0.2 sec
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=6) mario.p.vy=9;
|
||||
else mario.p.vy=8;
|
||||
}
|
||||
// n'a pas sauté alors que la touche était enfoncée
|
||||
else if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2) jump_buffering=5; // Jump buffering during 5-1 frames = 0.2 sec
|
||||
if (mario.immunity==60) mario.immunity=0;
|
||||
else if (mario.immunity) mario.immunity++;
|
||||
}
|
||||
|
||||
if (jump_buffering) jump_buffering--;
|
||||
if (mario.bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
|
||||
|
||||
for (int i=0; i<mario.p.w; i++)
|
||||
{
|
||||
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
|
||||
{ // Jump (with coyote time & jump buffering)
|
||||
bool jump=0; // will he jump ?
|
||||
|
||||
// coyote time
|
||||
for (int i = 0; i < mario.p.w; i++) if (worldGetCellCategory(mario.p.x + i, mario.p.y - 1)==CTG_SOIL)
|
||||
{
|
||||
coyote_time=0;
|
||||
if (jump_input>0) jump=1;
|
||||
else jump_input=-COYOTE_INTERVAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
coyote_time++;
|
||||
|
||||
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
|
||||
|
||||
int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows)
|
||||
|
||||
int c1=worldGetCellCategory(mario.p.x, mario.p.y-1/*+mario.p.h*/);
|
||||
int c2=worldGetCellCategory(mario.p.x+mario.p.w-1, mario.p.y-1/*+mario.p.h*/);
|
||||
|
||||
mario_timeAccel=1-mario_timeAccel;
|
||||
if (vx==-sgn(mario.p.vx)) mario_timeAccel=1;
|
||||
if (mario_timeAccel)
|
||||
{
|
||||
if (vx)
|
||||
// jump buffering
|
||||
if (MKB_getKeyState(MK_JUMP)==2)
|
||||
{
|
||||
// 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);
|
||||
if (jump_input<0) jump = 1; // break the rules
|
||||
else jump_input = 1;
|
||||
}
|
||||
else mario.p.vx-=sgn(mario.p.vx);
|
||||
}
|
||||
|
||||
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 (jump_input) jump_input++;
|
||||
if (jump_input==COYOTE_INTERVAL+1) jump_input=0;
|
||||
|
||||
if (mario.p.x+mario.p.vx<cameraX(mario.p.x))
|
||||
{
|
||||
mario.p.vx=0;
|
||||
mario.p.x=cameraX(mario.p.x);
|
||||
}
|
||||
//teleporteurs_check();
|
||||
boxMove(&mario.p); // <-> + gravity
|
||||
|
||||
if (mario.p.y<0)
|
||||
mario_dead=1;
|
||||
if (mario.p.vx==0)
|
||||
mario_timeAccel=0;
|
||||
|
||||
// coins
|
||||
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_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);
|
||||
}
|
||||
if (e2->type==END_LEVEL)
|
||||
{
|
||||
finish_level=1;
|
||||
scoreAdd(400*e2->bonus);
|
||||
}
|
||||
|
||||
|
||||
//if ((mario.p.x+mario.p.w/2)/8==(mario.p.x+mario.p.w/2-1)/8)
|
||||
//{
|
||||
gift_t* t=(gift_t*)worldGetCell((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 (jump)
|
||||
{
|
||||
if (c->content==0 || c->number)
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (e2->type==END_LEVEL)
|
||||
{
|
||||
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--;
|
||||
coinAdd();
|
||||
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--;
|
||||
bonusSet(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--;
|
||||
bonusSet(BONUS_1UP,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
||||
}
|
||||
else if (c->content==4 && c->number)
|
||||
{
|
||||
c->number--;
|
||||
bonusSet(BONUS_STAR,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
||||
}
|
||||
else if (c->content==0 && mario.size==M_BIG && c->type==BRICK)
|
||||
{
|
||||
c->state=1;
|
||||
mario.p.vy=0;
|
||||
}
|
||||
c->hidden=0;
|
||||
else if (c->content==0 && c->type==BRICK) c->time_hit_id=1;
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
66
src/score.c
|
@ -6,6 +6,9 @@
|
|||
#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;
|
||||
|
||||
|
@ -16,7 +19,7 @@ static int pieces=0;
|
|||
static unsigned int time_last_piece=0;
|
||||
|
||||
unsigned int time_id=0;
|
||||
int time_left=0;
|
||||
static int time_left=0;
|
||||
int time_spent=0;
|
||||
|
||||
int finish_level=0;
|
||||
|
@ -30,7 +33,7 @@ void gameNew()
|
|||
combo=0;
|
||||
combo_id=-10;
|
||||
marioSmaller();
|
||||
mario_immunity=0;
|
||||
mario.immunity=0;
|
||||
levelNew();
|
||||
time_spent=0;
|
||||
}
|
||||
|
@ -69,8 +72,7 @@ void coinAdd()
|
|||
|
||||
void scoreAdd(int i)
|
||||
{
|
||||
if (i==0)
|
||||
return;
|
||||
if (i==0) return;
|
||||
if (time_id-combo_id<=12 && combo)
|
||||
{
|
||||
score+=i;
|
||||
|
@ -90,55 +92,49 @@ void scoreDisplay()
|
|||
|
||||
char str[10];
|
||||
|
||||
if (time_id-combo_id<=8 && combo) // displays score & combo only when there is a 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;
|
||||
}
|
||||
else combo=0; // combo too old
|
||||
|
||||
if (time_last_piece<=time_id && time_id<=time_last_piece+30) // display pieces only when 1 is taken during 2 seconds
|
||||
if (time_last_piece<=time_id && time_id<=time_last_piece+DISPLAY_TIME) // display pieces only when 1 is taken during 2 seconds
|
||||
{
|
||||
sprintf(str, "c*%d", pieces);
|
||||
dtext(50,0,str, C_BLACK, C_WHITE);
|
||||
}
|
||||
|
||||
time_id++;
|
||||
if (time_id%8==0)
|
||||
if ((mario.dead|finish_level)==0)
|
||||
{
|
||||
time_left--;
|
||||
time_spent++;
|
||||
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(127-6*i, 1, str, C_BLACK, C_WHITE);
|
||||
extern image_t img_time_over;
|
||||
if (time_left==0)
|
||||
{
|
||||
dimage(0,0, &img_time_over);
|
||||
dupdate();
|
||||
sleep_ms(3,1000);
|
||||
sleep_ms(3,1000);
|
||||
sleep_ms(3,1000);
|
||||
finish_level=2;
|
||||
}
|
||||
int i=0; while (str[i]) i++;
|
||||
dtext(128-6*i, 1, str, C_BLACK, C_WHITE);
|
||||
}
|
||||
|
||||
int getTimeSpent()
|
||||
{
|
||||
return time_spent;
|
||||
}
|
||||
int getTimeSpent(void) { return time_spent; }
|
||||
|
||||
|
||||
|
||||
int lifesGet() { return lifes; }
|
||||
int lifesGet(void) { return lifes; }
|
||||
|
||||
void lifesSet(int l) { lifes = l; }
|
||||
|
||||
|
|
|
@ -22,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;
|
||||
|
@ -46,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};
|
||||
|
|
19
src/tuyau.c
|
@ -6,6 +6,7 @@
|
|||
#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
|
||||
|
@ -51,10 +52,26 @@ void teleportersActive()
|
|||
}
|
||||
/* End of animated section */
|
||||
|
||||
resetMarioJump();
|
||||
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); worldDraw(0,0); dupdate();
|
||||
waitNextFrame(); waitNextFrame();
|
||||
mario.p.y++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
245
src/world.c
|
@ -1,19 +1,21 @@
|
|||
#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>
|
||||
|
||||
|
@ -43,129 +45,106 @@ void cellDraw(int cx, int cy, int sx, int sy, int plan)
|
|||
const cell_t * cell=worldGetCell(cx,cy);
|
||||
if (cell==0)
|
||||
return;
|
||||
if (plan==1)
|
||||
if (plan==1) switch (cell->type)
|
||||
{
|
||||
if (cell->type==TUYAU)
|
||||
{
|
||||
tuyau_t* i=(tuyau_t*)cell;
|
||||
tileDraw(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==ARBRE)
|
||||
{
|
||||
arbre_t* i=(arbre_t*)cell;
|
||||
tileDraw(sx, sy, &arbre, i->x, i->y);
|
||||
}
|
||||
case ARBRE:
|
||||
tileDraw(sx, sy, &arbre, ((arbre_t*)cell)->x, ((arbre_t*)cell)->y);
|
||||
break;
|
||||
|
||||
case EARTH:
|
||||
tileDraw(sx, sy, &earth, ((earth_t*)cell)->x, ((earth_t*)cell)->y);
|
||||
break;
|
||||
|
||||
if (cell->type==EARTH)
|
||||
{
|
||||
earth_t* i=(earth_t*)cell;
|
||||
tileDraw(sx, sy, &earth, i->x, i->y);
|
||||
}
|
||||
if (cell->type==BLOC)
|
||||
{
|
||||
tileDraw(sx, sy, &bloc, 0, 0);
|
||||
}
|
||||
case BLOC:
|
||||
tileDraw(sx, sy, &bloc, 0, 0);
|
||||
break;
|
||||
|
||||
if (cell->type==BLOC)
|
||||
{
|
||||
tileDraw(sx, sy, &bloc, 0, 0);
|
||||
}
|
||||
case SPIKES:
|
||||
tileDraw(sx, sy, &spikes, 0, 0);
|
||||
break;
|
||||
|
||||
if (cell->type==BRICK)
|
||||
case BRICK:
|
||||
if (((brick_t*)cell)->time_hit_id) // calculate collision animation
|
||||
{
|
||||
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)
|
||||
tileDraw(sx, sy, &brick, 0, i->state);
|
||||
else
|
||||
tileDraw(sx, sy, &gift, 1, 0);
|
||||
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
|
||||
tileDraw(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;
|
||||
|
||||
if (cell->type==GIFT)
|
||||
case GIFT:
|
||||
if (((gift_t*)cell)->time_hit_id)
|
||||
{
|
||||
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)
|
||||
tileDraw(sx, sy, &gift, 0, 0);
|
||||
else
|
||||
tileDraw(sx, sy, &gift, 1, 0);
|
||||
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
|
||||
tileDraw(sx, sy+8, &coin, 0, 0);
|
||||
}
|
||||
((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;
|
||||
tileDraw(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)
|
||||
tileDraw(sx, sy, &buisson, i->x, i->y);
|
||||
if (i->type==NUAGE)
|
||||
tileDraw(sx, sy, &nuage, i->x, i->y);
|
||||
if (i->type==COLLINE)
|
||||
tileDraw(sx, sy, &colline, i->x, i->y);
|
||||
if (i->type==CASTLE)
|
||||
tileDraw(sx, sy, &castle, i->x, i->y);
|
||||
if (i->type==END_LEVEL)
|
||||
tileDraw(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 worldGetCellCategory(int x, int y)
|
||||
{
|
||||
cell_t *c=worldGetCell(x,y);
|
||||
if (c==0)
|
||||
{
|
||||
return CTG_DEATH;
|
||||
}
|
||||
if (platformsCollisionTest(x,y))
|
||||
return CTG_SOIL;
|
||||
if (c->type==ARBRE)
|
||||
{
|
||||
arbre_t* a=(arbre_t*)c;
|
||||
if (a->x==1&&a->y==1)
|
||||
return CTG_EMPTY;
|
||||
}
|
||||
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:
|
||||
case ARBRE:
|
||||
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;
|
||||
}
|
||||
|
@ -173,19 +152,17 @@ int worldGetCellCategory(int x, int y)
|
|||
|
||||
void worldDraw()
|
||||
{
|
||||
cameraMove(0);
|
||||
//cameraAdjust();
|
||||
int mx0=cameraX();
|
||||
int my0=cameraY();
|
||||
int sx0=mx0%8;
|
||||
int sy0=my0%8;
|
||||
cameraMove();
|
||||
|
||||
const int mx0=cameraX(), my0=cameraY();
|
||||
const int sx0=mx0%8, sy0=my0%8;
|
||||
|
||||
//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();
|
||||
|
@ -193,18 +170,16 @@ void worldDraw()
|
|||
//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
|
||||
if (mario_immunity) drect(0,64-MARIO_IMMUNITY_TIME+mario_immunity,2,64, C_BLACK);
|
||||
// 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void worldMove()
|
||||
{
|
||||
MKB_update();
|
||||
for (int i=0; i<ennemis_global_size; i++)
|
||||
{
|
||||
ennemiMove(&ennemis_global[i]);
|
||||
}
|
||||
for (int i=0; i<ennemiesNumber(); i++) ennemiMove(&ennemis_global[i]);
|
||||
bonusMove();
|
||||
bulletsMove();
|
||||
platformsMove();
|
||||
|
@ -212,32 +187,30 @@ void worldMove()
|
|||
teleportersActive();
|
||||
}
|
||||
|
||||
void worldSet(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)
|
||||
{
|
||||
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;
|
||||
|
||||
// Calculates the new struct size
|
||||
int size= 4*sizeof(int) + sizeof(cell_t)*w*h;
|
||||
if (0==w*h) return;
|
||||
|
||||
// Copy map into ram
|
||||
map_current=(map_t*)mallocProf(size); if (map_current==0) mallocError();
|
||||
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);
|
||||
}
|
||||
|
|