ajout des plateformes et corrections bug clavier

This commit is contained in:
Milang 2020-01-11 15:19:53 +01:00
parent 0282e75761
commit 836dce915b
35 changed files with 939 additions and 674 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

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

Binary file not shown.

View File

@ -1,6 +1,6 @@
build-fx/src/levelchanger.c.o: src/levelchanger.c include/levelchanger.h \
include/keyboard.h include/mario.h include/box.h include/world.h \
include/score.h include/level.h include/save.h
include/score.h include/level.h include/save.h include/config.h
include/levelchanger.h:
@ -17,3 +17,5 @@ include/score.h:
include/level.h:
include/save.h:
include/config.h:

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,15 @@
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/plateforme.h:
include/world.h:
include/mario.h:
include/box.h:
include/tile.h:
include/score.h:

BIN
build-fx/src/plateforme.c.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
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/constants.h include/plateforme.h
include/world.h:
@ -15,3 +15,5 @@ include/ennemi.h:
include/bonus.h:
include/constants.h:
include/plateforme.h:

Binary file not shown.

View File

@ -17,4 +17,6 @@ void update_keyboard();
void keyboard_clear();
int getkey_custom();
#endif

53
include/plateforme.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef PLATEFORME_H
#define PLATEFORME_H
#define P_FALLING 0
#define P_MOVING_H 1
#define P_MOVING_V 2
typedef struct
{
unsigned type;
int xinit, yinit;
int x, y;
int width; // height fixed to 3
int v, vinit;
union
{
int xmin;
int ymin;
};
union
{
int xmax;
int ymax;
};
int counter;
} plateforme_t;
#define PLATEFORME_HEIGHT 3
#define PLATEFORME_FALLING(x,y,w) {P_FALLING,x,y,x,y,w,0,0,.xmin=0,.xmax=0,0}
#define PLATEFORME_MOVING_H(x,y,w,v,x0,x1) {P_MOVING_H,x,y,x,y,w,0,v,.xmin=x0,.xmax=x0,0}
#define PLATEFORME_MOVING_V(x,y,w,v,y0,y1) {P_MOVING_V,x,y,x,y,w,0,v,.ymin=y0,.ymax=y0,0}
//void reset_plateforme(plateforme_t* p);
//void move_plateforme(plateforme_t* p); // touch mario stuff
void move_plateformes();
void display_plateformes();
int plateforme_check_collide(int x, int y);
extern int plateforme_table_size;
extern plateforme_t* plateformes;
#endif

View File

@ -37,6 +37,8 @@ extern const tileset_t bloc;
extern const tileset_t mario_small;
extern const tileset_t mario_big;
extern const tileset_t tplateforme;
void draw_tile(int sx, int sy, tileset_t const * const set, int x, int y);
#endif

View File

@ -9,7 +9,7 @@
mkey_t keys[6]={0};
static int konami[]={KEY_UP,KEY_UP,KEY_DOWN,KEY_DOWN,KEY_LEFT,KEY_RIGHT,KEY_LEFT,KEY_RIGHT,KEY_ALPHA,KEY_SHIFT};
@ -24,11 +24,9 @@ int menu_pause() // 1 exit, 0 continue
{
extern image_t img_menu_pause;
extern image_t img_select_arrow;
key_event_t e;
e=pollevent();
while(e.type!=KEYEV_NONE)
e=pollevent();
int key;
clearevents();
int choice=0;
int x=64-img_menu_pause.width/2;
@ -37,65 +35,63 @@ int menu_pause() // 1 exit, 0 continue
keys[i]=0;
while (1)
{
e=pollevent();
while(e.type!=KEYEV_NONE)
{
if (keydown(KEY_EXE))
{
if (choice==2)
configmenu();
else
return choice;
}
if (keydown(KEY_UP) && choice>0)
choice--;
if (keydown(KEY_DOWN) && choice<2)
choice++;
if (keydown(KEY_MENU))
return 1;
if (keydown(KEY_EXIT))
return 0;
if (keydown(KEY_OPTN))
configmenu();
if (keydown(KEY_F1))
{
e=pollevent();
int a=0;
while (a<10)
{
if (e.type==KEYEV_DOWN)
{
if (e.key==konami[a])
a++;
else
break;
}
if (keydown(KEY_EXIT))
break;
if (a==10) // CHEAT MENU
{
mario_bigger();
mario_has_bullets=1;
lifes=50;
extern image_t img_dev;
dimage(0,0,&img_dev);
dupdate();
sleep_ms(3,1000);
return 0;
}
else
e=pollevent();
}
}
e=pollevent();
}
dimage(x,y,&img_menu_pause);
dimage(x+2, y+2+7*choice, &img_select_arrow);
dupdate();
sleep_ms(3,1);
switch (getkey_custom())
{
case KEY_EXIT:
return 0;
case KEY_MENU:
return 1;
case KEY_OPTN:
choice=2;
case KEY_EXE:
if (choice==2)
configmenu();
return choice & 1;
case KEY_UP:
if (choice>0)
choice--;
break;
case KEY_DOWN:
if (choice<2)
choice++;
break;
case KEY_F1:
for (int a=0; a<10; a++)
{
key_event_t e=pollevent();
if (e.type==KEYEV_DOWN)
{
if (e.key!=konami[a])
break;
}
if (keydown(KEY_EXIT))
break;
if (a==10) // Cheat code
{
mario_bigger();
mario_has_bullets=1;
lifes=50;
extern image_t img_dev;
dimage(0,0,&img_dev);
dupdate();
sleep_ms(3,1000);
return 0;
}
else
e=pollevent();
}
}
}
}
@ -128,7 +124,7 @@ void update_keyboard()
if(keydown(KEY_EXIT))
menu=1;
if (k!=MK_NONE)
@ -145,5 +141,23 @@ void update_keyboard()
e=pollevent();
}
if (menu)
global_quit=menu_pause();
mario_dead=menu_pause();
}
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();
}
}

