|
|
@ -43,22 +43,26 @@ Direction Game::getDirection(sf::Keyboard::Key &key) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case sf::Keyboard::A:
|
|
|
|
case sf::Keyboard::A:
|
|
|
|
case sf::Keyboard::Left:
|
|
|
|
case sf::Keyboard::Left:
|
|
|
|
return Direction::LEFT;
|
|
|
|
case sf::Keyboard::Num4:
|
|
|
|
|
|
|
|
return Direction::Left;
|
|
|
|
|
|
|
|
|
|
|
|
case sf::Keyboard::W:
|
|
|
|
case sf::Keyboard::W:
|
|
|
|
case sf::Keyboard::Up:
|
|
|
|
case sf::Keyboard::Up:
|
|
|
|
return Direction::UP;
|
|
|
|
case sf::Keyboard::Num8:
|
|
|
|
|
|
|
|
return Direction::Up;
|
|
|
|
|
|
|
|
|
|
|
|
case sf::Keyboard::D:
|
|
|
|
case sf::Keyboard::D:
|
|
|
|
case sf::Keyboard::Right:
|
|
|
|
case sf::Keyboard::Right:
|
|
|
|
return Direction::RIGHT;
|
|
|
|
case sf::Keyboard::Num6:
|
|
|
|
|
|
|
|
return Direction::Right;
|
|
|
|
|
|
|
|
|
|
|
|
case sf::Keyboard::S:
|
|
|
|
case sf::Keyboard::S:
|
|
|
|
case sf::Keyboard::Down:
|
|
|
|
case sf::Keyboard::Down:
|
|
|
|
return Direction::DOWN;
|
|
|
|
case sf::Keyboard::Num2:
|
|
|
|
|
|
|
|
return Direction::Down;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return Direction::NONE;
|
|
|
|
return Direction::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -67,13 +71,42 @@ void Game::onMoving(sf::Keyboard::Key &key)
|
|
|
|
// Determine where to move
|
|
|
|
// Determine where to move
|
|
|
|
const Direction direction = getDirection(key);
|
|
|
|
const Direction direction = getDirection(key);
|
|
|
|
|
|
|
|
|
|
|
|
if (direction == Direction::NONE)
|
|
|
|
if (direction == Direction::None)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
int initial_x, initial_y;
|
|
|
|
// Save the initial coordinates
|
|
|
|
|
|
|
|
coordinate initial_x, initial_y;
|
|
|
|
hero->position(initial_x, initial_y);
|
|
|
|
hero->position(initial_x, initial_y);
|
|
|
|
|
|
|
|
|
|
|
|
// TO DO THE REST
|
|
|
|
// Try to move hero
|
|
|
|
|
|
|
|
hero->move(direction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the new coordinates after moving
|
|
|
|
|
|
|
|
coordinate attempt_x, attempt_y;
|
|
|
|
|
|
|
|
hero->position(attempt_x, attempt_y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the following cell is water
|
|
|
|
|
|
|
|
if (level->isCellOfType(attempt_x, attempt_y, '.'))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Try to use one charge to place a bridge
|
|
|
|
|
|
|
|
if (hero->useCharge())
|
|
|
|
|
|
|
|
level->placeBridge(attempt_x, attempt_y);
|
|
|
|
|
|
|
|
// If hero doesn't have enough charges, we move Hero back
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
hero->setPosition(initial_x, initial_y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the following cell is a charge
|
|
|
|
|
|
|
|
if (level->isCellOfType(attempt_x, attempt_y, '$'))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Hero picks up the charge; remove it from the map
|
|
|
|
|
|
|
|
hero->refillCharges(1);
|
|
|
|
|
|
|
|
level->removeCharge(attempt_x, attempt_y);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|