Sauvegarde BFile

Update temps
Update textures
Update fichier image
This commit is contained in:
Tituya 2020-08-27 00:31:22 +02:00
parent d56e88f40d
commit a45220cacf
29 changed files with 178 additions and 78 deletions

BIN
AST3.g3a

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 339 B

After

Width:  |  Height:  |  Size: 945 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

After

Width:  |  Height:  |  Size: 881 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

BIN
assets-cg/img/endscreen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 B

After

Width:  |  Height:  |  Size: 807 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 B

After

Width:  |  Height:  |  Size: 977 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 590 B

BIN
assets-cg/img/medals.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

View File

@ -1,3 +1,3 @@
#define PLAYER_SPEED 2
#define LEVEL_MAX 15
#define PLAYER_HEIGHT 11
#define FPS 70

View File

@ -2,3 +2,4 @@ void draw_level(char level[]);
void draw_player(int x, int y, char type);
void draw_timer(unsigned int frame);
void draw_blackout(int x, int y);
void draw_end(int framelevel, int id_level);

View File

@ -1,2 +1,3 @@
char start_menu();
char speed_menu(int *id_level);
int round(float num);

6
include/save.h Normal file
View File

@ -0,0 +1,6 @@
void savefile(void);
int loadtime(int a);
void loadfile(void);
void restore(void);
void savetimes(float framelevel, int id_level);

View File

@ -1,2 +1,2 @@
void check_medal(unsigned int frame_level, int id_level);
void check_medal(unsigned int frame_level, int id_level, int x, int y);
void draw_time(int id_level);

View File

@ -2,6 +2,7 @@
#include <gint/std/string.h>
#include <gint/display.h>
#include "define.h"
#include "times.h"
#define VISIBLE_RECT 35
@ -11,20 +12,17 @@ extern bopti_image_t img_dead; //dead block
extern bopti_image_t img_player; //player
extern bopti_image_t img_end; //end of level
extern bopti_image_t img_key1; //key 1
extern bopti_image_t img_keyblock; //block link to the key1
extern bopti_image_t img_blackout; //blackout
extern bopti_image_t img_chrono1; //chronoblock
extern bopti_image_t img_chrono2; //chronoblock 2
extern bopti_image_t img_key2; //key 2
extern bopti_image_t img_key2block; //block link to the key 2
extern bopti_image_t img_key2blockvoid; //block link to the key 2
extern bopti_image_t img_damaged; //damaged block
extern bopti_image_t img_chock; //chock block
extern bopti_image_t img_switch; //switch block
extern bopti_image_t img_ice; //switch block
extern bopti_image_t img_appear; //appear block
extern bopti_image_t img_appearblock; //appear block
extern bopti_image_t img_chrono2appear; //appear block
extern bopti_image_t img_endscreen;
void draw_player(int x, int y, char type)
{
@ -54,25 +52,25 @@ void draw_level(char level[])
dimage(x,y,&img_end);
break;
case '3': //block link to the key1
dimage(x,y,&img_keyblock);
dsubimage(x,y,&img_key1,0,0,16,16,DIMAGE_NONE);
break;
case 'k': //key1
dimage(x,y,&img_key1);
dsubimage(x,y,&img_key1,16,0,16,16,DIMAGE_NONE);
break;
case 'a': //block link to the key2 when it's not powered on
dimage(x,y,&img_key2blockvoid);
dsubimage(x,y,&img_key2,0,0,16,16,DIMAGE_NONE);
break;
case '4': //block link to the key2
dimage(x,y,&img_key2block);
dsubimage(x,y,&img_key2,16,0,16,16,DIMAGE_NONE);
break;
case 'K': //key2
dimage(x,y,&img_key2);
dsubimage(x,y,&img_key2,32,0,16,16,DIMAGE_NONE);
break;
case 'c': //chrono blocks
dimage(x,y,&img_chrono1);
break;
case 'C': //chrono blocks
dimage(x,y,&img_chrono2);
dsubimage(x,y,&img_chrono2,16,0,16,16,DIMAGE_NONE);
break;
case 'b': //blackout blocks
dimage(x,y,&img_blackout);
@ -83,23 +81,23 @@ void draw_level(char level[])
case 'l': //chock blocks
dimage(x,y,&img_chock);
break;
case 'i': //chock blocks
case 'i': //ice blocks
dimage(x,y,&img_ice);
break;
case 'S': //chock blocks
dimage(x,y,&img_switch);
break;
case 'h': //void appear blocks
dimage(x,y,&img_appear);
dsubimage(x,y,&img_appear,0,0,16,16,DIMAGE_NONE);
break;
case 'y': //void appear blocks
dimage(x,y,&img_appear);
dsubimage(x,y,&img_appear,0,0,16,16,DIMAGE_NONE);
break;
case 'H': //appear blocks
dimage(x,y,&img_appearblock);
dsubimage(x,y,&img_appear,16,0,16,16,DIMAGE_NONE);
break;
case 'm': //chronoappear blocks
dimage(x,y,&img_chrono2appear);
dsubimage(x,y,&img_chrono2,0,0,16,16,DIMAGE_NONE);
break;
}
x+=16;
@ -126,3 +124,13 @@ void draw_timer(unsigned int frame)
{
dprint_opt(0, 0, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%u.%02u",(frame)/FPS, (frame)%FPS);
}
void draw_end(int framelevel, int id_level)
{
float framefloat = framelevel;
dimage(144,60,&img_endscreen);
dprint_opt(220, 115, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%d", framelevel);
dprint(166, 87, C_RED, "%.2j",(int)(framefloat/FPS*100));
check_medal(framelevel, id_level, 178, 140);
dupdate();
}

View File

@ -2,6 +2,7 @@
#include <gint/keyboard.h>
#include <gint/clock.h>
#include <gint/timer.h>
#include <gint/gint.h>
#include <gint/std/string.h>
#include "setlevel.h"
@ -9,6 +10,7 @@
#include "collide.h"
#include "menu.h"
#include "times.h"
#include "save.h"
#include "define.h"
#define VACCELERATION 0.2
@ -17,6 +19,7 @@
#define FRICTION 0.2
int main(void);
void end(unsigned int frame);
int callback(volatile int *frame_elapsed)
{
@ -24,11 +27,6 @@ int callback(volatile int *frame_elapsed)
return TIMER_CONTINUE;
}
int round(float num) //round(2.5) = 3 round(-3.2) = -3
{
return num < 0 ? num - 0.5 : num + 0.5;
}
void game(int *id_level, char mode, char *type)
{
volatile int frame_elapsed = 1;
@ -41,7 +39,7 @@ void game(int *id_level, char mode, char *type)
int player_x = 20, player_y = 20;
char level[351];
char gravity = 0; //0 down 1 up
char check = 0;
char check = 1;
char blackout = 0;
int start_x;
int start_y;
@ -209,6 +207,11 @@ void game(int *id_level, char mode, char *type)
framelevel=0;
if(*id_level==10 && *type==1) *type = 2;
else if(*type!=3) *type = 1;
if(*id_level==LEVEL_MAX+1)
{
timer_stop(timer);
end(frame);
}
}
if(collide(player_x, player_y, level, 'k')) //Collide with key1 = disappearance of blocks
{
@ -401,12 +404,9 @@ void game(int *id_level, char mode, char *type)
if(*id_level==0) *id_level=1;
if(game_loop)
{
dclear(C_WHITE);
float framefloat = framelevel;
dprint_opt(198, 90, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%d", framelevel);
dprint_opt(198, 112, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%.2j",(int)(framefloat/FPS*100));
check_medal(framelevel, *id_level);
dupdate();
draw_end(framelevel, *id_level);
savetimes(framefloat, *id_level);
sleep_ms(5000);
}
if(!speed_menu(id_level))
@ -417,7 +417,16 @@ void game(int *id_level, char mode, char *type)
}
else main();
}
if(!mode) main();
else main();
}
void end(unsigned int frame)
{
dclear(C_WHITE);
float framefloat = frame;
dprint_opt(198, 112, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%.2j",(int)(framefloat/FPS*100));
dupdate();
sleep_ms(5000);
}
int main(void)
@ -446,5 +455,8 @@ int main(void)
int id_level = 0;
game(&id_level, mode, &type);
}
gint_setrestart(1);
gint_osmenu();
main();
return 0;
}

View File

@ -3,6 +3,14 @@
#include <gint/keyboard.h>
#include "setlevel.h"
#include "times.h"
#include "define.h"
#include "save.h"
#include <gint/gint.h>
int round(float num) //round(2.5) = 3 round(-3.2) = -3
{
return num < 0 ? num - 0.5 : num + 0.5;
}
char start_menu(char *type)
{
@ -12,6 +20,7 @@ char start_menu(char *type)
char buffer = 1;
char buffer2 = 1;
int Y_POS = 85;
gint_switch(restore);
while(menu_loop)
{
clearevents();
@ -34,7 +43,7 @@ char start_menu(char *type)
if(!buffer) return -1;
}
else buffer = 0;
if(keydown(KEY_5) && keydown(KEY_6)) *type = 3;
if(keydown_all(KEY_5,KEY_6)) *type = 3;
while (keydown_any(KEY_UP, KEY_DOWN, 0)) clearevents();
}
return selection;
@ -49,7 +58,7 @@ char speed_menu(int *id_level)
char buffer = 1;
int appear = 10;
int disappear = 13;
int sto = loadtime(*id_level-1);
char menu_loop = 1;
char check = 1;
extern bopti_image_t img_speedrun;
@ -59,14 +68,18 @@ char speed_menu(int *id_level)
clearevents();
dclear(C_WHITE);
*id_level += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
if (*id_level == 16) *id_level = 1;
else if (*id_level == 0) *id_level = 15;
if (*id_level == LEVEL_MAX+1) *id_level = 1;
else if (*id_level == 0) *id_level = LEVEL_MAX;
if(keydown(KEY_RIGHT) || keydown(KEY_LEFT)) sto = loadtime(*id_level-1);
set_level(*id_level, level, &start_x, &start_y, &gravity, &appear, &disappear);
draw_level(level);
dimage(0,0,&img_speedrun);
dtext(340, 214, C_BLACK, "TIME");
if(sto != 0) check_medal(round(sto*0.01*FPS), *id_level, 335, 8);
dtext(340, 214, C_BLACK, "TIMES");
dtext(190, 45, C_BLACK, "Time : ");
dprint(80,20,C_BLACK,"Level : %d",*id_level);
if(sto != 0) dprint(194,60,C_RED, "%.2j", sto);
else dprint(202,60,C_RED, "/");
dupdate();
if (keydown_any(KEY_SHIFT, KEY_EXE, 0))
{

66
src/save.c Normal file
View File

@ -0,0 +1,66 @@
#include <gint/bfile.h>
#include <gint/gint.h>
#include <gint/std/stdlib.h>
#include "define.h"
int retcode;
int valeur = 0;
int times[LEVEL_MAX]; //moche et je le sais... A essayer l'allocution dynamique
void savefile(void)
{
uint16_t *filepath = u"\\\\fls0\\AST3.sav";
int descriptor;
descriptor = BFile_Open(filepath, BFile_WriteOnly);
for(int i = 0; i != 14; i++) BFile_Write(descriptor, &times[i], sizeof(times[i]));
BFile_Close(descriptor);
}
void loadfile(void)
{
int descriptor;
uint16_t *filepath = u"\\\\fls0\\AST3.sav";
descriptor = BFile_Open(filepath, BFile_ReadOnly);
BFile_Read(descriptor, &retcode, 4, 4*valeur);
BFile_Close(descriptor);
}
void savetimes(float framelevel, int id_level)
{
if(times[id_level-1]>(int)(framelevel/FPS*100) || times[id_level-1]==0)
{
times[id_level-1]=(int)(framelevel/FPS*100);
gint_switch(savefile);
}
}
void restore()
{
uint16_t *filepath = u"\\\\fls0\\AST3.sav";
struct BFile_FileInfo fileInfo;
int handle;
uint16_t foundpath[30];
int size = 500;
int descriptor;
char checkfile = BFile_FindFirst(filepath, &handle, foundpath, &fileInfo);
BFile_FindClose(handle);
if(checkfile == -1) BFile_Create(filepath, BFile_File, &size);
else
{
descriptor = BFile_Open(filepath, BFile_ReadOnly);
for(int i = 0; i != 14; i++)
{
BFile_Read(descriptor, &retcode, 4, 4*i);
times[i] = (int)retcode;
}
BFile_Close(descriptor);
}
}
int loadtime(int a)
{
valeur = a;
gint_switch(loadfile);
return (int)retcode;
}

View File

@ -3,43 +3,39 @@
#include <gint/display.h>
#include <gint/keyboard.h>
extern bopti_image_t img_bronze;
extern bopti_image_t img_argent;
extern bopti_image_t img_or;
extern bopti_image_t img_createur;
void check_medal(unsigned int frame_level, int id_level)
extern bopti_image_t img_medals;
void check_medal(unsigned int frame_level, int id_level, int x, int y)
{
float time=1.0;
float framefloat = frame_level;
float level_time[] = {5.81,8.38,5.89,8.68,3.84,3.58,6.81,7.48,10.46,9.25,6.48,11.94,5.68};
float level_time[] = {5.91,8.76,5.89,3.58,3.84,8.45,6.92,7.68,10.46,9.25,6.48,11.94,5.68};
time = level_time[id_level-1];
if(frame_level/FPS < (unsigned int)time || (frame_level/FPS <= (unsigned int)time &&
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time)*100-(int)(time)*100))) dimage(380,8,&img_createur);
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time)*100-(int)(time)*100))) dsubimage(x+45,y,&img_medals,36,0,12,12,DIMAGE_NONE);
if(frame_level/FPS < (unsigned int)(time*1.2) || (frame_level/FPS <= (unsigned int)(time*1.2) &&
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*1.2)*100-(int)(time*1.2)*100))) dimage(360,8,&img_or);
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*1.2)*100-(int)(time*1.2)*100))) dsubimage(x+30,y,&img_medals,24,0,12,12,DIMAGE_NONE);
if(frame_level/FPS < (unsigned int)(time*1.5) || (frame_level/FPS <= (unsigned int)(time*1.5) &&
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*1.5)*100-(int)(time*1.5)*100))) dimage(340,8,&img_argent);
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*1.5)*100-(int)(time*1.5)*100))) dsubimage(x+15,y,&img_medals,12,0,12,12,DIMAGE_NONE);
if(frame_level/FPS < (unsigned int)(time*2) || (frame_level/FPS <= (unsigned int)(time*2) &&
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*2)*100-(int)(time*2)*100))) dimage(320,8,&img_bronze);
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*2)*100-(int)(time*2)*100))) dsubimage(x,y,&img_medals,0,0,12,12,DIMAGE_NONE);
}
void draw_time(int id_level)
{
dclear(C_WHITE);
float time=1.0;
float level_time[] = {5.81,8.38,5.89,8.68,3.84,3.58,6.81,7.48,10.46,9.25,6.48,11.94,5.68};
float level_time[] = {5.91,8.76,5.89,3.58,3.84,8.45,6.92,7.68,10.46,9.25,6.48,11.94,5.68};
time = level_time[id_level-1];
dimage(160,90,&img_createur);
dprint(175,90,C_BLACK,"%.2j",(int)(time*100));
dimage(160,110,&img_or);
dprint(175,110,C_BLACK,"%.2j",(int)(time*1.2*100));
dimage(160,130,&img_argent);
dprint(175,130,C_BLACK,"%.2j",(int)(time*1.5*100));
dimage(160,150,&img_bronze);
dprint(175,150,C_BLACK,"%.2j",(int)(time*2*100));
dsubimage(172,90,&img_medals,36,0,12,12,DIMAGE_NONE);
dprint(187,90,C_BLACK,"%.2j",(int)(time*100));
dsubimage(172,110,&img_medals,24,0,12,12,DIMAGE_NONE);
dprint(187,110,C_BLACK,"%.2j",(int)(time*1.2*100));
dsubimage(172,130,&img_medals,12,0,12,12,DIMAGE_NONE);
dprint(187,130,C_BLACK,"%.2j",(int)(time*1.5*100));
dsubimage(172,150,&img_medals,0,0,12,12,DIMAGE_NONE);
dprint(187,150,C_BLACK,"%.2j",(int)(time*2*100));
dupdate();
getkey();
}

