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
+ }
};
};
};
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!");
};
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;
};
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 {
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;
}