cleaned some parts of the code

dev
Milang 3 years ago
parent 17bd723f43
commit adccfcceb3
  1. BIN
      SuperCbr.g1a
  2. BIN
      build-fx/SuperCbr.bin
  3. BIN
      build-fx/SuperCbr.elf
  4. 1058
      build-fx/map
  5. 4
      build-fx/src/bonus.c.d
  6. BIN
      build-fx/src/bonus.c.o
  7. 5
      build-fx/src/box.c.d
  8. BIN
      build-fx/src/box.c.o
  9. 4
      build-fx/src/config.c.d
  10. BIN
      build-fx/src/config.c.o
  11. 4
      build-fx/src/ennemi.c.d
  12. BIN
      build-fx/src/ennemi.c.o
  13. BIN
      build-fx/src/keyboard.c.o
  14. BIN
      build-fx/src/level.c.o
  15. BIN
      build-fx/src/levelchanger.c.o
  16. 6
      build-fx/src/mario.c.d
  17. BIN
      build-fx/src/mario.c.o
  18. 4
      build-fx/src/plateforme.c.d
  19. BIN
      build-fx/src/plateforme.c.o
  20. BIN
      build-fx/src/score.c.o
  21. 5
      build-fx/src/tuyau.c.d
  22. BIN
      build-fx/src/tuyau.c.o
  23. 13
      build-fx/src/world.c.d
  24. BIN
      build-fx/src/world.c.o
  25. 28
      include/bonus.h
  26. 11
      include/box.h
  27. 2
      include/ennemi.h
  28. 41
      include/keyboard.h
  29. 11
      include/score.h
  30. 2
      include/world.h
  31. 115
      src/bonus.c
  32. 108
      src/box.c
  33. 9
      src/config.c
  34. 17
      src/ennemi.c
  35. 79
      src/keyboard.c
  36. 14
      src/level.c
  37. 27
      src/levelchanger.c
  38. 40
      src/mario.c
  39. 3
      src/plateforme.c
  40. 19
      src/score.c
  41. 8
      src/tuyau.c
  42. 57
      src/world.c

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
build-fx/src/bonus.c.o: src/bonus.c include/bonus.h include/box.h \
include/mario.h include/box.h include/world.h include/tile.h \
include/score.h include/ennemi.h include/constants.h
include/score.h include/ennemi.h include/constants.h include/base.h
include/bonus.h:
@ -19,3 +19,5 @@ include/score.h:
include/ennemi.h:
include/constants.h:
include/base.h:

Binary file not shown.

@ -1,5 +1,6 @@
build-fx/src/box.c.o: src/box.c include/box.h include/world.h \
include/ennemi.h include/box.h include/score.h include/constants.h
include/ennemi.h include/box.h include/score.h include/constants.h \
include/base.h
include/box.h:
@ -12,3 +13,5 @@ include/box.h:
include/score.h:
include/constants.h:
include/base.h:

Binary file not shown.

@ -1,3 +1,5 @@
build-fx/src/config.c.o: src/config.c include/config.h
build-fx/src/config.c.o: src/config.c include/config.h include/keyboard.h
include/config.h:
include/keyboard.h:

Binary file not shown.

@ -1,6 +1,6 @@
build-fx/src/ennemi.c.o: src/ennemi.c include/ennemi.h include/box.h \
include/mario.h include/box.h include/tile.h include/world.h \
include/score.h
include/score.h include/camera.h
include/ennemi.h:
@ -15,3 +15,5 @@ include/tile.h:
include/world.h:
include/score.h:
include/camera.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,6 +1,6 @@
build-fx/src/mario.c.o: src/mario.c include/mario.h include/box.h \
include/tile.h include/world.h include/keyboard.h include/box.h \
include/score.h include/bonus.h
include/score.h include/bonus.h include/bullets.h include/camera.h
include/mario.h:
@ -17,3 +17,7 @@ include/box.h:
include/score.h:
include/bonus.h:
include/bullets.h:
include/camera.h:

Binary file not shown.

@ -1,6 +1,6 @@
build-fx/src/plateforme.c.o: src/plateforme.c include/plateforme.h \
include/world.h include/mario.h include/box.h include/tile.h \
include/score.h
include/score.h include/camera.h
include/plateforme.h:
@ -13,3 +13,5 @@ include/box.h:
include/tile.h:
include/score.h:
include/camera.h:

