]> _ Git - aichan-platformer.git/commitdiff
I HAVE SPENT FAR TOO MUCH TIME TRYING TO FIX THIS. is printf broken or smth. ...
authorparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 20:12:34 +0000 (16:12 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 20:12:34 +0000 (16:12 -0400)
game.h
physics.c
player.c

diff --git a/game.h b/game.h
index f728229..a090eaf 100644 (file)
--- 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);
 
index 0811cec..4f9c830 100644 (file)
--- 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;
index ac1ad39..71bec42 100644 (file)
--- 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;
 }