From 5825b1cd8732d8b0d183f3c389046ea26a1d8a96 Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Wed, 8 Jul 2026 19:23:58 -0400 Subject: [PATCH] gravity --- main.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index a9a40cf..0ec5008 100644 --- 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; } -- 2.47.3