From: parking_turkeys Date: Tue, 14 Jul 2026 20:12:34 +0000 (-0400) Subject: I HAVE SPENT FAR TOO MUCH TIME TRYING TO FIX THIS. is printf broken or smth. ... X-Git-Tag: broken~8 X-Git-Url: http://git.p-t.hackclub.app/?a=commitdiff_plain;h=0e2cd6fa472ae2fda7ec18c79d0e1f8e371eb01e;p=aichan-platformer.git I HAVE SPENT FAR TOO MUCH TIME TRYING TO FIX THIS. is printf broken or smth. help --- diff --git a/game.h b/game.h index f728229..a090eaf 100644 --- a/game.h +++ b/game.h @@ -13,7 +13,7 @@ #define SPEED 20 #define GRAVITY 20 #define FRAMELENGTH 0.1 -#define JUMPVELOCITY -40 +#define JUMPVELOCITY -90 struct character *spielersetup(void); diff --git a/physics.c b/physics.c index 0811cec..4f9c830 100644 --- a/physics.c +++ b/physics.c @@ -4,7 +4,7 @@ #include "game.h" static int gravity(float delta, struct character *player); -static int move_player(float delta, struct character *player); +int move_player(float delta, struct character *player); int physics(float delta, struct character *player) { @@ -19,18 +19,21 @@ static int gravity(float d, struct character *p) return 1; } -static int move_player(float d, struct character *p) +int move_player(float d, struct character *p) { - printf("x velocity: %d; y velocity: %d; delta: %f\n", p->velocity.x, p->velocity.y, d); + //printf("x velocity: %d; y velocity: %d; delta: %f\n", p->rect.x, p->velocity.y, d); Vector2 distance = {ceil(p->velocity.x*d), ceil(p->velocity.y*d)}; - printf("x distance: %d; y distance: %d\n", distance.x, distance.y); - int steps, stepx, stepy; + //printf("x distance: %d; y distance: %d\n", distance.x, distance.y); + int steps_phys, stepx, stepy; + steps_phys = stepx = stepy = 0; if (distance.x == 0) { - steps = distance.y; stepy = 1; stepx = 0; + steps_phys = distance.y; stepy = 1; stepx = 0; } else if (distance.y == 0) { - steps = distance.x; stepx = 1; stepy = 0; - } else if (distance.x > distance.y) { steps = distance.y; stepy = 1; stepx = round(distance.x/steps); } else { steps = distance.x; stepx = 1; stepy = round(distance.y/steps); }; - for (int i = 0; i < steps; i++) + steps_phys = distance.x; stepx = 1; stepy = 0; + } else if (distance.x > distance.y) { steps_phys = distance.y; stepy = 1; stepx = ceil(distance.x/steps_phys); } else { steps_phys = distance.x; stepx = 1; stepy = round(distance.y/steps_phys); }; + + //printf("stepx:%d; stepy:%d; steps: %d\n", stepx, stepy, steps_phys); + for (int i = 0; i < steps_phys; i++) { p->rect.x += stepx; p->rect.y += stepy; diff --git a/player.c b/player.c index ac1ad39..71bec42 100644 --- a/player.c +++ b/player.c @@ -34,12 +34,16 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic if (on_floor(&(player.rect)) == 0) { player.velocity.y += GRAVITY; - } else if (IsKeyDown(inputs[2])) { + } else { + player.velocity.y = 0; + }; + if (IsKeyDown(inputs[2])) { player.velocity.y = JUMPVELOCITY; + printf("JUMP"); }; int direction; - if ((IsKeyDown(inputs[0])) == (IsKeyDown(inputs[1]))) { + if ((IsKeyDown(inputs[0]) && IsKeyDown(inputs[1])) || (!IsKeyDown(inputs[1]) && !IsKeyDown(inputs[0]))) { direction = 0; } else if (IsKeyDown(inputs[0]) == 1) { direction = -1; @@ -48,7 +52,8 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic }; player.velocity.x = direction * SPEED; - + if (player.velocity.x != direction * SPEED) { printf("sad"); }; + printf("direction * SPEED: %d; velocity.x: %d; is A down?:%d\n", direction * SPEED, (player.velocity.x), IsKeyDown(inputs[0])); return 1; }