]> git.lizzy.rs Git - nothing.git/commitdiff
Don't switch to the layer if you physically can't
authorrexim <reximkut@gmail.com>
Sun, 26 Jan 2020 19:40:06 +0000 (02:40 +0700)
committerrexim <reximkut@gmail.com>
Sat, 8 Feb 2020 16:51:01 +0000 (23:51 +0700)
src/game/level.c
src/game/level/platforms.c
src/game/level/platforms.h

index 021f1a86cfda03d9cab0852b47f028f7bf83729e..61c8333b929a2400b28cf98b9754dc944335ded5 100644 (file)
@@ -308,7 +308,10 @@ int level_event_idle(Level *level, const SDL_Event *event,
         } break;
 
         case SDLK_1: {
-            if (level->current_platforms > 0) {
+            if (level->current_platforms > 0
+                && !platforms_overlap_with_rect(
+                    level->platform_layers[level->current_platforms - 1],
+                    player_hitbox(level->player))) {
                 level->a = 0.0f;
                 level->da = PLATFORM_LAYERS_SPEED;
                 level->prev_platform = level->current_platforms;
@@ -317,7 +320,10 @@ int level_event_idle(Level *level, const SDL_Event *event,
         } break;
 
         case SDLK_2: {
-            if (level->current_platforms + 1 < PLATFORM_LAYERS_COUNT) {
+            if (level->current_platforms + 1 < PLATFORM_LAYERS_COUNT
+                && !platforms_overlap_with_rect(
+                    level->platform_layers[level->current_platforms + 1],
+                    player_hitbox(level->player))) {
                 level->a = 0.0f;
                 level->da = -PLATFORM_LAYERS_SPEED;
                 level->prev_platform = level->current_platforms;
index 67b552ff874ecec977c6cfc81ef153acbaab5f82..2f1f0d2a69e787e142051c1f35397f990928a17d 100644 (file)
@@ -141,3 +141,15 @@ Vec2f platforms_snap_rect(const Platforms *platforms,
 
     return result;
 }
+
+int platforms_overlap_with_rect(const Platforms *platforms,
+                                Rect rect)
+{
+    for (size_t i = 0; i < platforms->rects_size; ++i) {
+        if (rects_overlap(platforms->rects[i], rect)) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
index a3c8cb57b6d43436f4010daa571c7938bc66625b..9962977a6a6a27da0ff0ec340fec60889e5e45d9 100644 (file)
@@ -21,4 +21,7 @@ void platforms_touches_rect_sides(const Platforms *platforms,
 Vec2f platforms_snap_rect(const Platforms *platforms,
                           Rect *object);
 
+int platforms_overlap_with_rect(const Platforms *platforms,
+                                Rect rect);
+
 #endif  // PLATFORMS_H_