Compare commits
15 Commits
7138dd442c
...
6a744b0547
Author | SHA1 | Date |
---|---|---|
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 |
Binary file not shown.
12
SuperCbr.dlw
12
SuperCbr.dlw
|
@ -2,7 +2,7 @@
|
|||
|
||||
[_1]
|
||||
Type=5
|
||||
Order=0
|
||||
Order=1
|
||||
Top=15
|
||||
Left=2235
|
||||
Height=4740
|
||||
|
@ -13,11 +13,11 @@ OptionA=0
|
|||
|
||||
[_2]
|
||||
Type=1
|
||||
Order=1
|
||||
Order=0
|
||||
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
BIN
SuperCbr.g1a
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 651 B |
|
@ -12,6 +12,4 @@
|
|||
//extern bool dark_theme_enable;
|
||||
//extern bool is_in_water;
|
||||
|
||||
extern int frame_id;
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
|
|
@ -1,25 +1,30 @@
|
|||
#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 PLANTE(x,y) {PLANTE_ID,{x,y,ennemi_widths[PLANTE_ID],ennemi_heights[PLANTE_ID],0,0,0,0},ALIVE,0,0}
|
||||
|
||||
#define DEAD 0
|
||||
|
||||
// Dimensions pr les boites
|
||||
|
||||
|
@ -41,6 +46,6 @@ void ennemiesDisplay();
|
|||
|
||||
void ennemiMove(ennemi_t *e);
|
||||
|
||||
void EnnemiesInit(ennemi_t * table, int s);
|
||||
void ennemiesInit(ennemi_t * table, int s);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,15 +30,8 @@ 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();
|
||||
|
||||
|
@ -46,7 +39,6 @@ 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;
|
||||
|
|
|
@ -115,7 +115,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 +134,7 @@ typedef struct
|
|||
int h;
|
||||
int start_x;
|
||||
int start_y;
|
||||
cell_t data[];
|
||||
cell_t* data;
|
||||
}map_t;
|
||||
|
||||
extern map_t * map_current;
|
||||
|
|
61
src/box.c
61
src/box.c
|
@ -13,11 +13,7 @@ int check_collision(box_t *b)
|
|||
|
||||
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;
|
||||
|
|
53
src/bullet.c
53
src/bullet.c
|
@ -25,9 +25,9 @@ void bulletThrow()
|
|||
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
|
||||
bullets[i].b.vx=-9; //speed = 9
|
||||
else
|
||||
bullets[i].b.vx=9;
|
||||
bullets[i].b.vx=9;
|
||||
bullets[i].b.vy=0;
|
||||
bullets[i].p1=last_vx_sign;
|
||||
return;
|
||||
|
@ -37,43 +37,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);
|
||||
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<ennemis_global_size; 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
44
src/camera.c
44
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;
|
||||
}
|
||||
*/
|
||||
if (MKB_getKeyState(MK_UP) && abs(delta_y)<24) delta_y-=4;
|
||||
if (MKB_getKeyState(MK_DOWN) && abs(delta_y)<24) 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++;
|
||||
immobile++;
|
||||
else
|
||||
{
|
||||
last_vy=mario.p.y;
|
||||
|
@ -53,13 +43,13 @@ void cameraMove() // movement vertical seulement
|
|||
|
||||
//décéleration après avoir parvouru la moitié de la distance, sinon acceleration
|
||||
if (camera_vy*(camera_vy+1)>distance)
|
||||
camera_vy--;
|
||||
camera_vy--;
|
||||
else
|
||||
camera_vy++;
|
||||
camera_vy++;
|
||||
//y++;
|
||||
|
||||
if (camera_vy<0)
|
||||
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 +57,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
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
205
src/ennemi.c
205
src/ennemi.c
|
@ -8,15 +8,17 @@
|
|||
#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};
|
||||
const int ennemi_widths [NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8 , 8, 8};
|
||||
//const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 12, 9, 12, 9, 8};
|
||||
const int ennemi_heights[NOMBRE_ENNEMIS] = {0, 8, 8, 8, 8, 8, 8};
|
||||
|
||||
void ennemiDisplay(ennemi_t * e)
|
||||
{
|
||||
if (e->life==0)
|
||||
if (e->life==0 && e->type!=NONE)
|
||||
{
|
||||
if (e->p1==0)
|
||||
{
|
||||
|
@ -27,84 +29,100 @@ void ennemiDisplay(ennemi_t * e)
|
|||
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==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
|
||||
else e->discovered=1; // for security, tag as discover all drawed ennemies
|
||||
|
||||
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);
|
||||
}
|
||||
{// 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;
|
||||
// TODO tx ty tsx,tsy
|
||||
}
|
||||
}
|
||||
tileDraw(e->b.x-cameraX(0)+dsx, e->b.y-cameraY(mario.p.y)+dsy, &t, tx, ty);
|
||||
}
|
||||
}
|
||||
|
||||
bool ennemi_check_collision(ennemi_t *e) { return (boxContact(&e->b, &mario.p)); }
|
||||
|
||||
void hurtMario()
|
||||
{ if (mario.size==M_SMALL && mario_immunity==0)
|
||||
{
|
||||
if (mario.size==M_SMALL && mario_immunity==0)
|
||||
{mario_dead=1;finish_level=0;}
|
||||
else
|
||||
marioSmaller();
|
||||
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)
|
||||
{
|
||||
e->life=DEAD;
|
||||
e->p1=0;
|
||||
scoreAdd(200);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,7 +152,7 @@ void ennemiMove(ennemi_t *e)
|
|||
{
|
||||
t->life=DEAD;
|
||||
t->p1=0;
|
||||
scoreAdd(200);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +169,7 @@ void ennemiMove(ennemi_t *e)
|
|||
{
|
||||
e->life=DEAD;
|
||||
e->p1=0;
|
||||
scoreAdd(100);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -177,19 +195,19 @@ void ennemiMove(ennemi_t *e)
|
|||
}
|
||||
}
|
||||
if (e->b.y<0)
|
||||
e->type=NONE;
|
||||
e->type=NONE;
|
||||
if (e_hitMario)
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
{
|
||||
e->life=DEAD;
|
||||
e->p1=0;
|
||||
scoreAdd(200);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[GOOMBA_ID]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
hurtMario();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -211,7 +229,7 @@ void ennemiMove(ennemi_t *e)
|
|||
}
|
||||
}
|
||||
if (e->b.y<0)
|
||||
e->type=NONE;
|
||||
e->type=NONE;
|
||||
if (e_hitMario)
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
|
@ -220,12 +238,12 @@ void ennemiMove(ennemi_t *e)
|
|||
e->b.h=ennemi_heights[CARAPACE_VERTE];
|
||||
e->p1=2;
|
||||
e->b.vx=0;
|
||||
scoreAdd(200);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
hurtMario();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -250,7 +268,7 @@ void ennemiMove(ennemi_t *e)
|
|||
{ // demi tour automatique
|
||||
int s=-1;
|
||||
if (e->b.vx>0)
|
||||
s=e->b.w;
|
||||
s=e->b.w;
|
||||
|
||||
if (worldGetCellCategory(e->b.x+s, e->b.y-1)==CTG_EMPTY && sgn(e->b.vx)==sgn(s))
|
||||
{
|
||||
|
@ -261,7 +279,7 @@ void ennemiMove(ennemi_t *e)
|
|||
|
||||
|
||||
if (e->b.y<0)
|
||||
e->type=NONE;
|
||||
e->type=NONE;
|
||||
if (e_hitMario)
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
|
@ -270,12 +288,12 @@ void ennemiMove(ennemi_t *e)
|
|||
e->b.h=ennemi_heights[CARAPACE_ROUGE];
|
||||
e->p1=2;
|
||||
e->b.vx=0;
|
||||
scoreAdd(200);
|
||||
scoreAdd(KILL_ENNEMI);
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[CARAPACE_ROUGE]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
hurtMario();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -290,20 +308,15 @@ void ennemiMove(ennemi_t *e)
|
|||
e->b.vx=6*e->p1;
|
||||
}
|
||||
}
|
||||
if (e->b.y<0)
|
||||
e->type=NONE;
|
||||
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;
|
||||
{ // 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,9 +325,9 @@ void ennemiMove(ennemi_t *e)
|
|||
if (e->p1==0 || e->p1>=2)
|
||||
{
|
||||
if (mario.p.x>=e->b.x)
|
||||
e->p1=-1;
|
||||
e->p1=-1;
|
||||
if (mario.p.x<=e->b.x)
|
||||
e->p1=1;
|
||||
e->p1=1;
|
||||
e->b.vx=6*e->p1;
|
||||
if (mario_fatal_hit)
|
||||
{
|
||||
|
@ -322,24 +335,20 @@ void ennemiMove(ennemi_t *e)
|
|||
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 bounce
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mario_fatal_hit)
|
||||
{
|
||||
e->p1=0;
|
||||
e->b.vx=0;
|
||||
e->p1=e->b.vx=0;
|
||||
mario.p.vy=4;
|
||||
mario.p.y=e->b.y+ennemi_heights[CARAPACE_VERTE]+1;
|
||||
}
|
||||
else
|
||||
hurtMario();
|
||||
else hurtMario();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -349,34 +358,24 @@ void ennemiMove(ennemi_t *e)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Global variables for ennemies
|
||||
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]);
|
||||
}
|
||||
for (int i=0; i<ennemis_global_size; i++) ennemiDisplay(&ennemis_global[i]);
|
||||
}
|
||||
|
||||
|
||||
void EnnemiesInit(ennemi_t * table, int s)
|
||||
void ennemiesInit(ennemi_t * table, int s)
|
||||
{
|
||||
ennemis_global_size=0;
|
||||
if (ennemis_global)
|
||||
{
|
||||
freeProf(ennemis_global);
|
||||
ennemis_global=0;
|
||||
}
|
||||
if (0==s)
|
||||
return;
|
||||
ennemis_global_size=ennemis_global=0;
|
||||
if (!s) return;
|
||||
int size=sizeof(ennemi_t)*s;
|
||||
ennemis_global=mallocProf(size);
|
||||
if (ennemis_global==0)
|
||||
mallocError();
|
||||
if ((ennemis_global=mallocProf(size))==0) mallocError();
|
||||
ennemis_global_size=s;
|
||||
memcpy(ennemis_global, table, size);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -329,10 +329,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 +342,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
|
||||
|
|
|
@ -252,13 +252,9 @@ void launchUI() // Main Menu
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int frame_id;
|
||||
|
||||
int PlayLevel(int w, int l)
|
||||
{
|
||||
time_id=0;
|
||||
initRefreshTimer();
|
||||
|
||||
//int finish_status=0; // FAil
|
||||
|
@ -278,7 +274,6 @@ int PlayLevel(int w, int l)
|
|||
{
|
||||
waitNextFrame();
|
||||
|
||||
frame_id++;
|
||||
//marioMove();
|
||||
|
||||
worldMove();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
282
src/mario.c
282
src/mario.c
|
@ -1,4 +1,5 @@
|
|||
#include "mario.h"
|
||||
#include <mario.h>
|
||||
|
||||
#include "tile.h"
|
||||
#include "world.h"
|
||||
#include <gint/display.h>
|
||||
|
@ -10,9 +11,6 @@
|
|||
#include <camera.h>
|
||||
#include <base.h>
|
||||
|
||||
|
||||
int id_frame=0;
|
||||
|
||||
pnj mario=
|
||||
{
|
||||
{26,17,6,8,0,0,0,1},
|
||||
|
@ -21,8 +19,10 @@ pnj mario=
|
|||
0
|
||||
};
|
||||
|
||||
// if mario is able to throw fire bullets
|
||||
int mario_has_bullets=0;
|
||||
static int mario_timeAccel=0;
|
||||
|
||||
// If mario is dead
|
||||
int mario_dead=0;
|
||||
|
||||
// Used to draw mario (mario direction)
|
||||
|
@ -31,7 +31,7 @@ int last_vx_sign=1;
|
|||
// After he becomes little
|
||||
int mario_immunity=0;
|
||||
|
||||
|
||||
// Time during mario is invincible
|
||||
int mario_starMode=0;
|
||||
|
||||
void marioBigger()
|
||||
|
@ -48,7 +48,6 @@ void marioSmaller()
|
|||
mario_has_bullets=0;
|
||||
if (mario_immunity==0)
|
||||
mario_immunity=1;
|
||||
//mario.p.vy=5;
|
||||
}
|
||||
|
||||
void marioDraw()
|
||||
|
@ -59,46 +58,24 @@ void marioDraw()
|
|||
const int my=mario.p.y-cameraY(mario.p.y);
|
||||
if (mario.size==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);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int jump_buffering=0;
|
||||
static int coyote_time=5;
|
||||
|
||||
void resetMarioJump()
|
||||
{
|
||||
void marioResetJump()
|
||||
{ // disables jump buffering & coyote time until the next time mario hits the ground
|
||||
jump_buffering=0;
|
||||
coyote_time=5;
|
||||
}
|
||||
|
@ -106,154 +83,139 @@ void resetMarioJump()
|
|||
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_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
|
||||
{ // 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) mario.p.vy=9;
|
||||
else mario.p.vy=8;
|
||||
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
|
||||
}
|
||||
// n'a pas sauté alors que la touche était enfoncée
|
||||
else if (mario.p.vy<=0 && MKB_getKeyState(MK_JUMP)==2) jump_buffering=5; // Jump buffering during 5-1 frames = 0.2 sec
|
||||
|
||||
if (jump_buffering) jump_buffering--;
|
||||
|
||||
for (int i=0; i<mario.p.w; i++)
|
||||
{
|
||||
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
|
||||
{
|
||||
coyote_time=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
coyote_time++;
|
||||
|
||||
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
|
||||
}
|
||||
|
||||
if (jump_buffering) jump_buffering--;
|
||||
|
||||
for (int i=0; i<mario.p.w; i++)
|
||||
{
|
||||
if (worldGetCellCategory(mario.p.x+i, mario.p.y-1)==CTG_SOIL)
|
||||
{ // 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)
|
||||
{
|
||||
coyote_time=0;
|
||||
break;
|
||||
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)) last_vx_sign=1;
|
||||
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL)) last_vx_sign=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);
|
||||
}
|
||||
}
|
||||
coyote_time++;
|
||||
|
||||
if (mario.p.vy>=2 && MKB_getKeyState(MK_JUMP)==0) mario.p.vy-=2; // Custom jump height
|
||||
boxMove(&mario.p); // apply gravity
|
||||
|
||||
int vx=sgn(MKB_getKeyState(MK_RIGHT)-MKB_getKeyState(MK_LEFT)); // Mario wanted dir (arrows)
|
||||
if (mario.p.y<0) mario_dead=1; // die if out of the map
|
||||
|
||||
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*/);
|
||||
{// 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;}
|
||||
|
||||
mario_timeAccel=1-mario_timeAccel;
|
||||
if (vx==-sgn(mario.p.vx)) mario_timeAccel=1;
|
||||
if (mario_timeAccel)
|
||||
{
|
||||
if (vx)
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
finish_level=1;
|
||||
scoreAdd(400*e1->bonus);
|
||||
}
|
||||
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 (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 (e2->type==END_LEVEL)
|
||||
{
|
||||
if (c->content==0 || c->number)
|
||||
finish_level=1;
|
||||
scoreAdd(400*e2->bonus);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{// mario box auto hit
|
||||
gift_t* c=(gift_t*)worldGetCell((mario.p.x+mario.p.w/2),mario.p.y+mario.p.h);
|
||||
|
||||
if ((c->type==GIFT || c->type==BRICK) && (c->time_hit_id==0 && mario.p.last_vy>0))
|
||||
{
|
||||
c->hidden=0;
|
||||
mario.p.last_vy=0;
|
||||
if (c->number)
|
||||
{
|
||||
c->time_hit_id=1;
|
||||
mario.p.last_vy=0;
|
||||
}
|
||||
switch (c->content)
|
||||
{
|
||||
case 1: c->number--; coinAdd(); break;
|
||||
|
||||
if (c->content==1 && c->number)
|
||||
{
|
||||
c->number--;
|
||||
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)
|
||||
{
|
||||
c->number--;
|
||||
bonusSet(BONUS_CHAMPI,((mario.p.x+mario.p.w/2)/8)*8,mario.p.y+mario.p.h+8);
|
||||
}
|
||||
else if (c->content==3 && c->number)
|
||||
{
|
||||
c->number--;
|
||||
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 && mario.size==M_BIG && c->type==BRICK) c->state=c->time_hit_id=1;
|
||||
else if (c->content==0 && c->type==BRICK) c->time_hit_id=1;
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
64
src/score.c
64
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;
|
||||
|
@ -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; }
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ 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();
|
||||
|
|
235
src/world.c
235
src/world.c
|
@ -1,19 +1,23 @@
|
|||
#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 <ennemi.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 +47,98 @@ 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)
|
||||
case BRICK:
|
||||
if (((brick_t*)cell)->time_hit_id) // calculate collision animation
|
||||
{
|
||||
tileDraw(sx, sy, &bloc, 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==BRICK)
|
||||
case GIFT:
|
||||
if (((gift_t*)cell)->time_hit_id)
|
||||
{
|
||||
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);
|
||||
}
|
||||
((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 (cell->type==GIFT)
|
||||
if (((gift_t*)cell)->hidden==0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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:
|
||||
case TUYAU: case GIFT: case BRICK: case EARTH: case BLOC: case ARBRE:
|
||||
return CTG_SOIL;
|
||||
|
||||
default:
|
||||
return CTG_EMPTY;
|
||||
}
|
||||
|
@ -173,19 +146,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 +164,14 @@ 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
|
||||
// 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<ennemis_global_size; i++) ennemiMove(&ennemis_global[i]);
|
||||
bonusMove();
|
||||
bulletsMove();
|
||||
platformsMove();
|
||||
|
@ -212,32 +179,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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue