diff --git a/src/cell.cpp b/src/cell.cpp index ec4bd1b..114aae9 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -137,11 +137,10 @@ Cell::Status Cell::update() { if (rotation()) { const Uint64 diff = SDL_GetTicks64() - rotate_start; - if (diff > rotation_time) { + if (diff >= rotation_time) { // rotation completed rotate_start = 0; if (rotate_twice) { - rotate_twice = false; rotate(rotate_clockwise); } return Cell::RotationComplete; @@ -169,16 +168,16 @@ double Cell::phase() const double Cell::angle() const { - double angle = pipe.angle(); + double angle; - if (rotation()) { - const float diff_angle = phase() * 90.0f; - angle = rotate_pipe.angle(); - if (rotate_clockwise) { - angle += diff_angle; - } else { - angle -= diff_angle; + if (!rotation()) { + angle = pipe.angle(); + } else { + angle = phase() * 90.0; + if (!rotate_clockwise) { + angle = -angle; } + angle += rotate_pipe.angle(); } return angle; @@ -203,6 +202,7 @@ void Cell::rotate(bool clockwise) rotate_clockwise = clockwise; } } else { + rotate_twice = false; rotate_pipe = pipe; rotate_clockwise = clockwise; rotate_start = SDL_GetTicks64(); diff --git a/src/cell.hpp b/src/cell.hpp index 6ced576..b3a1634 100644 --- a/src/cell.hpp +++ b/src/cell.hpp @@ -128,7 +128,7 @@ struct Cell { Pipe pipe; ///< Pipe size_t rotate_start; ///< Rotation start timestamp - Pipe rotate_pipe; ///< Rotation pipe + Pipe rotate_pipe; ///< Start state of pipe before rotation bool rotate_twice; ///< Twice rotation flag bool rotate_clockwise; ///< Rotate direction }; diff --git a/src/level.cpp b/src/level.cpp index c4c44d6..8152b73 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -81,6 +81,7 @@ void Level::update() } } } + state.rotation_active |= state.rotation_complete; // trace from sender if (!get_cell(sender).rotation()) { diff --git a/src/main.cpp b/src/main.cpp index 3424c59..a0f66a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ bool run(State& state) // create window SDL_Window* window = SDL_CreateWindow("PipeWalker", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 480, 640, + SDL_WINDOWPOS_UNDEFINED, 480, 600, SDL_WINDOW_RESIZABLE); if (!window) { printf("Failed to create window: %s\n", SDL_GetError());