Fix TLB glitch + cleanup

new level 18
This commit is contained in:
Tituya 2021-05-02 20:21:41 +02:00
parent 0e4542bebe
commit af8d2f9092
34 changed files with 298 additions and 290 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
@ -51,6 +54,8 @@ set(SOURCES
src/main.c
src/menu.c
src/save.c
src/util.c
src/replace.c
generated/setlevel.c
generated/times.c)
@ -87,6 +92,6 @@ fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
add_executable(${PROJECT_NAME} ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_compile_options(${PROJECT_NAME} PRIVATE ${FLAGS})
target_link_libraries(${PROJECT_NAME} Gint::Gint)
target_link_options(${PROJECT_NAME} PRIVATE -Wl,-Map=map)
generate_g3a(TARGET ${PROJECT_NAME} OUTPUT "${PROJECT_NAME}.g3a"
NAME "${PROJECT_NAME}" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png)

View File

@ -7,8 +7,7 @@ while 1:
try:
lv = open(f"editor/levels/{ids}.lvl","r")
ide = lv.readlines()
if ide[1]!='\n':
save.write(f"case {ids}:\nmemcpy(level,\"{str(ide[0][:-2])}\",350);\n*appear={ide[1][:-1]};\n*disappear={ide[2]};\n*nbswitch={ide[3]};\nbreak;\n")
save.write(f"case {ids}:\nmemcpy(level,\"{str(ide[0][:-2])}\",350);\n*appear={ide[1][:-1]};\n*disappear={ide[2][:-1]};\n*nbswitch={ide[3]};\nbreak;\n")
ids+=1
except FileNotFoundError:
lv.close()
@ -30,13 +29,13 @@ 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
else: gravity = 1
if ide[350]=="6": gravity=1
else: gravity = -1
save.write(f"case {ids}:\n*default_gravity = {gravity};\nbreak;\n")
ids+=1
except FileNotFoundError:

View File

@ -107,12 +107,15 @@ def place():
fenetre.blit(levelgr, (10, 60))
fenetre.blit(timeapp, (55, 10))
fenetre.blit(timedisa, (140, 10))
fenetre.blit(nbswitchfont, (370, 10))
if "z" in str(grille):
fenetre.blit(nbswitchfont, (370, 10))
if id_level==0 : fenetre.blit(font.render("NIVEAU DE TEST",1,(0,180,255)), (600,10))
pygame.display.flip()
def write():
global nbswitch
f = open(f"editor/levels/{id_level}.lvl","w+")
if "z" not in str(grille): nbswitch = 1
f.write(str(grille).replace("]","").replace("(","").replace(")","").replace("'","").replace("[","").replace(" ","").replace(",","")+f"{gravityid}\n{app}\n{disa}\n{nbswitch}")
f.close()
@ -130,7 +133,7 @@ id_level = 0
gravityid = 6
disa = 10
app = 13
nbswitch = -1
nbswitch = 1
lock=""
tab = 0
@ -190,12 +193,12 @@ while securite==False:
disa-=1
write()
place()
if carac == "t":
if carac == "t" and "z" in str(grille):
nbswitch+=1
write()
place()
if carac == "g":
if nbswitch >= 0: nbswitch-=1
if carac == "g" and "z" in str(grille):
if nbswitch > 0: nbswitch-=1
write()
place()
if carac == "a":

View File

@ -1,4 +1,4 @@
11111111111111111111000111000000000000000000000001100000000000000000000000110e00000b0000l000S000000111111aaaaaaa11111111111111ddd1ddddddd1mmm1000000011ddd111111111mmm1000000011ddd111111111ccc101BB00011ddd1ddddddd1ccc10i00000111111aaaaaaa111110i000001100000000000030010i0000011000000000000300h0i1BBB111s000K00000k0300h0i0000011111111ddd1111111111000116
13
10
-1
6
9
1

View File

@ -1,4 +1,4 @@
10011111111dddd1111111111000111100000000000000000000011110011111111ddd100001111111001dd000ddddd111111111111001dd0t0ddddddddd11000001001dd000ddddddddd11000001001aaaaaaaaaaaaaa110s00010010000000000000e11d1100100100000000000aaa11111001001000000000ddddd1111100100100000000011111100010000010000000003000000001000001000K0000030k00010011111111111111111111116
13
11
10
-1
1

View File

@ -1,4 +1,4 @@
11111111t133111111100011111111111133311111110K01111100000100111111111000111110s00010i11111100000001111d110K10i11111d000000011111110K10i1111a001BBBBB11110000010i111d0a010000011110000010i11a03011d0ddd1111001ddd0i1d0a0d110000011110000000i0a30111100e00111100000k0130ad11110aa001111dd000001031111111ddd11111111111B1001111111aaa11111111111010011111110001116
13
10
-1
1

View File

@ -1,4 +1,4 @@
1ddddddddddd11dddddddddd11dddddddddd00000dd3aaa11i1dd111100000000000030000i1dd000000000001110003000i1d000001111100K000003000i1d00000S00k0000000003aBB110s000100000ddd011103atl11111331ddddddddddddddd1111ddd001dddddddd11d0S0ddd11ddd00d1dd11d000300000dd11ddd000000000000300000dd11dddaaa00000000d3S00e0dd11dddddd00S0d111d3d000ddd11ddddddddddddddddddddddd16
13
10
-1
1

View File

@ -1,4 +1,4 @@
1111111111010001dd11111110000001000013331001000000000000100t01000h0010000001111iB111111000h0013311111e00ik11d111000300300000d10ddi011d0010003003000s0d10aai01000010001hh1hh11111000i01h1h1100010010000011dd0i000000h00010010001a11aa01dd0dd110001001000h0110001dd1d1110S0100100010110000S0S0001ddd100h0001Kd100000S0S001111100h00011111111dddd10h00011111111116
13
10
-1
1

View File

@ -1,4 +1,4 @@
11111111111111111111111111ddddddddd0S00ddddddddddd1ddddaaaaa000000ddddddddd1ddd00S000000e0ddd0dddddd1dd000000ddddddd00000dddd1daaaa00dd11100S00S000ddd10000000d00000000000S00dd10K000h0d00001100000000dd1111000ddd000000S0d0h00dd1ddd000dd000dd000ddd000dd1dddhhdd000ddddddddd000dd1ddb00S0000100000dd0000dd1dtb00000011s000000000ddd111111d11111111111111dddd6
13
10
-1
1

View File

@ -1,4 +1,4 @@
1111111111111ddd11iK1d00100000d111000000011it1d00000000d100000000011i31110011100d13331110e011ihhh11100000d100011111111i00000000000d100000011111i00111011100d1000000000011000s111111111000000000011dd0001hk001111i00Sddd001dddd00hh0000001i000111000aad1ddhddd0000000001110000001111111dd0000000111000000001111111dd000011110000000001111111111111111ddd13100017
13
10
-1
1

View File

@ -1,4 +1,4 @@
i011100dd1111dddm111ddmd1i01d1000000010S0011100S01i01d100000001000000000001i01d1cc111001hh1c11111001i01ddddddi00i000bddd00001i01dd1133i00i000lddd000K1100000000i00i00001d110011300000000i00100331d100003300000010i001s03t1d1000031111100hki0011111ddd1BB1110S01hh11100m0000aaa0000110001001d100m000000000001100e1001d100m0aaa000aaa0110d11001111111ddddddddd116
13
10
-1
4
7
1

View File

@ -1,4 +1,4 @@
11111dddd100d110111111331000000000000d1d0000dd10s0111d00000000K1d10000d11111ddddd11ddhh1dddd000dddd11100Sh00dd00000dd00000001i0000000dd000000d0000S001i01100d0dd00d000dd0000001i0d00Sd0dd00dd10ddhh00l01i0ddddd0dd00ddi0d00000001iBBBdd0011aaddi0d0S00d0011000dd000300ddi0d0000d00110mmdd000d00ddi0dd00dd0011emtdddddd00ddi0ddddddkk1111111111100111Bdddd110016
13
14
10
-1
1

View File

@ -1,4 +1,4 @@
101111110111111111100111110dS00d00000001111100111110aaa0d00000K010000001111100h00d0S0000010ddaaa1111100000ddd1111110ddddd1111111a00000S1e3s00100S0111100z0000000111dda100k0100000z000000000ddddd00001000111ddaaaaa000000000101001100Saddddd0000000001010011000000aa11111111111110011000a000003000000010000011000a0a0003010000t100000110111111011111111110011117
13
10
18
19

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

@ -0,0 +1,4 @@
111111110011ddd111111111110000001000S000S0d000000110000001000000000d0000s0111mmm101aaa000000d00BBB31100m01010a0000000d00B0Bb1100m01h10a00dKdhi0i0BBB011d0m01h10a00d0d00i00B0B011d0001h10000dSd00i00d00011d00d1h10000ddd00iBBd0t01h000d101dddd11100000d000h1000d1011111111331111111130000100000ddd000000100003000110000000000000k10e00111111110011111ddd11111116
8
10
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
10
-1
2
1

View File

@ -1,4 +1,4 @@
11001111111001111111111111000111dddd000000000100013000111dddd00000000010003300000000dd11111000010e03100000000dd03a01000011111111110000dd03a01000000001100s1dd00ddt3a0100000000110001dd00dd1110100000000110001dd0Kdd00001ddd000ddd10001dd00dd00001111100ddd10001dd00dd00001000000ddd30001dd0000000010k000000330001dd0000000010000000031d001111111001111111111117
13
10
-1
1

View File

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

View File

@ -1,4 +1,4 @@
000000000000000000000000000000000000000000000000t000000000000000000000000000011dd111111111111111110000100000100000010000001000011cc001s0000d00000001000010000e111dd0100000dd100001001111000d0000000dd100001000001000111d000ddd1000010000000000000000ddd1000011111111111d111B11111000000000000000000000000000000000000000000000000000000000000000000000000000006
13
10
-1
6
1

View File

@ -1,4 +1,4 @@
10001011111011111111111111000101dd10001111dddd11110000101dd10001000000000001111101dd1aaa1000ccccddd110s00010013331000000000011dddd110010001mmmdd00000100000000010e010t0dd00000011111100011111d1dddddd1111k00000001d000111001111111111111101d00000000000111000010000100000000000000010K010000100011100000011110001000010001110000dd11110001011111011111111111117
13
10
-1
5
9
1

View File

@ -1,4 +1,4 @@
111001111111100i0d0011111100000111ddd000i0d0000001100000000000000itd00000e1111111ddd111111111111111100000000000000000h00d0000111111111dd111110100d000110001100000000010100d0001000011000000000i0d00d0000000000000000000i0d00d00001111dd111100000ild00111111000011111ddd00i0d0011111d000011111ddd00i0d0011111d0s0011111ddd00i0d0011111111001111111100i0d00111116
13
10
-1
1

View File

@ -1,4 +1,4 @@
dddddddddddddddddddddddddBBBBBBBBBBBBBBBBBBBBBBBBB100001kk10011111dt0a000011000010010010000d11a00001100001BB100100000000000013000000000010001110000000300000000001aaaaaa0000000111111000001000000001111110dd00000001000000001000110000000a001BBBd00a0100013000000000010001000010003300s000000010K0100001e003aaBBBBBBBBBBBBBBBBBBBaaaaddddddddddddddddddddddddd6
13
10
-1
1

View File

@ -1,4 +1,4 @@
00000ddddddd100000000000011111111111111111110011111000000dd1111ddd0K10000b1100111000000100000100000110000100000010000010010011000k111dd101dd00d10000011000110000001000001BBBB011000100011dd1000001dddd01100010ddd1dd1d00dd1011001133310ddd1dd1BBBBB1t00001100000ddd1dd1000001ddd1111s0000ddd1dd10000011111111BBB111aaaaa110001111111100000000000e10000000000006
13
10
-1
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);

