Implement moving the player
Player: Add rotation and linear speeds, as well as their current state. Player: Allow to move in the local coordinates and compute world-speed equivalent. Player: Update movement axis while rotating. World: Add a function to advance a step. Main: Handle key events, add world step in the main loop.
This commit is contained in:
parent
b359ff171f
commit
804f0272f8
5 changed files with 80 additions and 3 deletions
|
@ -243,4 +243,13 @@ void World::render(sf::RenderWindow& window) const
|
|||
}
|
||||
}
|
||||
|
||||
void World::step(const float& stepTime) {
|
||||
player.move(player.currentMoveSpeedX*stepTime,
|
||||
player.currentMoveSpeedY*stepTime);
|
||||
/* Undo last move if the player would end up in a wall. */
|
||||
if (getBlock((int)player.x, (int)player.y) != BlockType::AIR) {
|
||||
player.move(-player.currentMoveSpeedX*stepTime,
|
||||
-player.currentMoveSpeedY*stepTime);
|
||||
}
|
||||
player.rotate(player.currentRotationSpeed*stepTime);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue