]> _ Git - aichan-platformer.git/commitdiff
no idea what but smth is very wrong with this program, i cant code
authorparking_turkeys <roya1060wien@gmail.com>
Thu, 9 Jul 2026 17:18:22 +0000 (13:18 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Thu, 9 Jul 2026 17:18:22 +0000 (13:18 -0400)
main.c

diff --git a/main.c b/main.c
index 0ec5008..aed67e4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -38,6 +38,7 @@ int move_y(struct character *character, int direction);
 int onfloor(struct character *chara, struct platform *ground, int ground_length);
 int gravity(struct character *character, struct platform *ground, int ground_length);
 int move_character(struct character *character, struct platform *ground, int ground_length, float delta);
+int infloor(struct character *character, struct platform *ground, int ground_length);
 
 int main(void)
 {
@@ -153,7 +154,7 @@ int gravity(struct character *chara, struct platform *ground, int length)
        return 1;
 }
 
-struct Vector2 infloor(struct character *chara, struct platform *ground, int length) {
+int infloor(struct character *chara, struct platform *ground, int length) {
        struct Vector2 depth = {0,0};
        struct Rectangle charrect = {chara->position.x, chara->position.y, chara->size.x, chara->size.y};
        struct Rectangle groundrect, collrect;
@@ -166,26 +167,28 @@ struct Vector2 infloor(struct character *chara, struct platform *ground, int len
                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 1;
                } 
        }
-       return depth;
+       return 0;
 }       
 
 int move_character(struct character *chara, struct platform *ground, int length, float delta)
 {
-       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);
+       int stepx, stepy, steps;
+       if (abs(chara->velocity.x) > abs(chara->velocity.y)) { //x is a larger movement
+               steps = chara->velocity.y; stepy = 1; stepx = round(chara->velocity.x/steps);
+       } else {
+               steps = chara->velocity.x + 1; stepx = 1; stepy = round(chara->velocity.y/steps);
+       }
+       printf("stepx: %d stepy: %d steps: %d yvel: %d xvel:%d\n", stepx, stepy, steps, chara->velocity.y, chara->velocity.x);
+       while ((infloor(chara, ground, length) == 0) && (steps != 0)) {
+               chara->position.x += stepx;
+               chara->position.y += stepy;
+               steps--;
        }
+       chara->position.x -= stepx;
+       chara->position.y -= stepy;
+       chara->position.y += 1;
        return 1;
 }