View File

@ -1,3 +1,6 @@
char start_menu();
#pragma once
enum MenuCode { MenuLevelSel, MenuAllMode, MenuTutorial, MenuExit };
enum MenuCode start_menu();
char speed_menu(int *id_level);
int round(float num);

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[]);

3
include/util.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
int round(float num);

View File

@ -1,18 +1,22 @@
#include "collide.h"
#include "define.h"
#include "util.h"
#define DEAD_COLLISION 3 // make collision with the deadly block less effective
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] ==
if ((level[(int)(x / TILE_HEIGHT) +
(int)((y + PLAYER_HEIGHT) / TILE_HEIGHT) * LEVEL_WIDTH] ==
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))
level[(int)((x + PLAYER_HEIGHT) / TILE_HEIGHT) +
(int)((y + PLAYER_HEIGHT) / TILE_HEIGHT) * LEVEL_WIDTH] ==
block ||
level[(int)(x / TILE_HEIGHT) +
(int)((y / TILE_HEIGHT) * LEVEL_WIDTH)] == block ||
level[(int)((x + PLAYER_HEIGHT) / TILE_HEIGHT) +
(int)((y / TILE_HEIGHT) * LEVEL_WIDTH)] == block))
return 1;
return 0;
}
@ -44,7 +48,8 @@ char collide_dead(int x, int y, char level[])
char collide_point(int x, int y, char level[], char block)
{
return (level[(int)(x / 16) + (int)(y / 16) * 25] == block);
return (level[(int)(x / TILE_HEIGHT) +
(int)(y / TILE_HEIGHT) * LEVEL_WIDTH] == block);
}
char collide_end(int x, int y, char level[])
@ -55,17 +60,32 @@ char collide_end(int x, int y, char level[])
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) / TILE_HEIGHT) + ((y) / TILE_HEIGHT) * LEVEL_WIDTH] =
replace;
}
if (collide_point(x + PLAYER_HEIGHT, y, level, collide)) {
level[((x + PLAYER_HEIGHT) / 16) + ((y) / 16) * 25] = replace;
level[((x + PLAYER_HEIGHT) / TILE_HEIGHT) +
((y) / TILE_HEIGHT) * LEVEL_WIDTH] = replace;
}
if (collide_point(x, y + PLAYER_HEIGHT, level, collide)) {
level[((x) / 16) + ((y + PLAYER_HEIGHT) / 16) * 25] = replace;
level[((x) / TILE_HEIGHT) +
((y + PLAYER_HEIGHT) / TILE_HEIGHT) * LEVEL_WIDTH] =
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) / TILE_HEIGHT) +
((y + PLAYER_HEIGHT) / TILE_HEIGHT) * LEVEL_WIDTH] =
replace;
}
}
char collide_center(int x, int y, char level[], char block)
{
if (level[(int)((x + round(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) +
(int)((y + round(PLAYER_HEIGHT / 2)) / TILE_HEIGHT) *
LEVEL_WIDTH] == block) {
return 1;
}
return 0;
}

View File

@ -1,3 +1,12 @@
#include "collide.h"
#include "define.h"
#include "drawlevel.h"
#include "menu.h"
#include "replace.h"
#include "save.h"
#include "setlevel.h"
#include "times.h"
#include "util.h"
#include <gint/clock.h>
#include <gint/display.h>
#include <gint/gint.h>
@ -5,31 +14,67 @@
#include <gint/std/string.h>
#include <gint/timer.h>
#include "collide.h"
#include "define.h"
#include "drawlevel.h"
#include "menu.h"
#include "save.h"
#include "setlevel.h"
#include "times.h"
#define VACCELERATION 0.2
#define HACCELERATION 0.4
#define MAX_VSPD 9.0
#define FRICTION 0.2
int main(void);
void end(unsigned int frame);
static int callback(volatile int *frame_elapsed);
static void end(unsigned int frame);
static void game(int *id_level, char mode, char *type);
char run = 0;
int main(void)
{
static int run = 0;
if (!run) {
gint_world_switch(GINT_CALL(restore));
run = 1;
}
int callback(volatile int *frame_elapsed)
char mode = 0;
char type = 1;
const enum MenuCode valeur = start_menu(&type);
switch (valeur) {
case MenuLevelSel: {
int id_level = 1;
if (!speed_menu(&id_level)) {
mode = 1;
game(&id_level, mode, &type);
} else
main();
} break;
case MenuAllMode: {
int id_level = 1;
mode = 0;
game(&id_level, mode, &type);
} break;
case MenuTutorial: {
int id_level = 0;
mode = 1;
game(&id_level, mode, &type);
} break;
case MenuExit:
gint_world_switch(GINT_CALL(savefile));
break;
}
return 0;
}
static int callback(volatile int *frame_elapsed)
{
*frame_elapsed = 1;
return TIMER_CONTINUE;
}
void game(int *id_level, char mode, char *type)
static void end(unsigned int frame)
{
draw_end((int)frame, 15, 2);
sleep_ms(7000);
main();
}
static void game(int *id_level, char mode, char *type)
{
volatile int frame_elapsed = 1;
int timer = timer_configure(TIMER_ANY, 1000000 / FPS,
@ -41,7 +86,7 @@ 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;
@ -60,6 +105,7 @@ 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)
@ -69,7 +115,7 @@ void game(int *id_level, char mode, char *type)
&disappear, &nbswitch);
player_x = start_x;
player_y = start_y;
draw_level(level);
while (game_loop) {
while (!frame_elapsed)
sleep();
@ -112,102 +158,78 @@ void game(int *id_level, char mode, char *type)
draw_nbswitch(nbswitch);
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, 0)) {
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,
level))
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;
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 || nbswitch == -1) &&
if (keydown(KEY_SHIFT) && !check && nbswitch > 0 &&
((collide_solid(player_x, player_y - 1, level) &&
gravity) ||
gravity == -1) ||
(collide_solid(player_x, player_y + 1, level) &&
!gravity))) {
gravity))) {
vspd = 1;
if (!gravity)
if (gravity == -1)
gravity = 1;
else
gravity = 0;
if (check_nbswitch && nbswitch != 0) {
gravity = -1;
if (check_nbswitch && nbswitch > 0) {
nbswitch -= 1;
}
check = 1;
} else if (!keydown(KEY_SHIFT) && check)
check = 0;
// Gravity
if (!gravity) {
if (!collide_solid(player_x, player_y + (int)vspd + 1,
level)) {
if (vspd < MAX_VSPD)
vspd += VACCELERATION;
if (collide(player_x + 1, player_y, level, 'i'))
vspd += 0.15;
if (collide(player_x - 1, player_y, level, 'i'))
vspd += 0.15;
player_y += (int)vspd;
} else if (!collide_solid(
player_x, player_y + (int)vspd, level)) {
vspd -= VACCELERATION;
player_y += (int)vspd;
} else if (!collide_solid(player_x, player_y + 1,
level)) {
vspd = 1;
player_y += 1;
} else
vspd = 1;
} else {
if (!collide_solid(player_x, player_y - (int)vspd - 1,
level)) {
if (vspd < MAX_VSPD)
vspd += VACCELERATION;
if (collide(player_x + 1, player_y, level, 'i'))
vspd += 0.15;
if (collide(player_x - 1, player_y, level, 'i'))
vspd += 0.15;
player_y -= (int)vspd;
} else if (!collide_solid(
player_x, player_y - (int)vspd, level)) {
vspd -= VACCELERATION;
player_y -= (int)vspd;
} else if (!collide_solid(player_x, player_y - 1,
level)) {
vspd = 1;
player_y -= 1;
} else
vspd = 1;
}
// Collide with red block
// gravity
if (!collide_solid(player_x,
player_y + ((int)vspd) * gravity + 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 dead block
if (collide_dead(player_x, player_y, level)) {
vspd = 1;
player_x = start_x;
@ -236,6 +258,7 @@ void game(int *id_level, char mode, char *type)
&gravity, &appear, &disappear, &nbswitch);
player_x = start_x;
player_y = start_y;
check_nbswitch = 0;
blackout = 0;
double_check = 1;
framelevel = 0;
@ -248,68 +271,40 @@ void game(int *id_level, char mode, char *type)
end(frame);
}
}
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';
}
// Collide with key1 = disappearance of blocks
if (collide(player_x, player_y, level, 'k')) {
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';
}
// Collide with key2 = appearance of blocks
if (collide(player_x, player_y, level, 'K')) {
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;
}
}
// Collide with coin
if (collide(player_x, player_y, level, 't') && !check_coin) {
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;
}
}
// Collide with blackout block
if (collide(player_x, player_y, level, 'b')) {
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';
}
}
// Collide with nbswitch block
if (collide(player_x, player_y, level, 'z')) {
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
{
// Collide with change block
if (collide_center(player_x, player_y, level, 'l')) {
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++;
@ -326,38 +321,39 @@ void game(int *id_level, char mode, char *type)
level[i] = '0';
break;
}
x += 16;
if (x == 16 * 25) {
x += TILE_HEIGHT;
if (x == TILE_HEIGHT * LEVEL_WIDTH) {
x = 0;
y += 16;
y += TILE_HEIGHT;
}
i++;
}
if (!gravity)
if (gravity == -1)
gravity = 1;
else
gravity = 0;
gravity = -1;
chock++;
}
// Damaged block
if (collide(player_x, player_y + (int)vspd + 2, level, 'B') &&
vspd >= 5) // Damaged block
{
vspd >= 5) {
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;
}
// Damaged block
if (collide(player_x, player_y - (int)vspd - 2, level, 'B') &&
vspd >= 5) // Damaged block
{
vspd >= 5) {
if (level[((player_x) / 16) +
((player_y - (int)vspd - 2) / 16) * 25] ==
'B')
@ -375,58 +371,46 @@ void game(int *id_level, char mode, char *type)
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
{
// Appear block
collide_replace(player_x, player_y, level, 'h', 'y');
// Appear block
if (!collide(player_x, player_y, level, 'y') && double_check) {
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
// when an h or y is on the level
}
for (int i = 0; level[i] != '\0'; ++i) {
if (level[i] == 'y') {
level[i] = 'H';
}
double_check = 0;
}
replace_all_block('y', 'H', level);
}
if (level[((player_x + 6) / 16) + ((player_y + 6) / 16) * 25] ==
'S') // Switch block
{
level[((player_x + 6) / 16) +
((player_y + 6) / 16) * 25] = '0';
// Switch block
if (collide_center(player_x, player_y, level, 'S')) {
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)
player_y = 212;
// Menu
if (keydown_any(KEY_EXIT, KEY_MENU, 0)) {
char menu_loop = 1;
char selected = 0;
@ -451,7 +435,7 @@ 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);
@ -487,12 +471,10 @@ void game(int *id_level, char mode, char *type)
if (mode) {
if (*id_level == 0) {
game_loop = 0;
draw_end(framelevel, *id_level, 0);
sleep_ms(2500);
*id_level = 1;
}
if (game_loop) // end of a level with level selection
{
// end of a level with level selection
if (game_loop) {
float framefloat = framelevel;
draw_end(framelevel, *id_level, 0);
savetime(framefloat, *id_level);
@ -507,42 +489,3 @@ void game(int *id_level, char mode, char *type)
} else
main();
}
void end(unsigned int frame)
{
draw_end((int)frame, 15, 2);
sleep_ms(7000);
main();
}
int main(void)
{
if (!run) {
gint_world_switch(GINT_CALL(restore));
run = 1;
}
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)) {
mode = 1;
game(&id_level, mode, &type);
} else
main();
} else if (valeur == 1) // all mode
{
int id_level = 1;
mode = 0;
game(&id_level, mode, &type);
} else if (valeur == 2) // tutorial
{
int id_level = 0;
mode = 1;
game(&id_level, mode, &type);
} else if (valeur == 3) // exit
gint_world_switch(GINT_CALL(savefile));
return 0;
}

View File

@ -1,18 +1,15 @@
#include "menu.h"
#include "define.h"
#include "drawlevel.h"
#include "save.h"
#include "setlevel.h"
#include "times.h"
#include "util.h"
#include <gint/display.h>
#include <gint/gint.h>
#include <gint/keyboard.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)
enum MenuCode start_menu(char *type)
{
extern bopti_image_t img_menu;
char menu_loop = 1;
@ -56,7 +53,7 @@ char 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;
@ -87,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

16
src/replace.c Normal file
View File

@ -0,0 +1,16 @@
#include "replace.h"
#include "define.h"
#include <gint/keyboard.h>
void replace_all_block(char a, char b, char level[])
{
for (int i = 0; i < LEVEL_WIDTH * LEVEL_HEIGHT; i++) {
if (level[i] == a)
level[i] = b;
}
}
void replace_xy_block(int x, int y, char block, char level[])
{
level[(x / TILE_HEIGHT) + ((y / TILE_HEIGHT) * LEVEL_WIDTH)] = block;
}

3
src/util.c Normal file
View File

@ -0,0 +1,3 @@
#include "util.h"
int round(float num) { return (num < 0) ? (num - 0.5) : (num + 0.5); }

View File

@ -15,3 +15,4 @@
7.45
10.53
17.95
9.54

View File

@ -1,5 +1,8 @@
#!/bin/sh
echo "#define LEVEL_MAX $(ls editor/levels/[^0]*.lvl | wc -l)
#define PLAYER_HEIGHT 11
#define FPS 70" > generated/include/define.h
#define FPS 70
#define LEVEL_WIDTH 25
#define LEVEL_HEIGHT 14
#define TILE_HEIGHT 16" > generated/include/define.h
python3 compile_levels.py