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
17
Player.cpp
17
Player.cpp
|
@ -25,4 +25,21 @@ void Player::rotate(float alpha)
|
|||
{
|
||||
orientation += 360;
|
||||
}
|
||||
|
||||
/*
|
||||
* Rotate the movement vector along the new angle, assumes that the only
|
||||
* speed influencing the player is its own movement.
|
||||
*/
|
||||
float prevSpeedX = currentMoveSpeedX;
|
||||
float prevSpeedY = currentMoveSpeedY;
|
||||
currentMoveSpeedX = cosf(-alpha * deg_to_rad) * prevSpeedX
|
||||
- sinf(-alpha * deg_to_rad) * prevSpeedY;
|
||||
currentMoveSpeedY = sinf(-alpha * deg_to_rad) * prevSpeedX
|
||||
+ cosf(-alpha * deg_to_rad) * prevSpeedY;
|
||||
}
|
||||
|
||||
void Player::updateSpeed(float localX, float localY) {
|
||||
// TODO: Support strafing.
|
||||
currentMoveSpeedX = localX * sinf(orientation*deg_to_rad)*moveSpeed;
|
||||
currentMoveSpeedY = localX * cosf(orientation*deg_to_rad)*moveSpeed;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue