add menu selection (incomplete)

This commit is contained in:
Milang 2020-01-07 21:31:34 +01:00
parent 6f96c557cc
commit 32659a4b16
16 changed files with 780 additions and 640 deletions

Binary file not shown.

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,12 @@
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/levelchanger.h:
include/keyboard.h:
include/mario.h:
include/box.h:
include/world.h:

Binary file not shown.

3
build-fx/src/save.c.d Normal file
View File

@ -0,0 +1,3 @@
build-fx/src/save.c.o: src/save.c include/save.h
include/save.h:

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

Binary file not shown.

6
include/levelchanger.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef LEVEL_CHANGE_H
#define LEVEL_CHANGE_H
void launch_ui();
#endif

16
include/save.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef SAVE_H
#define SAVE_H
#define WORLD_RUN_ENTRY 9
#define NB_MONDES 5
void load_save(); // Ho calme toi pas tt de suite !
void flash_save(); // Non plus :E
int get_highscore(int world, int level);
void set_highscore(int world, int level, int score);
int get_best_time(int world, int level);
void set_best_time(int world, int level, int score);
#endif

View File

@ -29,78 +29,6 @@ static int sgn(int x)
static bonus_t bonus ={BONUS_NONE, {0,0,TILE_W,TILE_H,0,0,0,1}, 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;
}
}
}
}
}
}
void bonus_set(int type, int x, int y)
{
@ -121,7 +49,6 @@ void bonus_move() //+collision
if (bonus.type==BONUS_NONE)
return;
if (bonus.type==BONUS_STAR)
{
box_jump(&bonus.b,4);
@ -191,4 +118,80 @@ void bonus_draw()
draw_tile(bonus.b.x-world_get_real_x0(), bonus.b.y-world_get_real_y0(mario.p.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;
}
}
}
}
}
}

103
src/levelchanger.c Normal file
View File

@ -0,0 +1,103 @@
#include <levelchanger.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <keyboard.h>
#include <mario.h>
#include <world.h>
extern image_t img_mainmenu;
void launch_ui()
{
keyboard_clear();
extern image_t img_mainmenu;
while (1)
{
keyboard_clear();
dimage(0,0,&img_mainmenu);
dupdate();
int key=getkey().key;
if (key==KEY_EXIT)
break;
}
}
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)
{
volatile int *has_ticked = arg;
*has_ticked = 1;
return 0;
}
void play_level(int l)
{
volatile int has_ticked = 1;
set_level(l);
while(global_quit==0)
{
if (has_ticked)
{
has_ticked=0;
frame_id++;
//mario_move();
world_move();
dclear(C_WHITE);
world_draw(mario.p.x,mario.p.y);
score_display();
dupdate();
if (mario_dead==1)
{
mario_dead=0;
finish_level=0;
}
if (finish_level==0)
{
lifes--;
mario_smaller();
set_level(current_level);
extern image_t img_new_level;
dimage(0,0,&img_new_level);
char lvl[4];
get_lvl_id(current_level, lvl);
dtext(57,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes);
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,1000);
sleep_ms(3,1000);
sleep_ms(3,1000);
dclear(C_BLACK);
}
if (finish_level>=1)
{
current_level+=finish_level;
set_level(current_level);
}
}
else
sleep_ms(3,1);
}
}

View File

@ -3,6 +3,8 @@
#include <gint/timer.h>
#include <liblog.h>
#include <levelchanger.h>
#include "world.h"
#include "mario.h"
#include "level.h"
@ -15,83 +17,19 @@
#include <gint/clock.h>
#include <gint/std/stdio.h>
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)
{
volatile int *has_ticked = arg;
*has_ticked = 1;
return 0;
}
int main(void)
{
extern font_t font_mario;
dfont(&font_mario);
//gint_panic_set(system_error);
ll_set_panic();
volatile int has_ticked = 1;
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
timer_start(0);
set_level(0);
int current_level=0;
while(global_quit==0)
{
if (has_ticked)
{
has_ticked=0;
frame_id++;
//mario_move();
world_move();
dclear(C_WHITE);
world_draw(mario.p.x,mario.p.y);
score_display();
dupdate();
if (mario_dead==1)
{
mario_dead=0;
finish_level=0;
}
if (finish_level==0)
{
lifes--;
mario_smaller();
set_level(current_level);
extern image_t img_new_level;
dimage(0,0,&img_new_level);
char lvl[4];
get_lvl_id(current_level, lvl);
dtext(57,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes);
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
sleep_ms(3,1000);
sleep_ms(3,1000);
sleep_ms(3,1000);
dclear(C_BLACK);
}
if (finish_level>=1)
{
current_level+=finish_level;
set_level(current_level);
}
}
else
sleep_ms(3,1);
}
launch_ui();
timer_stop(0);
}

38
src/save.c Normal file
View File

@ -0,0 +1,38 @@
#include <save.h>
#include <stdint.h>
uint32_t level_highscores [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_best_times [NB_MONDES] [WORLD_RUN_ENTRY];
uint32_t progress_status=1; // world 1 only
static uint32_t checksum1;
static uint32_t const file_size = sizeof(level_highscores)+sizeof(level_best_times)+sizeof(progress_status)+sizeof(checksum1);
void load_save(){};
void flash_save(){};
int get_highscore(int world, int level)
{
return level_highscores[world%NB_MONDES][level%WORLD_RUN_ENTRY];
}
void set_highscore(int world, int level, int score)
{
level_highscores[world%NB_MONDES][level%WORLD_RUN_ENTRY]=score;
}
int get_best_time(int world, int level)
{
return level_best_times[world%NB_MONDES][level%WORLD_RUN_ENTRY];
}
void set_best_time(int world, int level, int score)
{
level_best_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]=score;
}