31
time.py
View File

@ -12,11 +12,8 @@ d.write("#include \"times.h\"\n\
#include \"define.h\"\n\
#include <gint/display.h>\n\
#include <gint/keyboard.h>\n\n\
extern bopti_image_t img_bronze;\n\
extern bopti_image_t img_argent;\n\
extern bopti_image_t img_or;\n\
extern bopti_image_t img_createur;\n\n\
void check_medal(unsigned int frame_level, int id_level)\n\
extern bopti_image_t img_medals;\n\
void check_medal(unsigned int frame_level, int id_level, int x, int y)\n\
{\n\
float time=1.0;\n\
float framefloat = frame_level;\n\
@ -26,13 +23,13 @@ d.write(f"{','.join(times)}")
d.write("};\ntime = level_time[id_level-1];\n\n\
if(frame_level/FPS < (unsigned int)time || (frame_level/FPS <= (unsigned int)time && \n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time)*100-(int)(time)*100))) dimage(380,8,&img_createur);\n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time)*100-(int)(time)*100))) dsubimage(x+45,y,&img_medals,36,0,12,12,DIMAGE_NONE);\n\
if(frame_level/FPS < (unsigned int)(time*"+str(gold)+") || (frame_level/FPS <= (unsigned int)(time*"+str(gold)+") && \n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(gold)+")*100-(int)(time*"+str(gold)+")*100))) dimage(360,8,&img_or);\n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(gold)+")*100-(int)(time*"+str(gold)+")*100))) dsubimage(x+30,y,&img_medals,24,0,12,12,DIMAGE_NONE);\n\
if(frame_level/FPS < (unsigned int)(time*"+str(argent)+") || (frame_level/FPS <= (unsigned int)(time*"+str(argent)+") && \n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(argent)+")*100-(int)(time*"+str(argent)+")*100))) dimage(340,8,&img_argent);\n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(argent)+")*100-(int)(time*"+str(argent)+")*100))) dsubimage(x+15,y,&img_medals,12,0,12,12,DIMAGE_NONE);\n\
if(frame_level/FPS < (unsigned int)(time*"+str(bronze)+") || (frame_level/FPS <= (unsigned int)(time*"+str(bronze)+") && \n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(bronze)+")*100-(int)(time*"+str(bronze)+")*100))) dimage(320,8,&img_bronze);\n\
(unsigned int)((framefloat)/FPS*100-frame_level/FPS*100) <= (unsigned int)((time*"+str(bronze)+")*100-(int)(time*"+str(bronze)+")*100))) dsubimage(x,y,&img_medals,0,0,12,12,DIMAGE_NONE);\n\
}\n\
\n\
void draw_time(int id_level)\n\
@ -44,14 +41,14 @@ float level_time[] = {")
d.write(f"{','.join(times)}")
d.write("};\ntime = level_time[id_level-1];\n\n\
dimage(160,90,&img_createur);\n\
dprint(175,90,C_BLACK,\"%.2j\",(int)(time*100));\n\
dimage(160,110,&img_or);\n\
dprint(175,110,C_BLACK,\"%.2j\",(int)(time*"+str(gold)+"*100));\n\
dimage(160,130,&img_argent); \n\
dprint(175,130,C_BLACK,\"%.2j\",(int)(time*"+str(argent)+"*100));\n\
dimage(160,150,&img_bronze); \n\
dprint(175,150,C_BLACK,\"%.2j\",(int)(time*"+str(bronze)+"*100));\n\
dsubimage(172,90,&img_medals,36,0,12,12,DIMAGE_NONE);\n\
dprint(187,90,C_BLACK,\"%.2j\",(int)(time*100));\n\
dsubimage(172,110,&img_medals,24,0,12,12,DIMAGE_NONE);\n\
dprint(187,110,C_BLACK,\"%.2j\",(int)(time*"+str(gold)+"*100));\n\
dsubimage(172,130,&img_medals,12,0,12,12,DIMAGE_NONE); \n\
dprint(187,130,C_BLACK,\"%.2j\",(int)(time*"+str(argent)+"*100));\n\
dsubimage(172,150,&img_medals,0,0,12,12,DIMAGE_NONE); \n\
dprint(187,150,C_BLACK,\"%.2j\",(int)(time*"+str(bronze)+"*100));\n\
dupdate();\n\
getkey();\n\
}")

View File

@ -1,11 +1,11 @@
5.81
8.38
5.91
8.76
5.89
8.68
3.84
3.58
6.81
7.48
3.84
8.45
6.92
7.68
10.46
9.25
6.48