add global time management, update font and add dynamic infos about levels

This commit is contained in:
Milang 2020-01-15 20:42:51 +01:00
parent e3a82711d8
commit 823c28050e
23 changed files with 710 additions and 629 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
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/ennemi.h include/box.h include/score.h include/constants.h
include/box.h:
@ -10,3 +10,5 @@ include/ennemi.h:
include/box.h:
include/score.h:
include/constants.h:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,10 @@
#ifndef SAVE_H
#define SAVE_H
#define WORLD_RUN_ENTRY 9
#define WORLD_RUN_ENTRY 9 // 8 niveaux + mode run
#define NB_MONDES 5
void load_save(); // Ho calme toi pas tt de suite !
void load_save(); // Ho calme toi pas tt de suite ! Utilisera BFile lorsque le header de gint sera complété
void flash_save(); // Non plus :E
int get_highscore(int world, int level);

View File

@ -14,4 +14,6 @@ void score_add_coin();
void new_level();
void new_game();
int get_time_spent();
#endif

View File

@ -115,7 +115,8 @@ void world_reset();
#define CTG_SOIL 1
#define CTG_EMPTY 2
#define CTG_DEATH 3
#define CTG_WATER 3
#define CTG_DEATH 4
int world_get_ctg(int x, int y);
void reset_camera();

View File

