]> _ Git - aichan-platformer.git/commitdiff
fix on_floor
authorparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 21:21:59 +0000 (17:21 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Tue, 14 Jul 2026 21:21:59 +0000 (17:21 -0400)
level.c
physics.c
player.c

diff --git a/level.c b/level.c
index 515576c..794e128 100644 (file)
--- a/level.c
+++ b/level.c
@@ -26,13 +26,20 @@ int in_floor(struct Rectangle *rect)
 
 int on_floor(struct Rectangle *rect) //on floor == no overlap but right next to eachother ig?? like the bottom of rect is 1 less y than ground
 {
-       for (int i = 0; i < stages[level].platform_count; i++) {
-               if (rect->y == (stages[level].platforms[i].rect.y - 1)) {
+
+       int platcount = stages[level].platform_count;
+       for (int i = 0; i < platcount; i++) {
+               Rectangle *check = &(stages[level].platforms[i].rect);
+               int checkx, checky, rectx, recty, rectw, recth;
+               checkx = check->x; checky = check->y; rectx = rect->x; recty = rect->y; rectw = rect->width; recth = rect->height;
+               //printf("(%d,%d) (%d,%d, %d, %d)\n", checkx, checky, rectx, recty, rectw, recth);
+               if ((recty + recth) == (checky)) {
+                       //printf("same y...");
                        //check whether the X values match up uwu
-                       Rectangle eins = {rect->x, 1, rect->width, 1};
-                       Rectangle zwei = {stages[level].platforms[i].rect.x, 1, stages[level].platforms[i].rect.width, 1};
+                       Rectangle eins; eins.x = rectx;eins.y=1;eins.width=rectw;eins.height=1;
+                       Rectangle zwei; zwei.x =checkx;zwei.y=1;zwei.width=check->width;zwei.height=1;
                        if (CheckCollisionRecs(eins,zwei)) {
-                               return 1;
+                               return 1; printf("on floor!");
                        };
                };
        };
index 4f9c830..6b8c83d 100644 (file)
--- a/physics.c
+++ b/physics.c
@@ -21,23 +21,34 @@ static int gravity(float d, struct character *p)
 
 int move_player(float d, struct character *p)
 {
-       //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)};
+       int veloy, velox; velox = p->velocity.x; veloy = p->velocity.y;
+       //printf("x velocity: %d; y velocity: %d; delta: %f\n", velox, veloy, d);
+       int distancex, distancey; distancex = ceil(p->velocity.x *d); distancey= ceil(p->velocity.y*d);
+       Vector2 distance;
+       distance.x = distancex; distance.y = distancey;
        //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_phys = distance.y; stepy = 1; stepx = 0;
+               steps_phys = abs(distance.y); stepy = ceil(distance.y/steps_phys); stepx = 0;
        } else if (distance.y == 0) {
-               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); };
+               steps_phys = abs(distance.x); stepx = ceil(distance.x/steps_phys); stepy = 0;
+        } else if (abs(distance.x) > abs(distance.y)) { steps_phys = abs(distance.y); stepy = ceil(distance.y/steps_phys); stepx = ceil(distance.x/steps_phys); } else { steps_phys = abs(distance.x); stepx = ceil(distance.x/steps_phys); 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;
-               if (in_floor(&p->rect)) { p->rect.x -= stepx; p->rect.y -= stepy; return 1; };
+               if (in_floor(&p->rect)) { 
+                       p->rect.x -= stepx; p->rect.y -= stepy;
+                       for (;i < steps_phys; i++) {
+                               if (stepx > 0) {p->rect.x += 1; if (in_floor(&p->rect)) { p->rect.x-=1; };} else if (stepx < 0) {p->rect.x -= 1; if (in_floor(&p->rect)) { p->rect.x+=1; };};
+                               if (stepy > 0) {p->rect.y += 1; if (in_floor(&p->rect)) { p->rect.y-=1; };} else if (stepy < 0) {p->rect.y -= 1; if (in_floor(&p->rect)) { p->rect.y+=1; };};
+                       }
+
+                       return 1; 
+               };
        };
                        
        return 1;
index 71bec42..3769613 100644 (file)
--- a/player.c
+++ b/player.c
@@ -36,10 +36,11 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic
                player.velocity.y += GRAVITY;
        } else {
               player.velocity.y = 0;
+              //printf("ON FLOOR");
        };             
-       if (IsKeyDown(inputs[2])) {
+       if (on_floor(&player.rect) && IsKeyDown(inputs[2])) {
                player.velocity.y = JUMPVELOCITY;
-               printf("JUMP");
+               //printf("JUMP");
        };
 
        int direction;
@@ -52,8 +53,9 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic
        };
        
        player.velocity.x = direction * SPEED;
+       int playervelocityx = player.velocity.x;
        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]));
+       //printf("direction * SPEED: %d; velocity.x: %d; int playervelocityx = player.velocity.x:%d\n", direction * SPEED, (player.velocity.x), playervelocityx);
        return 1;
 }