View File

@ -4,13 +4,15 @@
#include "score.h"
#include "ennemi.h"
#include "keyboard.h"
//#include "teleporteur.h"
#include <plateforme.h>
#include <gint/display.h>
#include <gint/std/stdlib.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/std/string.h>
void malloc_error()
{
extern image_t img_ram;
@ -52,6 +54,20 @@ void init_ennemies(ennemi_t * table)
memcpy(ennemis_global, table, size);
}
static void init_plateformes(plateforme_t * table)
{
if (plateformes)
{
free(plateformes);
}
int size=sizeof(plateforme_t)*plateforme_table_size;
plateformes=malloc(size);
if (plateformes==0)
malloc_error();
memcpy(plateformes, table, size);
}
void set_level(int n)
{
new_level();
@ -313,6 +329,13 @@ void set_level(int n)
GOOMBA(924,16,-1)
};
init_ennemies(ennemies0);
plateforme_t plateforme0[]=
{
PLATEFORME_MOVING_H(15,25,16,1,0,60)
};
plateforme_table_size=1;
init_plateformes(plateforme0);
}
}

View File

@ -11,6 +11,7 @@
#include <score.h>
#include <level.h>
#include <save.h>
#include <config.h>
extern image_t img_mainmenu;
@ -49,7 +50,8 @@ void launch_ui()
drect(xt+24*choice_x,yt+24*choice_y, xt+24*choice_x+20,yt+24*choice_y+20, C_INVERT);
dupdate();
int key=getkey().key;
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=getkey_custom();
if (key==KEY_UP && choice_y>0)
choice_y--;
if (key==KEY_LEFT && choice_x>0)
@ -65,7 +67,19 @@ void launch_ui()
if (choice_x==3 && choice_y==1)
break;
if (choice_x==2 && choice_y==1)
break;
{
configmenu();
}
if (choice_y*choice_x==0)
{
int world_chosen=0;
if (choice_y==1)
world_chosen=4;
else
world_chosen=choice_x;
if (world_chosen<=get_progress_status())
play_level(world_chosen);
}
}
if (key==KEY_EXIT || key==KEY_MENU)
@ -75,17 +89,6 @@ void launch_ui()
}
extern image_t img_error;
GNORETURN void system_error(uint32_t code)
{
timer_stop(0);
dimage(0,0,&img_error);
dupdate();
while(1) getkey();
}
int frame_id;
int callback(volatile void *arg)
{
@ -99,16 +102,12 @@ int callback(volatile void *arg)
int play_level(int l)
{
set_level(l);
volatile int has_ticked = 1;
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
timer_start(0);
//int finish_status=0; // FAil
finish_level=0;
finish_level=0; mario_dead=0;
set_level(l);
while(global_quit==0)
{
@ -126,6 +125,7 @@ int play_level(int l)
dupdate();
if (mario_dead || finish_level)
{
timer_stop(0);
return 0;
}
@ -133,4 +133,5 @@ int play_level(int l)
else
sleep_ms(3,1);
}
}

View File

@ -24,9 +24,6 @@ int main(void)
//gint_panic_set(system_error);
ll_set_panic();
int current_level=0;
launch_ui();
timer_stop(0);
}

122
src/plateforme.c Normal file
View File