Binary file not shown.

Binary file not shown.

@ -1,5 +1,6 @@
build-fx/src/tuyau.c.o: src/tuyau.c include/tuyau.h include/mario.h \
include/box.h include/keyboard.h include/world.h include/framerate.h
include/box.h include/keyboard.h include/world.h include/framerate.h \
include/camera.h
include/tuyau.h:
@ -12,3 +13,5 @@ include/keyboard.h:
include/world.h:
include/framerate.h:
include/camera.h:

Binary file not shown.

@ -1,6 +1,7 @@
build-fx/src/world.c.o: src/world.c include/world.h include/tile.h \
include/mario.h include/box.h include/ennemi.h include/bonus.h \
include/constants.h include/plateforme.h include/tuyau.h
include/box.h include/constants.h include/plateforme.h include/tuyau.h \
include/bullets.h include/keyboard.h include/base.h include/camera.h
include/world.h:
@ -14,8 +15,18 @@ include/ennemi.h:
include/bonus.h:
include/box.h:
include/constants.h:
include/plateforme.h:
include/tuyau.h:
include/bullets.h:
include/keyboard.h:
include/base.h:
include/camera.h:

Binary file not shown.

@ -1,18 +1,32 @@
// v0.3
#ifndef BONUS_H
#define BONUS_H
#define BONUS_NONE 0
#define BONUS_CHAMPI 1
#define BONUS_1UP 2
#define BONUS_STAR 3
#include <box.h>
// Bonus
// Come from boxes
void bonus_set(int type, int x, int y);
typedef enum
{
BONUS_NONE=0,
BONUS_CHAMPI,
BONUS_FLEUR,
BONUS_1UP,
BONUS_STAR
} bonus_id; // TODO add fragment
void lance_bullet();
void bullet_display();
typedef struct
{
int type;
box_t b;
int p1;
} bonus_t;
void bonus_set(bonus_id t, int x, int y);
void bonus_draw();
void bonus_move();
#endif

@ -1,6 +1,10 @@
// v0.3
#ifndef BOX_H
#define BOX_H
// Box type
// Used to simulate gravity and collides
typedef struct
{
int x :16;
@ -12,11 +16,12 @@ typedef struct
int vx :8;
int vy :8;
int last_vy :8;
int gravity :2;
int gravity :8;
//int is_mario;
} box_t;
int box_move(box_t * b);
int box_jump(box_t * b, int height); // hauteur du saut
void box_move(box_t * b);
void box_jump(box_t * b, int height);
#endif

@ -42,4 +42,6 @@ extern ennemi_t * ennemis_global;
extern int ennemis_global_size;
void display_ennemi_table();
void move_ennemi(ennemi_t *e);
#endif

@ -1,22 +1,39 @@
#ifndef KEYBOARD_CUSTOM_H
#define KEYBOARD_CUSTOM_H
// v0.3
#ifndef MARIO_KEYBOARD_H
#define MARIO_KEYBOARD_H
#define KONAMI
/* Reduced keyboard
It simulates a nes controller */
typedef enum
{
MK_NONE=-1,
MK_LEFT,
MK_LEFT=0,
MK_RIGHT,
MK_JUMP1,
MK_UP,
MK_RUN,
MK_LITTLE
} mkey_t;
extern mkey_t keys[6];
MK_DOWN,
MK_UP,
MK_JUMP, // Shift
MK_RUN // Alpha
} mkb_t;
/* This function has been coded to replace the following array
`extern mkey_t keys[6];`
It returns the specific key state
2=newly pressed
1=currently down
0=up
*/
int mkb_getstate(mkb_t const k);
void update_keyboard();
// Update the keyboard, should be called at each frame
void mkb_update();
void keyboard_clear();
// Reset followed keys' states
void mkb_clear();
int getkey_custom();
// Experimental getkey, designed to compensate for a strange bug introduced by original getkey
// /!\ return gint keycodes
int mkb_getkey();
#endif

