fix player clip glitch thanks to KikooDX

This commit is contained in:
Tituya 2021-06-14 19:27:21 +02:00
parent 0e51573101
commit fe496f10ea
11 changed files with 100 additions and 100 deletions

3
.gitignore vendored
View File

@ -9,3 +9,6 @@ generated/
# fxlink screenshots
fxlink-*.png
# pictures
pictures/

View File

@ -51,7 +51,7 @@ def place():
if gravityid==7: levelgr = font.render("",1,(0,120,120))
timeapp = font.render("A="+str(app),1,(255,230,0))
timedisa = font.render("D="+str(disa)+" LOCK : "+str(lock),1,(255,180,0))
nbswitchfont = font.render("Nb="+str(nbswitch),1,(255,230,0))
nbswitchfont = font.render("Nb="+str(nbswitchmax),1,(255,230,0))
for a in range(14):
for b in range(25):
pygame.draw.rect(fenetre,(255,255,255),((52*b, 52*a), (52, 52)))

View File

@ -13,17 +13,18 @@ Pour ouvrir (python3 + pygame):
- S baisser temps avant apparition blocs +
- R augmenter temps avant disparition blocs - (temps affiché en haut à gauche)
- F baisser temps avant disparition blocs -
- T augmenter le nombre de switch possibles dans le niveau (nécessite le bloc d'activation)
- G baisser le nombre de switch possibles dans le niveau
- SHIFT changer le sens de la gravité par défaut (gravité affichée en haut à gauche)
- TAB Afficher le design des blocs non activé
- A supprime le bloc bloqué dans la main.
- N pour reset la pièce en entier
Click gauche : tourner parmis les blocs dans le sens horaire
Click droit : tourner parmis les blocs dans le sens anti-horaire
Click gauche : tourner parmis les blocs
Click droit : supprimer le bloc
Click molette centrale sur un bloc : bloquer ce bloc dans la main, permet de placer plusieurs fois le même bloc rapidement. (bloc bloqué affiché en haut)
Click gauche après molette : placer le bloc
Click droit après molette : supprimer le bloc
## Sauvegarde :
@ -31,4 +32,4 @@ L'éditeur sauvegarde automatiquement les niveaux à chaques actions.
`$ ./build.sh` pour construire l'application depuis ces niveaux.
by Tituya
Tituya

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

@ -0,0 +1,4 @@
11111111111111111111111111000000000100000s01000001100000000010001ddd1000001100000000010000000000000110000000001000000000000011000000000100000000000001100000000010000000000000110000000000000000000000011000000000000000000000001100000000000000000000000110000000000000000000000011000e00000000000000000001100000000000000000000000111111111111111111111111117
8
10
1

3
include/menu.h Executable file → Normal file
View File

@ -5,4 +5,5 @@ enum MenuPause { MenuContinue, MenuBack };
enum MenuCode start_menu();
char level_selection(int *id_level);
enum MenuPause pause_menu(char level[], int id_level, int coin, int death_count);
enum MenuPause pause_menu(char level[], int id_level, int coin,
int death_count);

View File

@ -1,6 +1,6 @@
#pragma once
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

@ -2,4 +2,5 @@
int round(float num);
int round_sup(float num);
int rand_range(int low, int high);
int rand_range(int low, int high);
int sign(float x);

View File

@ -6,9 +6,8 @@ void mod_accel_and_fric(float *acceleration, float *friction, int x, int y,
{
*acceleration = HACCELERATION;
*friction = HFRICTION;
if(!mod_rough(acceleration, friction, x, y, level))
mod_solid(acceleration, friction, x, y, level);
if(!mod_ice(acceleration, friction, x, y, level))
if (!mod_ice(acceleration, friction, x, y, level) &&
!mod_rough(acceleration, friction, x, y, level))
mod_solid(acceleration, friction, x, y, level);
}
@ -25,8 +24,8 @@ int mod_ice(float *acceleration, float *friction, int x, int y, char level[])
int mod_rough(float *acceleration, float *friction, int x, int y, char level[])
{
if (collide(x, y - 1, level, 'r') || collide(x, y + 1, level, 'r')) {
*friction *= 3;
*acceleration *= 2;
*friction *= 3.0;
*acceleration *= 2.0;
return 1;
}
return 0;

View File

@ -1,27 +1,27 @@
/*
* @author : Tituya x KikooDX
*/
* @author : Tituya x KikooDX
*/
#include <gint/clock.h>
#include <gint/display.h>
#include <gint/gint.h>
#include <gint/keyboard.h>
#include <gint/rtc.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
#include <gint/timer.h>
#include <gint/std/stdlib.h>
#include <gint/rtc.h>
#include <gint/usb-ff-bulk.h>
#include "collide.h"
#include "define.h"
#include "drawlevel.h"
#include "friction.h"
#include "menu.h"
#include "replace.h"
#include "save.h"
#include "setlevel.h"
#include "times.h"
#include "util.h"
#include "friction.h"
#define VACCELERATION 0.2
#define MAX_VSPD 9.0
@ -30,9 +30,10 @@ static void startmenu_launcher();
static int callback(volatile int *frame_elapsed);
static void game(int *id_level, char mode, char *type);
int main(void) {
int main(void)
{
/* open USB for fxlink screenshots */
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
usb_open(interfaces, GINT_CALL_NULL);
gint_world_switch(GINT_CALL(restore));
@ -46,29 +47,32 @@ int main(void) {
return 0;
}
static void startmenu_launcher() {
static void startmenu_launcher()
{
char type = 1;
int menu_run = 1;
int id_level = 1;
while(menu_run) {
while (menu_run) {
const enum MenuCode valeur = start_menu(&type);
switch(valeur) {
case MenuLevelSel: {
int doIRun = level_selection(&id_level);
if(doIRun)
game(&id_level, 1, &type);
} break;
case MenuAllMode: {
switch (valeur) {
case MenuLevelSel: {
if (id_level == 0)
id_level = 1;
game(&id_level, 0, &type);
} break;
case MenuTutorial: {
id_level = 0;
int doIRun = level_selection(&id_level);
if (doIRun)
game(&id_level, 1, &type);
} break;
case MenuExit: {
menu_run = 0;
} break;
} break;
case MenuAllMode: {
id_level = 1;
game(&id_level, 0, &type);
} break;
case MenuTutorial: {
id_level = 0;
game(&id_level, 1, &type);
} break;
case MenuExit: {
menu_run = 0;
} break;
}
}
}
@ -165,7 +169,7 @@ static void game(int *id_level, char mode, char *type)
coin);
if (check_nbswitch)
draw_nbswitch(nbswitch);
dprint(330, 0, C_RED, "%d", (int)(hspd*100));
dprint(330, 0, C_RED, "%d", (int)(hspd * 100));
dupdate();
if (keydown(KEY_VARS) && usb_is_open())
usb_fxlink_screenshot(1);
@ -180,28 +184,23 @@ static void game(int *id_level, char mode, char *type)
// right and left movement + collision
int signe = (keydown(KEY_RIGHT) - keydown(KEY_LEFT));
mod_accel_and_fric(&acceleration, &friction, player_x, player_y, level);
hspd *= 1 - friction;
mod_accel_and_fric(&acceleration, &friction, player_x, player_y,
level);
hspd *= (1 - friction);
hspd += signe * acceleration;
/* speed reminder */
/* TODO
* Please note than `hrem` should be reset after horizontal collision
* with a wall, death or level change. This is necessary to avoid
* cross-level jank/garbage data to be carreid that would ultimatly
* introduce inconsistancies. I didn't do it myself 'cause I couldn't
* find were to do this.
* -- KikooDX */
const float spd_n_rem_x = hspd + hrem;
const int spd_x = (int)spd_n_rem_x;
hrem = spd_n_rem_x - (float)spd_x;
if (!collide_solid(player_x + round(hspd) + signe * 1,
player_y, level))
player_x += round(hspd);
else if (!collide_solid(player_x + signe * 1, player_y,
level))
player_x += signe;
player_x += spd_x;
while (collide_solid(player_x, player_y, level)) {
player_x -= sign(spd_x);
hspd = 0;
hrem = 0;
}
if (player_x >= 388)
player_x = -4;
if (player_x < -9)
@ -269,7 +268,7 @@ static void game(int *id_level, char mode, char *type)
}
// Collide with the end
if (collide_end(player_x, player_y, level)) {
//if all mode
// if all mode
if (!mode) {
*id_level += 1;
check_coin = 0;
@ -280,21 +279,21 @@ static void game(int *id_level, char mode, char *type)
hrem = 0.00;
set_level(*id_level, level, &start_x, &start_y,
&gravity, &appear, &disappear, &nbswitch);
&gravity, &appear, &disappear,
&nbswitch);
player_x = start_x;
player_y = start_y;
if (*id_level == 10 && *type == 1)
*type = 2;
*type = 2;
else if (*type != 3)
*type = 1;
//End of all mode
// End of all mode
if (*id_level == LEVEL_MAX + 1) {
timer_stop(timer);
game_loop = 0;
}
}
else {
} else {
game_loop = 0;
}
hasReachedEnd = 1;
@ -401,7 +400,6 @@ static void game(int *id_level, char mode, char *type)
// 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' || level[i] == 'h') {
@ -440,26 +438,28 @@ static void game(int *id_level, char mode, char *type)
// Pause menu
if (keydown_any(KEY_EXIT, KEY_MENU, 0)) {
timer_pause(timer);
const enum MenuPause valeur = pause_menu(level, *id_level, coin, death_count);
switch(valeur) {
case MenuContinue: {
timer_start(timer);
check = 1; //prevent for switch when back to the level
} break;
case MenuBack: {
game_loop = 0;
hasReachedEnd = 0;
} break;
const enum MenuPause valeur =
pause_menu(level, *id_level, coin, death_count);
switch (valeur) {
case MenuContinue: {
timer_start(timer);
check = 1; // prevent for switch when back to
// the level
} break;
case MenuBack: {
game_loop = 0;
hasReachedEnd = 0;
} break;
}
}
}
timer_stop(timer);
// when a level is quit
//if level selection
// if level selection
if (mode == 1 && *id_level != 0) {
if(hasReachedEnd) {
if (hasReachedEnd) {
float framefloat = framelevel;
draw_end(framelevel, *id_level, 0);
savetime(framefloat, *id_level);
@ -467,9 +467,9 @@ static void game(int *id_level, char mode, char *type)
}
int doIRun = level_selection(id_level);
if(doIRun)
if (doIRun)
game(id_level, 1, type);
} else if(mode == 0 && hasReachedEnd == 1) {
} else if (mode == 0 && hasReachedEnd == 1) {
draw_end((int)frame, LEVEL_MAX, 2);
sleep_ms(7000);
}

View File

@ -1,6 +1,5 @@
#include "menu.h"
#include "define.h"
#include "util.h"
#include "drawlevel.h"
#include "save.h"
#include "setlevel.h"
@ -23,8 +22,8 @@ enum MenuCode start_menu(char *type)
int start_x;
int start_y;
set_level(rand_range(1,LEVEL_MAX), level, &start_x, &start_y, NULL,
NULL, NULL, NULL);
set_level(rand_range(1, LEVEL_MAX), level, &start_x, &start_y, NULL,
NULL, NULL, NULL);
while (menu_loop) {
clearevents();
dclear(C_WHITE);
@ -80,8 +79,8 @@ char level_selection(int *id_level)
*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, NULL,
NULL, NULL, NULL);
set_level(*id_level, level, &start_x, &start_y, NULL, NULL,
NULL, NULL);
draw_level(level);
dimage(0, 0, &img_speedrun);
if (sto != 0)
@ -94,7 +93,7 @@ char level_selection(int *id_level)
dprint(202, 60, C_RED, "/");
draw_time(*id_level);
dupdate();
if (keydown_any(KEY_SHIFT, KEY_EXE, 0)) {
if (!check) {
del_level(level);
@ -114,8 +113,8 @@ char level_selection(int *id_level)
return 0;
}
enum MenuPause pause_menu(char level[], int id_level, int coin, int death_count) {
enum MenuPause pause_menu(char level[], int id_level, int coin, int death_count)
{
extern bopti_image_t img_speedrun;
@ -136,14 +135,10 @@ enum MenuPause pause_menu(char level[], int id_level, int coin, int death_count)
selected = 1;
dtext(32, Y_POS, C_BLACK, "CONTINUE");
dtext(32, Y_POS + 12, C_BLACK, "BACK");
dtext(16, Y_POS + (selected * 12), C_BLACK,
">");
dprint(176, 45, C_BLACK, "LEVEL : %d",
id_level);
dprint(320, 3, C_RGB(255, 178, 0), "COIN : %d",
coin);
dprint(311, 17, C_RGB(150, 16, 16),
"DEATH : %d", death_count);
dtext(16, Y_POS + (selected * 12), C_BLACK, ">");
dprint(176, 45, C_BLACK, "LEVEL : %d", id_level);
dprint(320, 3, C_RGB(255, 178, 0), "COIN : %d", coin);
dprint(311, 17, C_RGB(150, 16, 16), "DEATH : %d", death_count);
draw_time(id_level);
dupdate();
if (keydown_any(KEY_SHIFT, KEY_EXE, 0)) {

View File

@ -1,14 +1,10 @@
#include "util.h"
#include <gint/std/stdlib.h>
int round(float num) {
return (num < 0) ? (num - 0.5) : (num + 0.5);
}
int round(float num) { return (num < 0) ? (num - 0.5) : (num + 0.5); }
int round_sup(float num) {
return (int)(num+1);
}
int round_sup(float num) { return (int)(num + 1); }
int rand_range(int low, int high) {
return (rand() % (high - low)) + low;
}
int rand_range(int low, int high) { return (rand() % (high - low)) + low; }
int sign(float x) { return 1 * (x > 0) - 1 * (x < 0); }