cleanup but load fail

This commit is contained in:
Tituya 2021-05-02 16:25:22 +02:00
parent d9d29907e4
commit f1dd20fe14
12 changed files with 122 additions and 109 deletions

View File

@ -26,6 +26,7 @@ add_custom_command(
COMMAND mkdir -p generated/include && sh update_levels.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS update_levels.sh compile_levels.py
editor/levels/
editor/levels/0.lvl
editor/levels/1.lvl
editor/levels/2.lvl
@ -43,7 +44,9 @@ add_custom_command(
editor/levels/14.lvl
editor/levels/15.lvl
editor/levels/16.lvl
editor/levels/17.lvl)
editor/levels/17.lvl
editor/levels/18.lvl
editor/levels/19.lvl)
set(SOURCES
src/collide.c
@ -52,6 +55,7 @@ set(SOURCES
src/menu.c
src/save.c
src/util.c
src/replace.c
generated/setlevel.c
generated/times.c)

View File

@ -29,12 +29,12 @@ y+=16;}i++;}}\n\
void set_gravity(int id_level, char *default_gravity){\n\
switch(id_level){")
ids = 0
gravity = 0
gravity = -1
while 1:
try:
lv = open(f"editor/levels/{ids}.lvl","r")
ide = lv.read()
if ide[350]=="6": gravity=0
if ide[350]=="6": gravity=-1
else: gravity = 1
save.write(f"case {ids}:\n*default_gravity = {gravity};\nbreak;\n")
ids+=1

4
editor/levels/19.lvl Normal file
View File

@ -0,0 +1,4 @@
11111111111111111111111111000000000000000000000001i000000000000000000000001i0000iiiii11i11iiiii00001i000000000000000000000001i00S000000000000000000001i000000000000000000000001i000011111111111111100001i000000000000000000000001i000000000000000000000001i0000iiiiiiiiiiiiiii00001i000000000000000000000001i00s00000000000000000e00111111iiiiiiiiiiiiiii111116
8
10
1

View File

@ -1,4 +1,4 @@
1dddddd100111111111111111000000000011111000000000000000000l01100c00000000001aaaaaaa111100c00000000011dddddddddd1001aaaaaaaaa11cccccccccc1001ddddddddd1000000000001331000000aa000000000000s10e1k0000000001ccccccccc111111111113311100000000011001000000000110000000001100b0000000001100000000011t0b00000000011000K0000011111aaaaaaaaa1111111110011111ddddddddd16
13
1
2
1

View File

@ -1,4 +1,4 @@
11111111111011111dddd1111100001dd0000dd100000000011s0001dd0d11dd10000000001111001dd0d111dd00111100011dd001dt0d10000001dd100011dd001d11d10000001dd100011dd00dd11110011111dd100011dd00000000001dddddd100011dd1111dbd1111ddd111100011ddddddd0dd1d1ddd100000011ddddddd0000d1ddd1e0000011ddddddd1110d1ddd111cccc11dddddddddd0d1ddd111dddd111111111111011111111111116
13
13
7
1

View File

@ -4,3 +4,4 @@ char collide_dead(int x, int y, char level[]);
char collide_point(int x, int y, char level[], char block);
char collide_end(int x, int y, char level[]);
void collide_replace(int x, int y, char level[], char collide, char replace);
char collide_center(int x, int y, char level[], char block);

2
include/replace.h Normal file
View File

@ -0,0 +1,2 @@
void replace_all_block(char a, char b, char level[]);
void replace_xy_block(int x, int y, char block, char level[]);

View File

@ -1,4 +1,4 @@
void set_level(int id_level, char level[], int *startx, int *starty,
char *gravity, int *appear, int *disappear, int *nbswitch);
void set_level(int id_level, char level[], int *startx, int *starty, char *gravity,
int *appear, int *disappear, int *nbswitch);
void set_gravity(int id_level, char *default_gravity);
void del_level(char level[]);

View File

@ -69,3 +69,11 @@ void collide_replace(int x, int y, char level[], char collide, char replace)
((y + PLAYER_HEIGHT) / 16) * 25] = replace;
}
}
char collide_center(int x, int y, char level[], char block) {
if(level[(int)((x + 6) / 16) +
(int)((y + 6) / 16) * 25] == block) {
return 1;
}
return 0;
}

