Make movement more natural
This commit is contained in:
parent
31211538aa
commit
e572f2a93a
2 changed files with 9 additions and 4 deletions
|
@ -29,13 +29,13 @@ void PacMan::update(std::chrono::milliseconds time_delta, InputState state, cons
|
|||
|
||||
void PacMan::setDirection(const InputState & state) {
|
||||
if (state.left)
|
||||
direction = Direction::LEFT;
|
||||
desired_direction = Direction::LEFT;
|
||||
else if (state.right)
|
||||
direction = Direction::RIGHT;
|
||||
desired_direction = Direction::RIGHT;
|
||||
else if (state.up)
|
||||
direction = Direction::UP;
|
||||
desired_direction = Direction::UP;
|
||||
else if (state.down)
|
||||
direction = Direction::DOWN;
|
||||
desired_direction = Direction::DOWN;
|
||||
}
|
||||
|
||||
void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
||||
|
@ -47,6 +47,10 @@ void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
|||
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
||||
float_t position_delta = (time_delta.count() / 128.0);
|
||||
|
||||
if (board.isWalkable(pos, position_delta, desired_direction)) {
|
||||
direction = desired_direction;
|
||||
}
|
||||
|
||||
if (board.isWalkable(pos, position_delta, direction)) {
|
||||
switch (direction) {
|
||||
case Direction::NONE:
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
private:
|
||||
|
||||
Direction direction = Direction::NONE;
|
||||
Direction desired_direction = Direction::NONE;
|
||||
Position pos = {14, 23};
|
||||
const SDL_Rect right_wide = {0*32, 0, 32, 32};
|
||||
const SDL_Rect right_narrow = {1*32, 0, 32, 32};
|
||||
|
|
Loading…
Reference in a new issue