@ -0,0 +1,122 @@
#include <plateforme.h>
#include <world.h>
#include <mario.h>
#include <tile.h>
#include <score.h>
int plateforme_table_size=0;
plateforme_t* plateformes=0;
static int sgn(int x)
{
if (x==0)
return 0;
else if (x>0)
return 1;
return -1;
}
void reset_plateforme(plateforme_t* p)
{
p->x=p->xinit;
p->y=p->yinit;
p->v=p->vinit;
}
void move_plateforme(plateforme_t* p)
{/*
if (p->x+p->width-world_get_real_x0()<-50)
return;
if (p->x-world_get_real_x0()-128>50)
return;
if (p->y-world_get_real_y0()-64>50)
return;
if (p->y+3-world_get_real_y0()<-50)
return;
*/
int xc = (mario.p.x<p->x+p->width && mario.p.x>=p->x) || (mario.p.x+mario.p.w<p->x+p->width && mario.p.x+mario.p.w>=p->x);
int yc = (mario.p.y+mario.p.h==p->y);
if (p->type==P_FALLING)
{
if (p->v)
p->v++;
p->y+=p->v;
}
if (p->type==P_MOVING_H)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->v==0)
p->v=p->vinit;
p->x+=t_v;
if (p->x+p->width >= p->xmax && p->v>0)
p->v *= -1;
if (p->x <= p->xmin && p->v<0)
p->v *= -1;
}
if (p->type==P_MOVING_V)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->v==0)
p->v=p->vinit;
p->y+=t_v;
if (p->y > p->ymax || p->y+3 < p->ymin)
p->v *= -1;
}
if (xc&&yc)
{
int s=sgn(p->v);
int t_v=((s*p->v+time_id%2)/2)*s;
if (p->type==P_FALLING)
mario.p.y+=t_v;
if (p->type==P_MOVING_H)
mario.p.x+=t_v;
if (p->type==P_MOVING_V)
mario.p.y+=t_v;
}
}
void display_plateformes()
{
plateforme_t * p=0;
for (int i=0; i<plateforme_table_size; i++)
{
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);
//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);
}
}
void move_plateformes()
{
plateforme_t * p=0;
for (int i=0; i<plateforme_table_size; i++)
{
p=&plateformes[i];
move_plateforme(p);
}
}
int plateforme_check_collide(int x, int y)
{
for (int i=0; i<plateforme_table_size; i++)
{
plateforme_t * p=&plateformes[i];
if (p->x<=x && p->x+p->width>x && p->y<=y && p->y+3>y)
return 1;
}
return 0;
}

View File

@ -17,7 +17,7 @@ int pieces=0;
int time_id=0;
int time_left=0;
int finish_level=-1;
int finish_level=0;
static void new_game()
{
@ -32,7 +32,7 @@ static void new_game()
void new_level()
{
finish_level=-1;
finish_level=0;
time_left=400;
time_id=0;
}
@ -105,5 +105,6 @@ void score_display()
sleep_ms(3,1000);
sleep_ms(3,1000);
finish_level=0;
mario_dead=1;
}
}

View File

@ -56,6 +56,9 @@ const tileset_t mario_small={&img_mariosmall, TILE_W, TILE_H, 1};
extern image_t img_mariobig;
const tileset_t mario_big={&img_mariobig, TILE_W, 2*TILE_H, 1};
extern image_t img_plateforme;
const tileset_t tplateforme={&img_plateforme, 3, 3, 0};
void draw_tile(int sx, int sy, tileset_t const * const set, int x, int y)
{

View File

@ -7,6 +7,7 @@
#include <liblog.h>
#include "constants.h"
#include "ennemi.h"
#include <plateforme.h>
world_t * w_current=0;
image_t * w_fond=0;
@ -138,6 +139,8 @@ int world_get_ctg(int x, int y)
{
return CTG_DEATH;
}
if (plateforme_check_collide(x,y))
return CTG_SOIL;
switch (c->type)
{
case TUYAU:
@ -176,8 +179,8 @@ int world_get_real_y0() //mario delta en 0,0
void world_draw(int x, int y)
{
int mx0=world_get_real_x0(x);
int my0=world_get_real_y0(y);
int mx0=world_get_real_x0();
int my0=world_get_real_y0();
int sx0=mx0%8;
int sy0=my0%8;
int mx=mx0;
@ -196,6 +199,7 @@ void world_draw(int x, int y)
display_ennemi_table();
bullet_display();
display_plateformes();
mario_draw();
//int mx, my;
@ -228,6 +232,7 @@ void world_move()
ll_sendp(LEVEL_INFO,"\n > Moved bonus");
bullet_move();
ll_sendp(LEVEL_INFO,"\n > Moved bullets");
move_plateformes();
mario_move();
ll_sendp(LEVEL_INFO,"\n > Moved mario !\n");