@ -1,8 +1,10 @@
#ifndef SCORE
#define SCORE
#ifndef SCORE_H
#define SCORE_H
#define KILL_ENNEMI 105
//extern int score;
extern int lifes;
//extern int lifes;
extern int finish_level; // si ==-1, continue, si 0==retry, si ==1 ou + next
extern int time_id;
@ -14,6 +16,9 @@ void score_display();
void score_add_coin();
void new_level();
void new_game();
int lifes_get();
void lifes_lose();
void lifes_add();
int get_time_spent();

@ -105,7 +105,7 @@ void display_cell(int cx, int cy, int sx, int sy, int plan);
void world_set(world_t * w);
void world_draw(int x, int y);
void world_draw();
void world_move();
int world_get_real_x0();

@ -7,33 +7,14 @@
#include "ennemi.h"
#include "constants.h"
#include <stdbool.h>
#define BONUS_FLEUR 4 // interne, généré depuis champi
#define BULLET 1
typedef struct
{
int type;
box_t b;
int p1;
} bonus_t;
static int sgn(int x)
{
if (x>0)
return 1;
else if (x<0)
return -1;
else
return 0;
}
#include <base.h>
static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 0};
void bonus_set(int type, int x, int y)
void bonus_set(bonus_id t, int x, int y)
{
bonus.type=type;
if (mario.size==M_BIG && type==BONUS_CHAMPI)
bonus.type=t;
if (mario.size==M_BIG && t==BONUS_CHAMPI)
bonus.type=BONUS_FLEUR;
bonus.b.x=x;
bonus.b.y=y;
@ -44,8 +25,6 @@ void bonus_set(int type, int x, int y)
void bonus_move() //+collision
{
if (bonus.b.x<=world_get_real_x0()-bonus.b.w || bonus.b.x>=world_get_real_x0()+127)
bonus_set(BONUS_NONE,0,0);
if (bonus.type==BONUS_NONE)
return;
@ -94,7 +73,7 @@ void bonus_move() //+collision
{
bonus_set(BONUS_NONE,0,0);
score_add(1000);
lifes++;
lifes_add();
}
if (bonus.type==BONUS_STAR)
{
@ -111,87 +90,11 @@ void bonus_draw()
if (bonus.type==BONUS_NONE)
return;
if (bonus.type==BONUS_CHAMPI)
draw_tile(bonus.b.x-world_get_real_x0(), bonus.b.y-world_get_real_y0(mario.p.y), &champi, 0,0);
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &champi, 0,0);
if (bonus.type==BONUS_FLEUR)
draw_tile(bonus.b.x-world_get_real_x0(), bonus.b.y-world_get_real_y0(mario.p.y), &fleur, 0,0);
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &fleur, 0,0);
if (bonus.type==BONUS_1UP)
draw_tile(bonus.b.x-world_get_real_x0(), bonus.b.y-world_get_real_y0(mario.p.y), &life_1up, 0,0);
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &life_1up, 0,0);
if (bonus.type==BONUS_STAR)
draw_tile(bonus.b.x-world_get_real_x0(), bonus.b.y-world_get_real_y0(mario.p.y), &mario_starman, 0,0);
}
/* Les balles ont les memes propriétés que les boulets et sont donc gérées ici */
static bonus_t bullets[2] =
{
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0},
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0}
};
void lance_bullet()
{
for (int i=0; i<2; i++)
{
if (bullets[i].type==0)
{
bullets[i].type=BULLET;
bullets[i].b.x=mario.p.x;
bullets[i].b.y=mario.p.y+8;
if (last_vx_sign==0)
bullets[i].b.vx=-6;
else
bullets[i].b.vx=6;
bullets[i].b.vy=0;
bullets[i].p1=last_vx_sign;
return;
}
}
}
void bullet_display()
{
for (int i=0; i<2; i++)
{
if (bullets[i].type==BULLET)
draw_tile(bullets[i].b.x-world_get_real_x0(), bullets[i].b.y-world_get_real_y0(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
}
}
void bullet_move()
{
for (int i=0; i<2; i++)
{
if (bullets[i].type==BULLET)
{
box_jump(&bullets[i].b,4);
box_move(&bullets[i].b);
if (bullets[i].b.vx==0)
bullets[i].type=0;
if (bullets[i].b.y<0)
bullets[i].type=0;
if (bullets[i].b.x<=world_get_real_x0()-bullets[i].b.w || bullets[i].b.x>=world_get_real_x0()+127)
bullets[i].type=0;
for (int a=0; a<ennemis_global_size; a++)
{
ennemi_t* t=&ennemis_global[a];
if (t->discovered && t->type!=NONE)
{
bool x_collide= (bullets[i].b.x<=t->b.x && t->b.x<bullets[i].b.x+bullets[i].b.w) || (bullets[i].b.x<=t->b.x+t->b.w-1 && t->b.x+t->b.w<bullets[i].b.x+bullets[i].b.w);
bool y_collide= (bullets[i].b.y<=t->b.y && t->b.y<bullets[i].b.y+bullets[i].b.h) || (bullets[i].b.y<=t->b.y+t->b.h-1 && t->b.y+t->b.h<bullets[i].b.y+bullets[i].b.h);
if (x_collide&& y_collide)
{
t->life=DEAD;
bullets[i].type=0;
score_add(100);
break;
}
}
}
}
}
draw_tile(bonus.b.x-camera_x(), bonus.b.y-camera_y(), &mario_starman, 0,0);
}

@ -3,16 +3,7 @@
#include "ennemi.h"
#include "score.h"
#include <constants.h>
int sgn(int x)
{
if (x==0)
return 0;
else if (x>0)
return 1;
return -1;
}
#include <base.h>
int check_collision(box_t *b)
{
@ -49,25 +40,19 @@ static void move_x(box_t * b)
{
for (int i=sgn_vx; i<=sgn_vx*t_vx; i++)
{
int previous_tested_y=-545;
int type=CTG_EMPTY;
for (int j=0; j<b->h; j++)
{
int t=(b->y+j)/8;
//if (t!=previous_tested_y)
//{
previous_tested_y=t;
int typetemp;
if (sgn_vx>0)
typetemp=world_get_ctg(b->x+b->w-1+i*sgn_vx,b->y+j);
else
typetemp=world_get_ctg(b->x+i*sgn_vx,b->y+j);
if (/*typetemp==CTG_DEATH ||*/ typetemp==CTG_SOIL)
{
b->x+=(i-1)*sgn_vx;
b->vx=0;
return;
}
int typetemp;
if (sgn_vx>0)
typetemp=world_get_ctg(b->x+b->w-1+i*sgn_vx,b->y+j);
else
typetemp=world_get_ctg(b->x+i*sgn_vx,b->y+j);
if (typetemp==CTG_SOIL)
{
b->x+=(i-1)*sgn_vx;
b->vx=0;
return;
}
//}
}
@ -92,50 +77,45 @@ static void move_y(box_t * b)
{
for (int i=sgn_vy; i<=sgn_vy*b->vy; i++)
{
int previous_tested_x=-545;
for (int j=0; j<b->w; j++)
{
int t=(b->x+j)/8;
//if (t!=previous_tested_x)
//{
previous_tested_x=t;
int typetemp;
if (sgn_vy>0)
typetemp=world_get_ctg(b->x+j ,b->y+b->h-1+i);
else
typetemp=world_get_ctg(b->x+j ,b->y-i);
if (/*typetemp==CTG_DEATH ||*/ typetemp==CTG_SOIL)
int typetemp;
if (sgn_vy>0)
typetemp=world_get_ctg(b->x+j ,b->y+b->h-1+i);
else
typetemp=world_get_ctg(b->x+j ,b->y-i);
if (typetemp==CTG_SOIL)
{
if (b->vy>0)
{
if (b->vy>0)
{
int old=b->x;
if (world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (old==b->x)
{
b->y+=(i-1)*sgn_vy;
b->vy=0;
return;
}
}
else
int old=b->x;
if (world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+3, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+2, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+1, b->y+b->h-1+i)==CTG_EMPTY)
b->x++;
if (world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-4, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-3, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (world_get_ctg(b->x+b->w-1, b->y+b->h-1+i)==CTG_SOIL && world_get_ctg(b->x+b->w-2, b->y+b->h-1+i)==CTG_EMPTY)
b->x--;
if (old==b->x)
{
b->y+=(i-1)*sgn_vy;
b->vy=0;
return;
}
}
else
{
b->y+=(i-1)*sgn_vy;
b->vy=0;
return;
}
}
//}
}
}
@ -146,14 +126,14 @@ static void move_y(box_t * b)
}
int box_move(box_t * b)
void box_move(box_t * b)
{
//velx
move_x(b);
move_y(b);
}
int box_jump(box_t * b, int height)
void box_jump(box_t * b, int height)
{
int sgn_vy=-1*sgn(height);
if (sgn_vy)

@ -2,6 +2,7 @@
#include <liblog.h>
#include <gint/display.h>
#include <keyboard.h>
#include <gint/keyboard.h>
extern image_t img_tickbox;
@ -10,8 +11,8 @@ char loglevels[6][14]={"--all","--information","--warning","--critical","--fatal
void configmenu()
{
keyboard_clear();
font_t* f=dfont(0);
mkb_clear();
font_t const * const f=dfont(0);
while (1)
{
dclear(C_WHITE);
@ -23,11 +24,11 @@ void configmenu()
dtext(40,9,&loglevels[ll_get_level()][0],C_BLACK,C_NONE);
dupdate();
int key=getkey().key;
int key=mkb_getkey();
if (key==KEY_EXIT)
break;
}
keyboard_clear();
mkb_clear();
dfont(f);
}

@ -4,6 +4,7 @@
#include "tile.h"
#include "world.h"
#include "score.h"
#include <camera.h>
#include <stdbool.h>
@ -37,7 +38,7 @@ void display_ennemi(ennemi_t * e)
}
if (e->type==NONE)
return;
if (e->b.x<=world_get_real_x0(0)-e->b.w || e->b.x>=world_get_real_x0(0)+127)
if (e->b.x<=camera_x(0)-e->b.w || e->b.x>=camera_x(0)+127)
return;
else
e->discovered=1;
@ -47,35 +48,35 @@ void display_ennemi(ennemi_t * e)
extern image_t img_goomba;
tileset_t goomba={&img_goomba, ennemi_widths[GOOMBA_ID], ennemi_heights[GOOMBA_ID], 1};
if (e->life==1)
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &goomba, 1+(time_id/10)%2, 0);
if (e->life==0)
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &goomba, 0, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &goomba, 0, 0);
}
if (e->type==KOOPA_V_ID)
{
extern image_t img_koopa_verte;
tileset_t koopa_verte={&img_koopa_verte, ennemi_widths[KOOPA_V_ID], ennemi_heights[KOOPA_V_ID], 1};
if (e->life==1)
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &koopa_verte, (1+e->p1)+(time_id/8)%2, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &koopa_verte, (1+e->p1)+(time_id/8)%2, 0);
}
if (e->type==KOOPA_R_ID)
{
extern image_t img_koopa_rouge;
tileset_t koopa_rouge={&img_koopa_rouge, ennemi_widths[KOOPA_R_ID], ennemi_heights[KOOPA_R_ID], 1};
if (e->life==1)
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &koopa_rouge, (1+e->p1)+(time_id/8)%2, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &koopa_rouge, (1+e->p1)+(time_id/8)%2, 0);
}
if (e->type==CARAPACE_VERTE)
{
extern image_t img_carapace_verte;
tileset_t carapace_verte={&img_carapace_verte, ennemi_widths[CARAPACE_VERTE], ennemi_heights[CARAPACE_VERTE], 1};
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &carapace_verte, 0, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &carapace_verte, 0, 0);
}
if (e->type==CARAPACE_ROUGE)
{
extern image_t img_carapace_rouge;
tileset_t carapace_rouge={&img_carapace_rouge, ennemi_widths[CARAPACE_ROUGE], ennemi_heights[CARAPACE_ROUGE], 1};
draw_tile(e->b.x-world_get_real_x0(0), e->b.y-world_get_real_y0(mario.p.y), &carapace_rouge, 0, 0);
draw_tile(e->b.x-camera_x(0), e->b.y-camera_y(mario.p.y), &carapace_rouge, 0, 0);
}
}
@ -96,7 +97,7 @@ void hurt_mario()
void move_ennemi(ennemi_t *e)
{
if (e->b.x<world_get_real_x0()+128+30 && e->b.x>world_get_real_x0()-30)
if (e->b.x<camera_x()+128+30 && e->b.x>camera_x()-30)
e->discovered=1;
//if (e->b.x+e->b.w<=world_get_real_x0())
// e->type=NONE;

@ -1,26 +1,43 @@
#include "keyboard.h"
#include "mario.h"
#include "score.h"
#include <keyboard.h>
#include <mario.h>
#include <score.h>
#include <gint/keyboard.h>
#include <gint/display.h>
#include <gint/timer.h>
//#include <gint/timer.h>
#include <gint/clock.h>
#include "config.h"
#include <config.h>
mkey_t keys[6]={0};
static mkb_t keys[6]={0};
int mkb_getstate(mkb_t const k)
{
if (k!=MK_NONE)
return keys[k];
return 0;
}
static int konami[]={KEY_UP,KEY_UP,KEY_DOWN,KEY_DOWN,KEY_LEFT,KEY_RIGHT,KEY_LEFT,KEY_RIGHT,KEY_ALPHA,KEY_SHIFT};
void keyboard_clear()
void mkb_clear()
{
for (int i=0; i<6; i++)
keys[i]=0;
clearevents();
}
int menu_pause() // 1 exit, 0 continue
int mkb_getkey()
{
mkb_clear();
while (1)
{
key_event_t const e=pollevent();
if (e.type==KEYEV_DOWN) // Returns only whan a key is down
return e.key;
else
sleep(); // Processor friendly :)
}
}
static int menu_pause() // 1 exit, 0 continue
{
extern image_t img_menu_pause;
extern image_t img_select_arrow;
@ -39,7 +56,7 @@ int menu_pause() // 1 exit, 0 continue
dimage(x+2, y+2+7*choice, &img_select_arrow);
dupdate();
switch (getkey_custom())
switch (mkb_getkey())
{
case KEY_EXIT:
return 0;
@ -49,7 +66,7 @@ int menu_pause() // 1 exit, 0 continue
case KEY_OPTN:
choice=2;
// fall through
case KEY_EXE:
if (choice==2)
configmenu();
@ -64,7 +81,7 @@ int menu_pause() // 1 exit, 0 continue
if (choice<2)
choice++;
break;
#ifdef KONAMI
case KEY_F1:
for (int a=0; a<10; a++)
@ -72,6 +89,7 @@ int menu_pause() // 1 exit, 0 continue
key_event_t e=pollevent();
if (e.type==KEYEV_DOWN)
{
static int const konami[]={KEY_UP,KEY_UP,KEY_DOWN,KEY_DOWN,KEY_LEFT,KEY_RIGHT,KEY_LEFT,KEY_RIGHT,KEY_ALPHA,KEY_SHIFT};
if (e.key!=konami[a])
break;
}
@ -81,7 +99,8 @@ int menu_pause() // 1 exit, 0 continue
{
mario_bigger();
mario_has_bullets=1;
lifes=50;
for (int i=0; i<20; i++)
lifes_add();
extern image_t img_dev;
dimage(0,0,&img_dev);
dupdate();
@ -91,11 +110,12 @@ int menu_pause() // 1 exit, 0 continue
else
e=pollevent();
}
#endif
}
}
}
void update_keyboard()
void mkb_update()
{
key_event_t e;
e=pollevent();
@ -104,7 +124,7 @@ void update_keyboard()
if (keys[i]==2) keys[i]=1;
while(e.type!=KEYEV_NONE)
{
mkey_t k = MK_NONE;
mkb_t k = MK_NONE;
if(e.key==KEY_LEFT)
k=MK_LEFT;
@ -112,18 +132,18 @@ void update_keyboard()
k=MK_RIGHT;
if(e.key==KEY_SHIFT)
k=MK_JUMP1;
k=MK_JUMP;
if(e.key==KEY_UP)
k=MK_UP;
if(e.key==KEY_DOWN)
k=MK_LITTLE;
k=MK_DOWN;
if(e.key==KEY_ALPHA)
k=MK_RUN;
if(keydown(KEY_EXIT))
menu=1;
menu=1; // Displays menu after updating the keyboard
@ -144,25 +164,12 @@ void update_keyboard()
{
int t=menu_pause();
if (t==1)
finish_level=-1;
finish_level=-1; // Exits the level
return;
}
}
int getkey_custom()
{
key_event_t e;
for (int i=0; i<6; i++)
keys[i]=0;
clearevents();
while (1)
{
e=pollevent();
if (e.type==KEYEV_DOWN)
return e.key;
else
sleep();
}
}

@ -376,7 +376,7 @@ void set_level(int w, int l)
teleport_t t[]=
{
{57,6, 212,12, MK_LITTLE},
{57,6, 212,12, MK_DOWN},
{222,2, 178,3, MK_RIGHT}
};
@ -651,10 +651,10 @@ init_ennemies(ennemies0);
teleport_t t[]=
{
{6,4, 21,12, MK_LITTLE},
{106,5, 188,12, MK_LITTLE},
{197,2, 118,4, MK_LEFT},
{180,5, 206,2, MK_LEFT},
{6,4, 21,12, MK_DOWN},
{106,5, 188,12, MK_DOWN},
{197,2, 118,4, MK_RIGHT},
{180,5, 206,2, MK_RIGHT},
};
set_teleporteurs(t, sizeof(t)/sizeof(teleport_t));
@ -985,8 +985,8 @@ init_ennemies(ennemies0);
teleport_t t[]=
{
{106,4, 222,9, MK_LITTLE},
{243,3, 174,4, MK_LITTLE},
{106,4, 222,9, MK_DOWN},
{243,3, 174,4, MK_DOWN},
{216,3, 248,2, MK_UP},
};

@ -28,7 +28,7 @@ static void levelchanger(int w)
while (1)
{
keyboard_clear();
mkb_clear();
dimage(0,0,&img_levelchanger);
drect(xt+(2+wt)*choice, yt, xt+(wt+2)*choice+wt,yt+ht, C_INVERT);
@ -71,7 +71,7 @@ static void levelchanger(int w)
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=getkey_custom();
int key=mkb_getkey();
if (key==KEY_LEFT && choice>0)
choice--;
@ -94,19 +94,19 @@ static void levelchanger(int w)
get_lvl_id(w, i, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes);
sprintf(lvl, "%d", lifes_get());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
int a=play_level(w, i);
if (a==0)
lifes--;
lifes_lose();
if (a==1)
i++;
if (a==-1)
break;
if (lifes==0)
if (lifes_get()==0)
{
extern image_t img_game_over;
dimage(0,0,&img_game_over);
@ -126,7 +126,7 @@ static void levelchanger(int w)
get_lvl_id(w, choice, lvl);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes);
sprintf(lvl, "%d", lifes_get());
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,2000);
@ -161,14 +161,13 @@ static void levelchanger(int w)
void launch_ui()
{
keyboard_clear();
extern image_t img_mainmenu;
const int xt=17,yt=9;
int choice_x=0, choice_y=0;
while (1)
{
keyboard_clear();
mkb_clear();
dimage(0,0,&img_mainmenu);
//Show unlocked worlds
@ -178,16 +177,16 @@ void launch_ui()
{
case 4:
dimage(xt, yt+24, &img_w5);
// fall through
case 3:
dimage(xt+72, yt, &img_w4);
// fall through
case 2:
dimage(xt+48, yt, &img_w3);
// fall through
case 1:
dimage(xt+24, yt, &img_w2);
// fall through
case 0:
dimage(xt, yt, &img_w1);
}
@ -196,7 +195,7 @@ void launch_ui()
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=getkey_custom();
int key=mkb_getkey();
if (key==KEY_UP && choice_y>0)
choice_y--;
if (key==KEY_LEFT && choice_x>0)
@ -250,7 +249,7 @@ int play_level(int w, int l)
timer_stop(0);
return -1;
}
reset_camera();
camera_adjust();

@ -2,11 +2,12 @@
#include "tile.h"
#include "world.h"
#include <gint/display.h>
#include <gint/keyboard.h>
#include "keyboard.h"
#include <keyboard.h>
#include "box.h"
#include "score.h"
#include "bonus.h"
#include <bullets.h>
#include <camera.h>
static int sgn(int x)
{
@ -63,20 +64,20 @@ void mario_draw()
if (mario.size==M_SMALL)
{
if (mario.p.vx*sgn(mario.p.vx)>=3)
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/4)%2, 0);
else if (mario.p.vx*sgn(mario.p.vx)>=1)
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_small, 2*last_vx_sign+(id_frame/8)%2, 0);
else
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_small, 2*last_vx_sign, 0);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_small, 2*last_vx_sign, 0);
}
else
{
if (mario.p.vx*sgn(mario.p.vx)>=3)
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/4)%2, mario_has_bullets);
else if (mario.p.vx*sgn(mario.p.vx)>=1)
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_big, 4*last_vx_sign+(id_frame/8)%2, mario_has_bullets);
else
draw_tile(mario.p.x-world_get_real_x0(mario.p.x), mario.p.y-world_get_real_y0(mario.p.y), &mario_big, 3*last_vx_sign, mario_has_bullets);
draw_tile(mario.p.x-camera_x(mario.p.x), mario.p.y-camera_y(mario.p.y), &mario_big, 3*last_vx_sign, mario_has_bullets);
}
}
}
@ -122,23 +123,22 @@ void mario_move()
}
id_frame++;
update_keyboard();
if (mario_has_bullets==1 && keys[MK_RUN]==2)
if (mario_has_bullets==1 && mkb_getstate(MK_RUN)==2)
{
lance_bullet();
bullet_throw();
}
int jump = keys[MK_JUMP1];// || keys[MK_JUMP2];
if (keys[MK_JUMP1]==2) //|| keys[MK_JUMP2]==2)
if (mkb_getstate(MK_JUMP)==2) //|| keys[MK_JUMP2]==2)
{
if (mario.p.vx*sgn(mario.p.vx)>=6)
box_jump(&mario.p, 9);
else
box_jump(&mario.p, 8);
}
else if (mario.p.vy>=6 && jump==0)
mario.p.vy=5;
else if (mario.p.vy>=2 && mkb_getstate(MK_JUMP)==0)
mario.p.vy--;
int vx=sgn(keys[MK_RIGHT] - keys[MK_LEFT]);
int vx=sgn(mkb_getstate(MK_RIGHT) - mkb_getstate(MK_LEFT));
int c1=world_get_ctg(mario.p.x, mario.p.y-1/*+mario.p.h*/);
int c2=world_get_ctg(mario.p.x+mario.p.w-1, mario.p.y-1/*+mario.p.h*/);
@ -153,7 +153,7 @@ void mario_move()
mario_time_accel%=2;
if (mario_time_accel==0)
{
if (keys[MK_RUN] && (c1==CTG_SOIL || c2==CTG_SOIL))
if (mkb_getstate(MK_RUN) && (c1==CTG_SOIL || c2==CTG_SOIL))
{
if(mario.p.vx*sgn(mario.p.vx)<=8)
mario.p.vx+=vx;
@ -164,7 +164,7 @@ void mario_move()
mario.p.vx+=vx;
}
if (keys[MK_RUN]==0)
if (mkb_getstate(MK_RUN)==0)
{
if (mario.p.vx*vx>4)
mario.p.vx-=vx;
@ -201,10 +201,10 @@ void mario_move()
if (vx<0 && (c1==CTG_SOIL || c2==CTG_SOIL))
last_vx_sign=0;
if (mario.p.x+mario.p.vx<world_get_real_x0(mario.p.x))
if (mario.p.x+mario.p.vx<camera_x(mario.p.x))
{
mario.p.vx=0;
mario.p.x=world_get_real_x0(mario.p.x);
mario.p.x=camera_x(mario.p.x);
}
//teleporteurs_check();
box_move(&mario.p); // <-> + gravity

@ -4,6 +4,7 @@
#include <mario.h>
#include <tile.h>
#include <score.h>
#include <camera.h>
int plateforme_table_size=0;
plateforme_t* plateformes=0;
@ -99,7 +100,7 @@ void display_plateformes()
{
p=&plateformes[i];
for (int j=p->x; j < p->x+p->width; j+=3)
draw_tile(j-world_get_real_x0(),p->y-world_get_real_y0(), &tplateforme, 0,0);
draw_tile(j-camera_x(),p->y-camera_y(), &tplateforme, 0,0);
//drect(p->x-world_get_real_x0(),64-(p->y-world_get_real_y0()),p->x-world_get_real_x0()+p->width,64-(p->y-world_get_real_y0()-3), C_BLACK);
}