]> _ Git - aichan-platformer.git/commitdiff
walljumps!!
authorparking_turkeys <roya1060wien@gmail.com>
Wed, 22 Jul 2026 21:08:07 +0000 (17:08 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Wed, 22 Jul 2026 21:08:07 +0000 (17:08 -0400)
level.c
player.c

diff --git a/level.c b/level.c
index 1af6efa..fef2f58 100644 (file)
--- a/level.c
+++ b/level.c
@@ -50,9 +50,12 @@ int bühnezeichnen(void)
 int in_floor(struct Rectangle *rect)
 {
        for (int i = 0; i < stages[level].platform_count; i++) {
-               if (CheckCollisionRecs(*rect, stages[level].platforms[i].rect)) { 
-                       if (!(stages[level].platforms[i].rect.y == rect->y + rect->height)) {// this would mean rect is just sitting on top of it
+               Rectangle check = stages[level].platforms[i].rect;
+               if (CheckCollisionRecs(*rect, check)) { 
+                       if (!(check.y == rect->y + rect->height)) {// this would mean rect is just sitting on top of it
+                               if (!(check.x == rect->x + rect->width) && !(check.x + check.width == rect->x)) {
                                return 1; //we dont want it to return 1 if they're just on the floor
+                               }
                        };
                };
        };
@@ -65,14 +68,11 @@ int on_floor(struct Rectangle *rect) //on floor == no overlap but right next to
        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)) {
+               if ((rect->y + rect->height) == (check->y)) {
                        //printf("same y...");
                        //check whether the X values match up uwu
-                       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;
+                       Rectangle eins = (struct Rectangle){rect->x,1,rect->width,1};
+                       Rectangle zwei = (struct Rectangle){check->x,1,check->width,1};
                        if (CheckCollisionRecs(eins,zwei)) {
                                return 1; printf("on floor!");
                        };
@@ -89,17 +89,19 @@ int sliding_wall(struct Rectangle *rect)
                return 0;
        } else {
                for (int i = 0; i < stages[level].platform_count; i++) {
-                       //printf("check slide");
                        Rectangle *check = &(stages[level].platforms[i].rect);
-                       if (CheckCollisionRecs(*rect, *check)) {
-                               printf("colliding!!");
-                               Rectangle overlap = (GetCollisionRec(*rect, *check));
-                               if ((overlap.height > 1) &&( overlap.width == 1)) {
-                                       printf("sliding!!");
+                       //int checkx = check->x; int rectx = rect->x;
+                       //printf("check->x:%d rect->x:%d\n", checkx, rectx);
+                       Rectangle eins = (struct Rectangle){1,rect->y,1,rect->height};
+                       Rectangle zwei = (struct Rectangle){1,check->y,1,check->height};
+                       if (CheckCollisionRecs(eins,zwei)) { //overlapping y
+                               if ((rect->x + rect->width) == (check->x)) {
+                                       return -1;
+                               } else if ((rect->x) == (check->width + check->x)) {
                                        return 1;
-                               }
-                       }
-               }
+                               };
+                       };
+               };
        };
        return 0;
 };
index 70540ae..1ed2176 100644 (file)
--- a/player.c
+++ b/player.c
@@ -61,8 +61,24 @@ int spielerzeichnen(void)
 
 int spieler_bewegen(float delta) // should actually only change velocity, physics file moves player based on velocity uwu
 {
+       int d;
+
+       static float walljumpprogress= 0;
+       static int walljumpdir = 0;
        delta_player = delta;
        
+       int direction;
+       if (IsKeyDown(inputs[1])) {
+               direction = 1;
+       } else if (IsKeyDown(inputs[0]) == 1) {
+               direction = -1;
+       } else {
+               direction = 0;
+       };
+       
+       player.velocity.x = direction * SPEED;
+       if (player.velocity.x != direction * SPEED) { printf("sad"); };
+
        if (on_floor(&(player.rect)) == 0) {
                player.velocity.y += GRAVITY;
        } else {
@@ -72,22 +88,21 @@ int spieler_bewegen(float delta) // should actually only change velocity, physic
        if (on_floor(&player.rect) && IsKeyDown(inputs[2])) {
                player.velocity.y = JUMPVELOCITY;
                //printf("JUMP");
-       } else if (IsKeyDown(inputs[2]) && sliding_wall(&player.rect)) {
-               player.velocity.y = JUMPVELOCITY;
+       } else if (IsKeyDown(inputs[2]) && (d = sliding_wall(&player.rect))) {
+               player.velocity.y = JUMPVELOCITY * 1.5;
+               player.velocity.x =   d * SPEED * 1.5;
+               walljumpprogress = 1;
+               walljumpdir = d;
        };
 
-       int direction;
-       if (IsKeyDown(inputs[1])) {
-               direction = 1;
-       } else if (IsKeyDown(inputs[0]) == 1) {
-               direction = -1;
-       } else {
-               direction = 0;
+       if (walljumpprogress > 0) {
+               walljumpprogress -= delta;
+               player.velocity.x = walljumpdir * SPEED * 1.5;
+       } else if (walljumpprogress < 0) {
+               walljumpprogress = 0;
        };
+
        
-       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; int playervelocityx = player.velocity.x:%d\n", direction * SPEED, (player.velocity.x), playervelocityx);
        return 1;
 }