Fix ground movement

cpp
Elnu 3 years ago
parent 7bb946a805
commit 2df9d4d95f

@ -185,7 +185,10 @@ int main()
sf::Sprite sprite; sf::Sprite sprite;
sprite.setTexture(texture); sprite.setTexture(texture);
bool snap, rotate, move_left, move_right; bool rotate = true;
bool move_left = true;
bool move_right = true;
bool snap = false;
sf::Clock update_clock; sf::Clock update_clock;
sf::Clock move_clock; sf::Clock move_clock;
@ -294,19 +297,21 @@ int main()
snap_offset++; snap_offset++;
} }
after_snap_loop: after_snap_loop:
bool landed = snap;
if (snap) { if (snap) {
block.position.y += snap_offset; block.position.y += snap_offset;
snap = false; snap = false;
} }
// Land checking // Land checking
bool landed = false; if (!snap && is_update_frame) {
for (auto tile : block.get_tiles()) { for (auto tile : block.get_tiles()) {
if (tile.y == GRID_HEIGHT - 1 || grid[tile.y + 1][tile.x] != nullptr) { if (tile.y == GRID_HEIGHT - 1 || grid[tile.y + 1][tile.x] != nullptr) {
landed = true; landed = true;
break; break;
} }
} }
}
// Draw block // Draw block
window.clear(clear_color); window.clear(clear_color);

Loading…
Cancel
Save