Visual clean up

Indentation, formatting, trailing whitespaces, much fun.
Please configure your editor Tituya.
This commit is contained in:
KikooDX 2021-03-23 11:42:29 +01:00
parent 4ab913dac3
commit 9f76700e44
7 changed files with 112 additions and 122 deletions

View File

@ -18,7 +18,8 @@ add_custom_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS time.py times.lvl include/define.h)
add_custom_command(OUTPUT
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_LIST_DIR}/src/setlevel.c"
"${CMAKE_CURRENT_LIST_DIR}/include/define.h"
COMMENT "Generate src/setlevel.c & include/define.h"

View File

@ -3,4 +3,3 @@ int loadtime(int idlevel);
void loadfile(void);
void restore(void);
void savetimes(float framelevel, int id_level);

View File

@ -5,40 +5,40 @@
char collide(int x, int y, char level[], char block) //detect if player is in a block
{
if((level[(int)(x/16) + (int)((y + PLAYER_HEIGHT)/16) * 25] == block ||
level[(int)((x + PLAYER_HEIGHT)/16) + (int)((y + PLAYER_HEIGHT)/16) * 25] == block ||
level[(int)(x/16) + (int)((y/16) * 25)] == block ||
if((level[(int)(x/16) + (int)((y + PLAYER_HEIGHT)/16) * 25] == block ||
level[(int)((x + PLAYER_HEIGHT)/16) + (int)((y + PLAYER_HEIGHT)/16) * 25] == block ||
level[(int)(x/16) + (int)((y/16) * 25)] == block ||
level[(int)((x + PLAYER_HEIGHT)/16) + (int)((y/16) * 25)] == block)) return 1;
return 0;
}
char collide_solid(int x, int y, char level[])
{
return collide(x, y, level, '1')
|| collide(x, y, level, '3')
|| collide(x, y, level, '4')
|| collide(x, y, level, 'c')
|| collide(x, y, level, 'C')
|| collide(x, y, level, 'B')
|| collide(x, y, level, 'i')
|| collide(x, y, level, 'H');
return collide(x, y, level, '1') ||
collide(x, y, level, '3') ||
collide(x, y, level, '4') ||
collide(x, y, level, 'c') ||
collide(x, y, level, 'C') ||
collide(x, y, level, 'B') ||
collide(x, y, level, 'i') ||
collide(x, y, level, 'H');
}
char collide_dead(int x, int y, char level[])
{
return collide_point(x + DEAD_COLLISION, y + DEAD_COLLISION, level, 'd') ||
collide_point(x + PLAYER_HEIGHT - DEAD_COLLISION, y + DEAD_COLLISION, level, 'd') ||
collide_point(x + DEAD_COLLISION, y + PLAYER_HEIGHT - DEAD_COLLISION, level, 'd') ||
collide_point(x + PLAYER_HEIGHT - DEAD_COLLISION, y + PLAYER_HEIGHT - DEAD_COLLISION, level, 'd') ||
collide_point(x + 1, y + 1, level, 'C') ||
collide_point(x + PLAYER_HEIGHT - 1, y + 1, level, 'C') ||
collide_point(x + 1, y + PLAYER_HEIGHT - 1, level, 'C') ||
collide_point(x + PLAYER_HEIGHT - 1, y + PLAYER_HEIGHT - 1, level, 'C');
return collide_point(x + DEAD_COLLISION, y + DEAD_COLLISION, level, 'd') ||
collide_point(x + PLAYER_HEIGHT - DEAD_COLLISION, y + DEAD_COLLISION, level, 'd') ||
collide_point(x + DEAD_COLLISION, y + PLAYER_HEIGHT - DEAD_COLLISION, level, 'd') ||
collide_point(x + PLAYER_HEIGHT - DEAD_COLLISION, y + PLAYER_HEIGHT - DEAD_COLLISION, level, 'd') ||
collide_point(x + 1, y + 1, level, 'C') ||
collide_point(x + PLAYER_HEIGHT - 1, y + 1, level, 'C') ||
collide_point(x + 1, y + PLAYER_HEIGHT - 1, level, 'C') ||
collide_point(x + PLAYER_HEIGHT - 1, y + PLAYER_HEIGHT - 1, level, 'C');
}
char collide_point(int x, int y, char level[], char block)
{
return (level[(int)(x/16) + (int)(y/16) * 25] == block);
return (level[x / 16 + (y / 16) * 25] == block);
}
char collide_end(int x, int y, char level[])
@ -50,18 +50,18 @@ void collide_replace(int x, int y, char level[], char collide, char replace)
{
if(collide_point(x, y, level, collide))
{
level[((x)/16)+((y)/16)*25] = replace;
level[(x / 16) + (y / 16) * 25] = replace;
}
if(collide_point(x + PLAYER_HEIGHT, y, level, collide))
{
level[((x + PLAYER_HEIGHT)/16)+((y)/16)*25] = replace;
level[((x + PLAYER_HEIGHT) / 16) + (y / 16) * 25] = replace;
}
if(collide_point(x, y + PLAYER_HEIGHT, level, collide))
{
level[((x)/16)+((y + PLAYER_HEIGHT)/16)*25] = replace;
level[(x / 16) + ((y + PLAYER_HEIGHT) / 16) * 25] = replace;
}
if(collide_point(x + PLAYER_HEIGHT, y + PLAYER_HEIGHT, level, collide))
{
level[((x + PLAYER_HEIGHT)/16)+((y + PLAYER_HEIGHT)/16)*25] = replace;
level[((x + PLAYER_HEIGHT) / 16) + ((y + PLAYER_HEIGHT) / 16) * 25] = replace;
}
}

View File

@ -27,7 +27,7 @@ extern bopti_image_t img_new;
void draw_player(int x, int y, char type)
{
dsubimage(x,y,&img_player, 12*(type-1),0,12,12, DIMAGE_NONE);
dsubimage(x, y, &img_player, 12 * (type - 1), 0, 12, 12, DIMAGE_NONE);
}
void draw_level(char level[])
@ -36,74 +36,73 @@ void draw_level(char level[])
unsigned int x = 0;
unsigned int y = 0;
unsigned int i = 0;
while (i!=strlen(level))
while (i !=strlen(level))
{
switch(level[i])
{
case '1': //solid block
dimage(x,y,&img_solid);
dimage(x, y, &img_solid);
break;
case 't': //coin (treasure)
dimage(x,y,&img_coin);
dimage(x, y, &img_coin);
break;
case 'd': //dead block
dimage(x,y,&img_dead);
dimage(x, y, &img_dead);
break;
case 'e': //end of level
dimage(x,y,&img_end);
dimage(x, y, &img_end);
break;
case '3': //block link to the key1
dsubimage(x,y,&img_key1,0,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_key1, 0, 0, 16, 16, DIMAGE_NONE);
break;
case 'k': //key1
dsubimage(x,y,&img_key1,16,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_key1, 16, 0, 16, 16, DIMAGE_NONE);
break;
case 'a': //block link to the key2 when it's not on
dsubimage(x,y,&img_key2,0,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_key2, 0, 0, 16, 16, DIMAGE_NONE);
break;
case '4': //block link to the key2
dsubimage(x,y,&img_key2,16,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_key2, 16, 0, 16, 16, DIMAGE_NONE);
break;
case 'K': //key2
dsubimage(x,y,&img_key2,32,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_key2, 32, 0, 16, 16, DIMAGE_NONE);
break;
case 'c': //chrono blocks
dimage(x,y,&img_chrono1);
dimage(x, y, &img_chrono1);
break;
case 'C': //chrono blocks
dsubimage(x,y,&img_chrono2,16,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_chrono2, 16, 0, 16, 16, DIMAGE_NONE);
break;
case 'b': //blackout blocks
dimage(x,y,&img_blackout);
dimage(x, y, &img_blackout);
break;
case 'B': //damaged block
dimage(x,y,&img_damaged);
dimage(x, y, &img_damaged);
break;
case 'l': //chock blocks
dimage(x,y,&img_chock);
dimage(x, y, &img_chock);
break;
case 'i': //chock blocks
dimage(x,y,&img_ice);
dimage(x, y, &img_ice);
break;
case 'S': //chock blocks
dimage(x,y,&img_switch);
dimage(x, y, &img_switch);
break;
case 'h': //void appear blocks
dsubimage(x,y,&img_appear,0,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_appear, 0, 0, 16, 16, DIMAGE_NONE);
break;
case 'H': //appear blocks
dsubimage(x,y,&img_appear,16,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_appear, 16, 0, 16, 16, DIMAGE_NONE);
break;
case 'y': //appear blocks
dsubimage(x,y,&img_appear,0,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_appear, 0, 0, 16, 16, DIMAGE_NONE);
break;
case 'm': //chronoappear blocks
dsubimage(x,y,&img_chrono2,0,0,16,16,DIMAGE_NONE);
dsubimage(x, y, &img_chrono2, 0, 0, 16, 16, DIMAGE_NONE);
break;
}
x+=16;
if(x==16*25)
{
x += 16;
if(x==16*25) {
x=0;
y+=16;
}
@ -113,35 +112,32 @@ void draw_level(char level[])
void draw_blackout(int x, int y)
{
x+=5;
y+=5;
drect(0, 0, 395, y-VISIBLE_RECT, C_BLACK); //top rect
drect(0, y-VISIBLE_RECT, x-VISIBLE_RECT, y+VISIBLE_RECT, C_BLACK); //left rect
drect(x+VISIBLE_RECT, y-VISIBLE_RECT, 395, y+VISIBLE_RECT, C_BLACK); //right rect
drect(0, y+VISIBLE_RECT, 395, 223, C_BLACK); //bottom rect
x += 5;
y += 5;
drect(0, 0, 395, y - VISIBLE_RECT, C_BLACK); //top rect
drect(0, y - VISIBLE_RECT, x - VISIBLE_RECT, y + VISIBLE_RECT, C_BLACK); //left rect
drect(x + VISIBLE_RECT, y - VISIBLE_RECT, 395, y + VISIBLE_RECT, C_BLACK); //right rect
drect(0, y + VISIBLE_RECT, 395, 223, C_BLACK); //bottom rect
}
void draw_timer(unsigned int frame)
{
float framefloat = frame;
dprint_opt(0, 0, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%.2j", (int)(framefloat/FPS*100));
dprint_opt(0, 0, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%.2j", (int)(framefloat / FPS * 100));
}
void draw_end(int framelevel, int id_level, char record)
{
float framefloat = framelevel;
dimage(144,60,&img_endscreen);
if(record!=2)
{
dimage(144, 60, &img_endscreen);
if(record != 2) {
dprint_opt(220, 115, C_WHITE, C_BLACK, DTEXT_LEFT, DTEXT_TOP, "%d", framelevel);
dprint(166, 87, C_RED, "%.2j",(int)(framefloat/FPS*100));
dprint(166, 87, C_RED, "%.2j",(int)(framefloat / FPS * 100));
check_medal(framelevel, id_level, 178, 140);
if(record==1) dimage(60,100,&img_new);
}
else
{
if(record == 1) dimage(60, 100 ,&img_new);
} else {
dprint(166, 87, C_RED, "GG !");
dprint(178, 140, C_RED, "%.2j",(int)(framefloat/FPS*100));
dprint(178, 140, C_RED, "%.2j",(int)(framefloat / FPS * 100));
}
dupdate();
}

View File

@ -23,8 +23,8 @@ void end(unsigned int frame);
int callback(volatile int *frame_elapsed)
{
*frame_elapsed = 1;
return TIMER_CONTINUE;
*frame_elapsed = 1;
return TIMER_CONTINUE;
}
void game(int *id_level, char mode, char *type)
@ -32,7 +32,7 @@ void game(int *id_level, char mode, char *type)
volatile int frame_elapsed = 1;
int timer = timer_setup(TIMER_ANY, 1000000/FPS, callback, &frame_elapsed);
timer_start(timer);
char game_loop = 1;
unsigned int frame = 0;
int framelevel = 0;
@ -44,14 +44,14 @@ void game(int *id_level, char mode, char *type)
int start_x;
int start_y;
int death_count = 0;
int coin = 0;
char check_coin = 0;
char double_check = 1;
int appear = 10;
int disappear = 13;
float vspd = 1.0;
float hspd = 0.0;
if(*id_level==10 && *type!=3) *type = 2;
@ -65,7 +65,7 @@ void game(int *id_level, char mode, char *type)
{
while(!frame_elapsed) sleep();
frame_elapsed = 0;
frame++;
framelevel++;
if(!(frame%2))
@ -75,7 +75,7 @@ void game(int *id_level, char mode, char *type)
draw_player(player_x, player_y, *type);
if(!mode) draw_timer(frame);
else draw_timer(framelevel);
if(*id_level==0 && !mode)
{
dprint(85,180,C_RGB(245,245,0),"SHIFT");
@ -87,10 +87,10 @@ void game(int *id_level, char mode, char *type)
if(!mode) dprint_opt(330, 0, C_RGB(255,190,0), C_BLACK, DTEXT_LEFT, DTEXT_TOP, "Coin : %d", coin);
dupdate();
}
pollevent();
if(keydown(KEY_OPTN))
{
level[((player_x+6)/16)+((player_y+6)/16)*25] = 'd';
@ -180,8 +180,8 @@ void game(int *id_level, char mode, char *type)
death_count++;
double_check = 1;
framelevel = 0;
if(*id_level == 1 && !mode)
frame = 0;
if(*id_level == 1 && !mode)
frame = 0;
}
//Collide with the end
if(collide_end(player_x, player_y, level))
@ -205,7 +205,7 @@ void game(int *id_level, char mode, char *type)
}
if(collide(player_x, player_y, level, 'k')) //Collide with key1 = disappearance of blocks
{
for (int i = 0; level[i]!='\0' ; i++)
for (int i = 0; level[i]!='\0' ; i++)
{
if(level[i]=='3') level[i]='0';
if(level[i]=='k') level[i]='0';
@ -213,7 +213,7 @@ void game(int *id_level, char mode, char *type)
}
if(collide(player_x, player_y, level, 'K')) //Collide with key2 = appearance of blocks
{
for (int i = 0; level[i]!='\0' ; i++)
for (int i = 0; level[i]!='\0' ; i++)
{
if(level[i]=='a') level[i]='4';
if(level[i]=='K') level[i]='0';
@ -221,9 +221,9 @@ void game(int *id_level, char mode, char *type)
}
if(collide(player_x, player_y, level, 't') && !check_coin) //Collide with coin
{
for (int i = 0; level[i]!='\0' ; i++)
for (int i = 0; level[i]!='\0' ; i++)
{
if(level[i]=='t')
if(level[i]=='t')
{
level[i]='0';
break;
@ -234,9 +234,9 @@ void game(int *id_level, char mode, char *type)
}
if(collide(player_x, player_y, level, 'b')) //Collide with blackout block
{
for (int i = 0; level[i]!='\0' ; i++)
for (int i = 0; level[i]!='\0' ; i++)
{
if(level[i]=='b')
if(level[i]=='b')
{
level[i]='0';
break;
@ -251,7 +251,7 @@ void game(int *id_level, char mode, char *type)
char level2[351] = { 0 };
int j = 0;
level[((player_x+6)/16)+((player_y+6)/16)*25] = 'P';
for (int i = 349; i!=-1 ; i--)
for (int i = 349; i!=-1 ; i--)
{
level2[j]=level[i];
j++;
@ -281,8 +281,8 @@ void game(int *id_level, char mode, char *type)
if(!gravity) gravity=1;
else gravity=0;
}
if(collide(player_x, player_y+(int)vspd+2, level, 'B') && vspd>=5) //Damaged block
if(collide(player_x, player_y+(int)vspd+2, level, 'B') && vspd>=5) //Damaged block
{
if(level[((player_x)/16)+((player_y+25)/16)*25]=='B') level[((player_x)/16)+((player_y+25)/16)*25]='0';
if(level[((player_x+12)/16)+((player_y+25)/16)*25]=='B' && collide_point(player_x+12, player_y+22, level, 'B')) level[((player_x+12)/16)+((player_y+25)/16)*25]='0';
@ -294,11 +294,11 @@ void game(int *id_level, char mode, char *type)
if(level[((player_x+12)/16)+((player_y-(int)vspd-2)/16)*25]=='B' && collide_point(player_x+12, player_y-12, level, 'B')) level[((player_x+12)/16)+((player_y-(int)vspd-2)/16)*25]='0';
vspd=1.0;
}
collide_replace(player_x, player_y, level, 'h', 'y'); //Appear block
if(!collide(player_x, player_y, level, 'y') && double_check) //Appear block
{
for (int i = 0; level[i]!='\0' ; i++)
for (int i = 0; level[i]!='\0' ; i++)
{
if(level[i]=='y')
{
@ -315,11 +315,9 @@ void game(int *id_level, char mode, char *type)
for (int i = 0; level[i]!='\0'; ++i)
{
if(level[i]=='y')
{
level[i]='H';
}
}
}
if(level[((player_x+6)/16)+((player_y+6)/16)*25] == 'S') //Switch block
{
@ -328,13 +326,13 @@ void game(int *id_level, char mode, char *type)
if(!gravity) gravity=1;
else gravity=0;
}
if((framelevel/FPS)>disappear) for (int i = 0; level[i]!='\0' ; i++) if(level[i]=='c') level[i]='0'; //after x seconds blocks disappear
if((framelevel/FPS)>appear) for (int i = 0; level[i]!='\0' ; i++) if(level[i]=='m') level[i]='C'; //after x seconds blocks appear
if(player_y>=212) player_y=-4;
if(player_y<-6) player_y=212;
//Menu
if(keydown_any(KEY_EXIT, KEY_MENU, 0))
{
@ -399,7 +397,7 @@ void game(int *id_level, char mode, char *type)
savetimes(framefloat, *id_level);
sleep_ms(3000);
}
if(!speed_menu(id_level))
if(!speed_menu(id_level))
{
mode = 1;
death_count = 0;
@ -418,14 +416,14 @@ void end(unsigned int frame)
}
int main(void)
{
{
char mode = 0;
char type = 1;
char valeur = start_menu(&type);
if(!valeur) //normal game (level selection)
{
int id_level = 1;
if(!speed_menu(&id_level))
if(!speed_menu(&id_level))
{
mode = 1;
game(&id_level, mode, &type);

View File

@ -8,9 +8,9 @@
#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;
}
{
return num < 0 ? num - 0.5 : num + 0.5;
}
char start_menu(char *type)
{
@ -21,11 +21,10 @@ char start_menu(char *type)
char buffer2 = 1;
int Y_POS = 85;
gint_switch(restore);
while(menu_loop)
{
while(menu_loop) {
clearevents();
dclear(C_WHITE);
dimage(0,0,&img_menu);
dimage(0, 0, &img_menu);
selection += keydown(KEY_DOWN) - keydown(KEY_UP);
if (selection == 4) selection = 0;
else if (selection == -1) selection = 3;
@ -62,28 +61,26 @@ char speed_menu(int *id_level)
char menu_loop = 1;
char check = 1;
extern bopti_image_t img_speedrun;
while(menu_loop)
{
while(menu_loop) {
clearevents();
dclear(C_WHITE);
*id_level += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
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);
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);
if(sto != 0) check_medal(round(sto*0.01*FPS), *id_level, 335, 8);
dimage(0, 0, &img_speedrun);
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, "/");
if(*id_level == 14) dprint_opt(180, 8, C_RGB(0,255,255), C_BLACK, DTEXT_LEFT, DTEXT_TOP, "VVVVVV");
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, "/");
if(*id_level == 14) dprint_opt(180, 8, C_RGB(0, 255, 255), C_BLACK, DTEXT_LEFT, DTEXT_TOP, "VVVVVV");
dupdate();
if (keydown_any(KEY_SHIFT, KEY_EXE, 0))
{
if (keydown_any(KEY_SHIFT, KEY_EXE, 0)) {
if(!check)
{
del_level(level);
@ -91,8 +88,7 @@ char speed_menu(int *id_level)
}
}
else check = 0;
if (keydown(KEY_F6))
{
if (keydown(KEY_F6)) {
draw_time(*id_level);
}
if(keydown_any(KEY_EXIT, KEY_MENU, 0)) {

View File

@ -16,7 +16,7 @@ static const uint16_t *filepath = u"\\\\fls0\\AST3.sav";
void savefile(void)
{
int descriptor;
descriptor = BFile_Open(filepath, BFile_WriteOnly);
BFile_Write(descriptor, times, sizeof(times));
BFile_Close(descriptor);
@ -41,7 +41,7 @@ void loadfile(void)
void savetimes(float framelevel, int id_level)
{
if(times[id_level - 1] > (int)(framelevel / FPS * 100) ||
times[id_level - 1] == 0 || keydown(KEY_7))
times[id_level - 1] == 0 || keydown(KEY_7))
{
times[id_level - 1] = (int)(framelevel / FPS * 100);
draw_end((int)framelevel, id_level, 1);