]> _ Git - aichan-platformer.git/commitdiff
gravity
authorparking_turkeys <roya1060wien@gmail.com>
Wed, 8 Jul 2026 23:23:58 +0000 (19:23 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Wed, 8 Jul 2026 23:23:58 +0000 (19:23 -0400)
main.c

diff --git a/main.c b/main.c
index a9a40cf..0ec5008 100644 (file)
--- a/main.c
+++ b/main.c
@@ -160,10 +160,18 @@ struct Vector2 infloor(struct character *chara, struct platform *ground, int len
        
        
        for (int i = 0; i < length; i++) {
-               if (CheckCollisionRecs(charrect, ground[i])) {
-                       collrect = GetCollisionRect(charrect, ground[i]);
-                       if (ground[i].position.x > charrect.x) { depth.x = (int)(collrect.width) * -1; } else { depth.x = (int)(collrect.width) };
-                       if (ground[i].position.y > charrect.y) { depth.y = (int)(collrect.height) * -1; } else { depth.y = (int)(collrect.height) };
+               groundrect.x = ground[i].position.x; 
+               groundrect.y = ground[i].position.y; 
+               groundrect.width=ground[i].size.x;
+               groundrect.height=ground[i].size.y;
+               if (CheckCollisionRecs(charrect, groundrect)) {
+                       collrect = GetCollisionRec(charrect, groundrect);
+                       if (collrect.height > 1) {
+                       if (ground[i].position.x > charrect.x) { depth.x = (int)(collrect.width) * -1; } else { depth.x = (int)(collrect.width);};
+                       if (ground[i].position.y > charrect.y) { depth.y = (int)(collrect.height) * -1; } else { depth.y = (int)(collrect.height);};
+                       return depth;
+                       }
+               } 
        }
        return depth;
 }       
@@ -172,5 +180,12 @@ int move_character(struct character *chara, struct platform *ground, int length,
 {
        chara->position.x += ceil(chara->velocity.x * delta);
        chara->position.y += ceil(chara->velocity.y * delta);
+       struct Vector2 depth;
+       depth = infloor(chara, ground, length);
+       while ((depth.y != 0) && (depth.x != 0)) {
+               chara->position.x += depth.x;
+               chara->position.y += depth.y;
+               depth = infloor(chara, ground, length);
+       }
        return 1;
 }