@ -2,6 +2,7 @@
#include "world.h"
#include "ennemi.h"
#include "score.h"
#include <constants.h>
int sgn(int x)
{
@ -38,6 +39,12 @@ static void move_x(box_t * b)
int t_vx=((sgn_vx*b->vx+time_id%2)/2)*sgn_vx;
sgn_vx=sgn(t_vx);
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;
if (frame_id%coef)
return;
if (sgn_vx)
{
for (int i=sgn_vx; i<=sgn_vx*t_vx; i++)
@ -74,6 +81,13 @@ static void move_y(box_t * b)
{
b->last_vy=b->vy;
int sgn_vy=sgn(b->vy);
int coef=1;//1;
if (world_get_ctg(b->x, b->y)==CTG_WATER || world_get_ctg(b->x+b->w-1, b->y)==CTG_WATER)
coef=2;
if (frame_id%coef)
return;
if (sgn_vy)
{
for (int i=sgn_vy; i<=sgn_vy*b->vy; i++)
@ -141,17 +155,21 @@ int box_move(box_t * b)
int box_jump(box_t * b, int height)
{
int sol=0;
int sgn_vy=-1*sgn(height);
if (sgn_vy)
{
int sol=0, eau=0;
for (int j=0; j<b->w; j++)
{
int typetemp=world_get_ctg(b->x+j ,b->y+sgn_vy);
if (/*typetemp==CTG_DEATH || */typetemp==CTG_SOIL)
sol=1;
if (typetemp==CTG_SOIL)
sol++;
if (typetemp==CTG_WATER)
eau++;
}
if (sol)
b->vy=height;
else if (eau)
b->vy+=height/2;
}
}

View File

@ -4,6 +4,7 @@
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/std/stdio.h>
#include <keyboard.h>
#include <mario.h>
@ -32,7 +33,29 @@ static void levelchanger(int w)
drect(xt+(2+wt)*choice, yt, xt+(wt+2)*choice+wt,yt+ht, C_INVERT);
char str[8];
if (choice != 8)
{
sprintf(str, "%d", choice+1);
dtext(45,19, str, C_BLACK, C_WHITE);
}
else
{
dtext(13,19, "MODE COURSE :", C_BLACK, C_WHITE);
}
if (get_best_time(w,choice))
{
sprintf(str, "%d", get_best_time(w,choice));
int i=0;
while (str[i])
i++;
dtext(99-6*i, 53, str, C_BLACK, C_WHITE);
}
dupdate();
//int key=getkey_opt(GETKEY_REP_ARROWS,0).key;
int key=getkey_custom();
@ -48,6 +71,8 @@ static void levelchanger(int w)
if (choice==8)
{
new_game();
mario_smaller();
mario_immunity=0;
for (int i=0; i<7; i+=0)
{
int a=play_level(w, i);
@ -70,10 +95,14 @@ static void levelchanger(int w)
}
else
{
new_game();
mario_smaller();
mario_immunity=0;
play_level(w, choice);
int s=play_level(w, choice);
if (s)
set_best_time(w, choice, get_time_spent());
}
}
if (key==KEY_EXIT || key==KEY_MENU)
@ -191,7 +220,7 @@ int play_level(int w, int l)
char lvl[4];
get_lvl_id(w, l, lvl);
dtext(57,28, lvl, C_WHITE, C_BLACK);
dtext(53,28, lvl, C_WHITE, C_BLACK);
sprintf(lvl, "%d", lifes);
dtext(65,54, lvl, C_WHITE, C_BLACK);
dupdate();
@ -214,7 +243,9 @@ int play_level(int w, int l)
dupdate();
if (mario_dead)
{
for (int i=6; mario.p.y>=0; i--)
mario_immunity=0;
int i=6;
while(mario.p.y>=0)
{
if (has_ticked)
{
@ -222,9 +253,11 @@ int play_level(int w, int l)
mario.p.y+=i;
dclear(C_WHITE);
world_draw(mario.p.x,mario.p.y);
mario_draw();
score_display();
dupdate();
i--;
}
else
sleep_ms(3,1);
@ -239,6 +272,7 @@ int play_level(int w, int l)
{
timer_stop(0);
// TODO ajouter temps au score etc
sleep_ms(3,3000);
return finish_level;
}
@ -246,5 +280,6 @@ int play_level(int w, int l)
else
sleep_ms(3,1);
}
return 0;
}

View File

@ -229,11 +229,16 @@ void mario_move()
if (c->type==COIN && c->taken==0)
{score_add_coin();c->taken=1;}
end_level_t* e=(end_level_t*)world_get(mario.p.x, mario.p.y);
if (e->type==END_LEVEL)
end_level_t *e1=(end_level_t*)world_get(mario.p.x, mario.p.y), *e2=(end_level_t*)world_get(mario.p.x+mario.p.w-1, mario.p.y);
if (e1->type==END_LEVEL)
{
finish_level=1;
score_add(400*e->bonus);
score_add(400*e1->bonus);
}
if (e2->type==END_LEVEL)
{
finish_level=1;
score_add(400*e2->bonus);
}

View File

@ -4,37 +4,41 @@
uint32_t level_highscores [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_scores [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_times [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_coins [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_starfrags [NB_MONDES] [WORLD_RUN_ENTRY]={0};
uint32_t level_best_times [NB_MONDES] [WORLD_RUN_ENTRY];
uint32_t progress_status=0; // 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);
static uint32_t const file_size = sizeof(level_scores)+sizeof(level_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];
return level_scores[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;
level_scores[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];
return level_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;
if (level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]==0 || score<level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY])
level_times[world%NB_MONDES][level%WORLD_RUN_ENTRY]=score;
}
int get_progress_status()

View File

@ -16,6 +16,7 @@ int pieces=0;
int time_id=0;
int time_left=0;
int time_spent=0;
int finish_level=0;
@ -29,6 +30,7 @@ void new_game()
combo_id=-10;
mario_smaller();
new_level();
time_spent=0;
}
void new_level()
@ -93,10 +95,13 @@ void score_display()
time_id++;
if (time_id%8==0)
{
time_left--;
time_spent++;
}
sprintf(str, "TIME : %d", time_left);
dtext(87,0,str, C_BLACK, C_WHITE);
dtext(87-7,0,str, C_BLACK, C_WHITE);
extern image_t img_time_over;
if (time_left==0)
{
@ -109,3 +114,8 @@ void score_display()
mario_dead=1;
}
}
int get_time_spent()
{
return time_spent;
}