View File

@ -12,6 +12,7 @@
#include "save.h"
#include "setlevel.h"
#include "times.h"
#include "replace.h"
#define VACCELERATION 0.2
#define HACCELERATION 0.4
@ -85,7 +86,7 @@ static void game(int *id_level, char mode, char *type)
int framelevel = 0;
int player_x = 20, player_y = 20;
char level[351];
char gravity = 0; // 0 down 1 up
char gravity = -1; // -1 down 1 up
char check = 1;
char blackout = 0;
int start_x;
@ -104,6 +105,7 @@ static void game(int *id_level, char mode, char *type)
char check_nbswitch = 0;
float vspd = 1.0;
float hspd = 0.0;
if (*id_level == 10 && *type != 3)
*type = 2;
else if (*type != 3)
@ -111,8 +113,6 @@ static void game(int *id_level, char mode, char *type)
extern bopti_image_t img_speedrun;
set_level(*id_level, level, &start_x, &start_y, &gravity, &appear,
&disappear, &nbswitch);
player_x = start_x;
player_y = start_y;
while (game_loop) {
while (!frame_elapsed)
sleep();
@ -153,62 +153,61 @@ static void game(int *id_level, char mode, char *type)
coin);
if (check_nbswitch)
draw_nbswitch(nbswitch);
dprint_opt(330, 0, C_RGB(255, 190, 0), C_BLACK,
DTEXT_LEFT, DTEXT_TOP, "%d",
(int)(hspd*100));
dupdate();
}
pollevent();
if (keydown(KEY_OPTN)) {
level[((player_x + 6) / 16) +
((player_y + 6) / 16) * 25] = 'd';
replace_xy_block(player_x + 6, player_y + 6, 'd', level);
death_count--;
}
// Right collision
if (keydown(KEY_RIGHT)) {
//right and left collision
if(keydown_any(KEY_RIGHT, KEY_LEFT)) {
float hbuff = 0.0;
char signe = (keydown(KEY_RIGHT) - keydown(KEY_LEFT));
if(collide(player_x, player_y-1, level, 'i') ||
collide(player_x, player_y+1, level, 'i')) {
hbuff += 0.12;
}
hspd *= 1 - FRICTION;
hspd += (keydown(KEY_RIGHT) - keydown(KEY_LEFT)) *
HACCELERATION;
if (!collide_solid(player_x + round(hspd) + 1, player_y,
hspd += signe * (HACCELERATION+hbuff);
if (!collide_solid(player_x + round(hspd) + signe*1, player_y,
level))
player_x += round(hspd);
else if (!collide_solid(player_x + 1, player_y, level))
player_x += 1;
else if (!collide_solid(player_x + signe*1, player_y, level))
player_x += signe*1;
if (player_x >= 388)
player_x = -4;
}
// Left collision
else if (keydown(KEY_LEFT)) {
hspd *= 1 - FRICTION;
hspd += (keydown(KEY_RIGHT) - keydown(KEY_LEFT)) *
HACCELERATION;
if (!collide_solid(player_x + round(hspd) - 1, player_y,
level))
player_x += round(hspd);
else if (!collide_solid(player_x - 1, player_y, level))
player_x -= 1;
if (player_x < -9)
player_x = 384;
} else
hspd = 0;
// Action key
if (keydown(KEY_SHIFT) && !check && nbswitch > 0 &&
/*if (keydown(KEY_SHIFT) && !check && nbswitch > 0 &&
((collide_solid(player_x, player_y - 1, level) &&
gravity) ||
(collide_solid(player_x, player_y + 1, level) &&
!gravity))) {
gravity == -1))) {
vspd = 1;
if (!gravity)
if (gravity == -1)
gravity = 1;
else
gravity = 0;
gravity = -1;
if (check_nbswitch && nbswitch > 0) {
nbswitch -= 1;
}
check = 1;
} else if (!keydown(KEY_SHIFT) && check)
check = 0;
check = 0;*/
/*
// Gravity
if (!gravity) {
if (gravity == -1) {
if (!collide_solid(player_x, player_y + (int)vspd + 1,
level)) {
if (vspd < MAX_VSPD)
@ -248,7 +247,24 @@ static void game(int *id_level, char mode, char *type)
player_y -= 1;
} else
vspd = 1;
}
}*/
/*if (!collide_solid(player_x, player_y + (int)vspd + gravity, level)) {
if (vspd < MAX_VSPD)
vspd += VACCELERATION;
if (collide(player_x + 1, player_y, level, 'i') ||
collide(player_x - 1, player_y, level, 'i'))
vspd += 0.15;
player_y += ((int)vspd) * gravity;
} else if (!collide_solid(player_x, player_y + (int)vspd + gravity, level)) {
vspd -= VACCELERATION;
player_y += ((int)vspd) * gravity;
} else if (!collide_solid(player_x, player_y + gravity, level)) {
vspd = 1;
player_y += 1 * gravity;
} else
vspd = 1;*/
// Collide with red block
if (collide_dead(player_x, player_y, level)) {
vspd = 1;
@ -257,8 +273,8 @@ static void game(int *id_level, char mode, char *type)
if (check_coin)
coin--;
check_coin = 0;
set_level(*id_level, level, &start_x, &start_y,
&gravity, &appear, &disappear, &nbswitch);
set_level(*id_level, level, &start_x, &start_y, &gravity,
&appear, &disappear, &nbswitch);
blackout = 0;
check_nbswitch = 0;
death_count++;
@ -274,8 +290,8 @@ static void game(int *id_level, char mode, char *type)
else
break;
check_coin = 0;
set_level(*id_level, level, &start_x, &start_y,
&gravity, &appear, &disappear, &nbswitch);
set_level(*id_level, level, &start_x, &start_y, &gravity,
&appear, &disappear, &nbswitch);
player_x = start_x;
player_y = start_y;
check_nbswitch = 0;
@ -294,65 +310,41 @@ static 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++) {
if (level[i] == '3')
level[i] = '0';
if (level[i] == 'k')
level[i] = '0';
}
replace_all_block('3','0', level);
replace_all_block('k','0', level);
}
if (collide(player_x, player_y, level,
'K')) // Collide with key2 = appearance of blocks
{
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == 'a')
level[i] = '4';
if (level[i] == 'K')
level[i] = '0';
}
replace_all_block('a','4', level);
replace_all_block('K','0', level);
}
if (collide(player_x, player_y, level, 't') &&
!check_coin) // Collide with coin
{
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == 't') {
level[i] = '0';
break;
}
}
replace_all_block('t','0', level);
check_coin = 1;
coin++;
}
if (collide(player_x, player_y, level,
'b')) // Collide with blackout block
{
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == 'b') {
level[i] = '0';
break;
}
}
replace_all_block('b','0', level);
blackout = 1;
}
if (collide(player_x, player_y, level,
'z')) // Collide with nbswitch block
{
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == 'z') {
level[i] = '0';
}
}
replace_all_block('z','0', level);
check_nbswitch = 1;
}
if (level[((player_x + 6) / 16) + ((player_y + 6) / 16) * 25] ==
'l') // Collide with change block
if(collide_center(player_x, player_y, level, 'l')) // Collide with change block
{
int x = 0;
int y = 0;
char level2[351] = {0};
int j = 0;
level[((player_x + 6) / 16) +
((player_y + 6) / 16) * 25] = 'P';
replace_xy_block(player_x+6, player_y+6, 'P', level);
for (int i = 349; i != -1; i--) {
level2[j] = level[i];
j++;
@ -376,10 +368,10 @@ static void game(int *id_level, char mode, char *type)
}
i++;
}
if (!gravity)
if (gravity == -1)
gravity = 1;
else
gravity = 0;
gravity = -1;
chock++;
}
@ -388,14 +380,13 @@ static void game(int *id_level, char mode, char *type)
{
if (level[((player_x) / 16) +
((player_y + 25) / 16) * 25] == 'B')
level[((player_x) / 16) +
((player_y + 25) / 16) * 25] = '0';
replace_xy_block(player_x, player_y + 25, '0', level);
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';
replace_xy_block(player_x +12, player_y + 25, '0', level);
vspd = 1.0;
}
if (collide(player_x, player_y - (int)vspd - 2, level, 'B') &&
@ -424,46 +415,36 @@ static void game(int *id_level, char mode, char *type)
double_check) // Appear block
{
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == 'y') {
double_check = 1;
break;
} else if (level[i] == 'h') {
if (level[i] == 'y' || level[i] == 'h') {
double_check = 1;
break;
} else
double_check =
0; // This loop is executed only
double_check = 0; // This loop is executed only
// when an h or y is on the level
}
for (int i = 0; level[i] != '\0'; ++i) {
if (level[i] == 'y') {
level[i] = 'H';
}
}
replace_all_block('y','H', level);
}
if (level[((player_x + 6) / 16) + ((player_y + 6) / 16) * 25] ==
'S') // Switch block
if (collide_center(player_x, player_y, level, 'S')) // Switch block
{
level[((player_x + 6) / 16) +
((player_y + 6) / 16) * 25] = '0';
replace_xy_block(player_x + 6, player_y + 6, '0', level);
vspd = 1.0;
if (!gravity)
if (gravity == -1)
gravity = 1;
else
gravity = 0;
gravity = -1;
}
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 ((framelevel / FPS) > disappear-1)
{
replace_all_block('c','0',level);
}
if ((framelevel / FPS) > appear-1)
{
replace_all_block('m','C',level);
}
//warp
if (player_y >= 212)
player_y = -4;
if (player_y < -6)
@ -494,7 +475,7 @@ static void game(int *id_level, char mode, char *type)
"SPEEDRUN MENU");
dtext(16, Y_POS + (selected * 12), C_BLACK,
">");
dprint(180, 45, C_RGB(83, 255, 0), "LEVEL : %d",
dprint(180, 45, C_BLACK, "LEVEL : %d",
*id_level);
dprint(320, 3, C_RGB(255, 178, 0), "COIN : %d",
coin);

View File

@ -53,7 +53,7 @@ enum MenuCode start_menu(char *type)
char speed_menu(int *id_level)
{
char level[351];
char gravity = 0; // 0 down 1 up
char gravity = -1; // -1 down 1 up
int start_x;
int start_y;
char buffer = 1;
@ -84,6 +84,7 @@ char speed_menu(int *id_level)
dtext(340, 214, C_BLACK, "TIMES");
dtext(190, 45, C_BLACK, "Time : ");
dprint(80, 20, C_BLACK, "Level : %d", *id_level);
dprint(80, 50, C_RED, "%d", gravity);
if (sto != 0)
dprint(194, 60, C_RED, "%.2j", sto);
else

12
src/replace.c Normal file
View File

@ -0,0 +1,12 @@
#include "replace.h"
void replace_all_block(char a, char b, char level[]) {
for (int i = 0; level[i] != '\0'; i++) {
if (level[i] == a)
level[i] = b;
}
}
void replace_xy_block(int x, int y, char block, char level[]) {
level[(x/16)+((y/16)*25)] = block;
}