Compare commits
23 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 |
|
@ -1,2 +1,4 @@
|
|||
build-fx/*
|
||||
build-cg/*
|
||||
build-cg/*
|
||||
INIT/CasioRAM.mem
|
||||
SuperCbr.dlw
|
||||
|
|
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,15 +1,9 @@
|
|||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
|
||||
#define TILE_W 8
|
||||
#define TILE_H 8
|
||||
|
||||
#define SCREEN_W 128
|
||||
#define SCREEN_H 64
|
||||
|
||||
#include <stdbool.h>
|
||||
//extern bool dark_theme_enable;
|
||||
//extern bool is_in_water;
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
|
|
@ -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,10 +21,11 @@
|
|||
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;
|
||||
|
@ -37,12 +38,6 @@ void marioSmaller();
|
|||
|
||||
extern int global_quit;
|
||||
extern int numero_frame;
|
||||
extern int mario_xMax;
|
||||
extern int mario_dead;
|
||||
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,
|
||||
|
|
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);
|
||||
}
|
||||
|
|
26
src/box.c
|
@ -7,7 +7,7 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -151,23 +151,21 @@ void boxMove(box_t * b)
|
|||
move_y(b);
|
||||
}
|
||||
|
||||
void boxJump(box_t * b, int height)
|
||||
void boxJump(box_t * b, int height, bool floor_needed)
|
||||
{
|
||||
int sgn_vy=-1*sgn(height);
|
||||
if (!floor_needed)
|
||||
{
|
||||
b->vy=height;
|
||||
return;
|
||||
}
|
||||
|
||||
const int sgn_vy=-1*sgn(height);
|
||||
if (sgn_vy)
|
||||
{
|
||||
int sol=0, eau=0;
|
||||
for (int j=0; j<b->w; j++)
|
||||
for (int j = 0; j < b->w; j++) if (worldGetCellCategory( b->x + j, b->y + sgn_vy) == CTG_SOIL)
|
||||
{
|
||||
int typetemp=worldGetCellCategory(b->x+j ,b->y+sgn_vy);
|
||||
if (typetemp==CTG_SOIL)
|
||||
sol++;
|
||||
if (typetemp==CTG_WATER)
|
||||
eau++;
|
||||
b->vy=height;
|
||||
return;
|
||||
}
|
||||
if (sol)
|
||||
b->vy=height;
|
||||
else if (eau)
|
||||
b->vy+=height/2;
|
||||
}
|
||||
}
|
||||
|
|
15
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;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ void bulletsMove()
|
|||
{
|
||||
for (int i=0; i<2; i++) if (bullets[i].type) // bullet active
|
||||
{
|
||||
boxJump(&bullets[i].b,4);
|
||||
boxJump( &bullets[i].b, 4, true);
|
||||
boxMove(&bullets[i].b);
|
||||
|
||||
if (bullets[i].b.vx==0) bullets[i].type=0; // delete a bullet if it is stopped
|
||||
|
@ -52,7 +53,7 @@ void bulletsMove()
|
|||
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<ennemis_global_size; a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
|
||||
for (int a=0; a<ennemiesNumber(); a++) if (ennemis_global[a].type!=NONE && boxContact(&bullets[i].b, &ennemis_global[a].b))
|
||||
{
|
||||
ennemis_global[a].life=DEAD;
|
||||
bullets[i].type=0;
|
||||
|
|
26
src/camera.c
|
@ -16,13 +16,13 @@ int cameraY() {return max(max(y-32,0)-delta_y,0);}
|
|||
|
||||
void cameraMove() // only vertical movement
|
||||
{
|
||||
if (MKB_getKeyState(MK_UP) && abs(delta_y)<24) delta_y-=4;
|
||||
if (MKB_getKeyState(MK_DOWN) && abs(delta_y)<24) delta_y+=4;
|
||||
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);
|
||||
|
||||
static int camera_vy=0;
|
||||
if (mario.p.y==last_vy) // mario arrêté
|
||||
immobile++;
|
||||
if (mario.p.y==last_vy) immobile++;
|
||||
else
|
||||
{
|
||||
last_vy=mario.p.y;
|
||||
|
@ -30,26 +30,20 @@ void cameraMove() // only vertical movement
|
|||
}
|
||||
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)
|
||||
{
|
||||
|
|
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;
|
||||
|
|
19
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)
|
||||
{
|
||||
|
@ -334,7 +341,7 @@ static void unpackLevel(packed_level_t * p)
|
|||
//freeProf(c);
|
||||
|
||||
|
||||
EnnemiesInit(ennemis, nombre_ennemis);
|
||||
ennemiesInit(ennemis, nombre_ennemis);
|
||||
}
|
||||
|
||||
void setLevel(int w, int l)
|
||||
|
@ -342,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
|
||||
|
@ -384,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)
|
||||
|
|
|
@ -258,7 +258,7 @@ int PlayLevel(int w, int l)
|
|||
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)
|
||||
{
|
||||
|
@ -267,14 +267,13 @@ int PlayLevel(int w, int l)
|
|||
}
|
||||
cameraAdjust();
|
||||
bonusSet(0, 0, 0);
|
||||
|
||||
mario.last_vx_sgn=1;
|
||||
|
||||
|
||||
while(global_quit==0)
|
||||
{
|
||||
waitNextFrame();
|
||||
|
||||
time_id++;
|
||||
//marioMove();
|
||||
|
||||
worldMove();
|
||||
|
@ -283,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)
|
||||
{
|
||||
|
|
113
src/mario.c
|
@ -14,111 +14,92 @@
|
|||
pnj mario=
|
||||
{
|
||||
{26,17,6,8,0,0,0,1},
|
||||
M_SMALL,
|
||||
M_RIGHT1, M_WALK,
|
||||
0
|
||||
};
|
||||
|
||||
// if mario is able to throw fire bullets
|
||||
int mario_has_bullets=0;
|
||||
|
||||
// If mario is dead
|
||||
int mario_dead=0;
|
||||
|
||||
// Used to draw mario (mario direction)
|
||||
int last_vx_sign=1;
|
||||
|
||||
// After he becomes little
|
||||
int mario_immunity=0;
|
||||
|
||||
// Time during mario is invincible
|
||||
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.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+(time_id/4)%2, 0);
|
||||
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_small, 2*last_vx_sign+(time_id/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+(time_id/4)%2, mario_has_bullets);
|
||||
else if (abs(mario.p.vx)>=1) tileDraw(mx, my, &mario_big, 1+3*last_vx_sign+(time_id/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int jump_buffering=0;
|
||||
static int coyote_time=5;
|
||||
#define COYOTE_INTERVAL 3
|
||||
static int jump_input=0;
|
||||
|
||||
void marioResetJump()
|
||||
{ // disables jump buffering & coyote time until the next time mario hits the ground
|
||||
jump_buffering=0;
|
||||
coyote_time=5;
|
||||
jump_input = 0;
|
||||
}
|
||||
|
||||
int global_quit=0;
|
||||
void marioMove()
|
||||
{
|
||||
{ // 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.immunity==60) mario.immunity=0;
|
||||
else if (mario.immunity) mario.immunity++;
|
||||
}
|
||||
|
||||
if (mario_has_bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
|
||||
if (mario.bullets==1 && MKB_getKeyState(MK_RUN)==2) bulletThrow();
|
||||
|
||||
{ // Jump (with coyote time & jump buffering)
|
||||
if (MKB_getKeyState(MK_JUMP)==2 || jump_buffering) //|| keys[MK_JUMP2]==2)
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=6) boxJump(&mario.p, 9);
|
||||
else boxJump(&mario.p, 8);
|
||||
bool jump=0; // will he jump ?
|
||||
|
||||
if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2 && coyote_time<4) // n'a pas sauté alors que la touche était enfoncée et coyote time =4 frames = 0.2 sec
|
||||
{
|
||||
if (mario.p.vx*sgn(mario.p.vx)>=6) mario.p.vy=9;
|
||||
else mario.p.vy=8;
|
||||
}
|
||||
// n'a pas sauté alors que la touche était enfoncée
|
||||
else if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2) jump_buffering=5; // Jump buffering during 5-1 frames = 0.2 sec
|
||||
// coyote time
|
||||
for (int i = 0; i < mario.p.w; i++) if (worldGetCellCategory(mario.p.x + i, mario.p.y - 1)==CTG_SOIL)
|
||||
{
|
||||
if (jump_input>0) jump=1;
|
||||
else jump_input=-COYOTE_INTERVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (jump_buffering) jump_buffering--;
|
||||
|
||||
for (int i=0; i<mario.p.w; i++)
|
||||
// jump buffering
|
||||
if (MKB_getKeyState(MK_JUMP)==2)
|
||||
{
|
||||
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
|
||||
{
|
||||
coyote_time=0;
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
coyote_time++;
|
||||
|
||||
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
|
||||
}
|
||||
|
@ -148,8 +129,8 @@ void marioMove()
|
|||
}
|
||||
|
||||
{ // last vx sign determination
|
||||
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 (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
|
||||
|
@ -161,7 +142,7 @@ void marioMove()
|
|||
|
||||
boxMove(&mario.p); // apply gravity
|
||||
|
||||
if (mario.p.y<0) mario_dead=1; // die if out of the map
|
||||
if (mario.p.y<0) mario.dead=1; // die if out of the map
|
||||
|
||||
{// take coins that mario touchs
|
||||
coin_t* c;
|
||||
|
@ -214,7 +195,11 @@ void marioMove()
|
|||
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==0 && mario.size==M_BIG && c->type==BRICK) c->state=c->time_hit_id=1;
|
||||
else if (c->content==0 && mario.p.h==M_BIG && c->type==BRICK)
|
||||
{
|
||||
c->state=c->time_hit_id=1;
|
||||
mario.p.vy=3;
|
||||
}
|
||||
else if (c->content==0 && c->type==BRICK) c->time_hit_id=1;
|
||||
}
|
||||
}
|
||||
|
|
69
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,54 +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);
|
||||
}
|
||||
|
||||
if (time_id%8==0)
|
||||
{
|
||||
time_left--;
|
||||
time_spent++;
|
||||
}
|
||||
|
||||
if ((mario.dead|finish_level)==0)
|
||||
{
|
||||
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};
|
||||
|
|
17
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
|
||||
|
@ -55,6 +56,22 @@ void teleportersActive()
|
|||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
18
src/world.c
|
@ -7,8 +7,6 @@
|
|||
#include <camera.h>
|
||||
|
||||
#include <mario.h>
|
||||
#include <ennemi.h>
|
||||
|
||||
#include <bonus.h>
|
||||
#include <ennemi.h>
|
||||
#include <plateforme.h>
|
||||
|
@ -65,6 +63,10 @@ void cellDraw(int cx, int cy, int sx, int sy, int plan)
|
|||
tileDraw(sx, sy, &bloc, 0, 0);
|
||||
break;
|
||||
|
||||
case SPIKES:
|
||||
tileDraw(sx, sy, &spikes, 0, 0);
|
||||
break;
|
||||
|
||||
case BRICK:
|
||||
if (((brick_t*)cell)->time_hit_id) // calculate collision animation
|
||||
{
|
||||
|
@ -136,7 +138,11 @@ int worldGetCellCategory(int x, int y)
|
|||
|
||||
switch (c->type)
|
||||
{
|
||||
case TUYAU: case GIFT: case BRICK: case EARTH: case BLOC: case ARBRE:
|
||||
case BRICK:
|
||||
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:
|
||||
|
@ -165,13 +171,15 @@ void worldDraw()
|
|||
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);
|
||||
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();
|
||||
|
|