diff options
-rw-r--r-- | levels/level0.txt | 2 | ||||
-rwxr-xr-x | source/main.cpp | 20 | ||||
-rwxr-xr-x | source/math.h | 1 |
3 files changed, 18 insertions, 5 deletions
diff --git a/levels/level0.txt b/levels/level0.txt index 8a0428e..27dd2fc 100644 --- a/levels/level0.txt +++ b/levels/level0.txt @@ -11,7 +11,7 @@ # == gameplay elements == # gravity inverter # type posx posy sizex sizey -# 3 650 60 1 1 + 3 650 60 1 1 # teleporter # type posx posy sizex sizey id link_id 4 800 90 1 2 50 51 diff --git a/source/main.cpp b/source/main.cpp index e80b419..67571df 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -272,6 +272,7 @@ struct GameState { b8 flip_gravity; b8 inside_teleporter; b8 teleporting; + r64 gravity_flip_timer; }; Rect rect(Vec3 position, Vec2 size) { @@ -1158,7 +1159,7 @@ int main(int argc, char* argv[]) // tl -> lt // br -> rb { - // @step: calculate camera bounds + // @step: calculate_camera_bounds Vec2 cam_lt = Vec2{renderer.cam_pos.x, renderer.cam_pos.y + state.screen_size.y}; Vec2 cam_rb = Vec2{renderer.cam_pos.x + state.screen_size.x, renderer.cam_pos.y}; state.camera_bounds.tl = cam_lt; @@ -1611,8 +1612,17 @@ int main(int argc, char* argv[]) } else if (t_collide_bottom) { player.position.y += (t_bottom - prev_top - 0.1f); } + if (e.type == INVERT_GRAVITY && (t_collide_x || t_collide_top || t_collide_bottom)) { - state.flip_gravity = 1; + // @note: gravity inverter mechanic + // 1. touch block, gravity flips + // 2. for 2 second, after gravity is flipped, gravity will not be flipped + // (this will collapse various cases where the player is trying to reflip gravity, + // but immediate contact after flipping makes this awkward and infeasible) + if (state.gravity_flip_timer <= 0) { + state.gravity_flip_timer = 1000.0f; + state.flip_gravity = 1; + } } is_collide_x = is_collide_x || t_collide_x; @@ -1697,6 +1707,9 @@ int main(int argc, char* argv[]) player.position.y = teleported_position.y; } } + { + state.gravity_flip_timer = MAX(state.gravity_flip_timer - timer.tDeltaMS, 0.0f); + } { // @step: update player variables @@ -1827,9 +1840,8 @@ int main(int argc, char* argv[]) renderer.preset_up_dir ); renderer.cam_update = false; - state.camera_bounds = rect(renderer.cam_pos, state.screen_size); { - // @step: calculate camera bounds + // @step: calculate_camera_bounds Vec2 cam_lt = Vec2{renderer.cam_pos.x, renderer.cam_pos.y + state.screen_size.y}; Vec2 cam_rb = Vec2{renderer.cam_pos.x + state.screen_size.x, renderer.cam_pos.y}; state.camera_bounds.tl = cam_lt; diff --git a/source/math.h b/source/math.h index ff76c0e..b189c89 100755 --- a/source/math.h +++ b/source/math.h @@ -9,6 +9,7 @@ #define TO_DEG(x) ((x) * 180.0f / PI) #define ABS(x) ((x) < 0 ? (-(x)) : (x)) #define MIN(x,y) ((x) < (y) ? (x) : (y)) +#define MAX(x,y) ((x) > (y) ? (x) : (y)) // @todo: // - make everything simd |