Skip to content

Commit

Permalink
Fix cell rotation
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Jan 23, 2024
1 parent 0361d4c commit f26c6a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
1 change: 1 addition & 0 deletions src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void Level::update()
}
}
}
state.rotation_active |= state.rotation_complete;

// trace from sender
if (!get_cell(sender).rotation()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f26c6a9

Please sign in to comment.