Fixed snake keeping movement on reset
This commit is contained in:
parent
c71b1d6982
commit
d83f271adf
@ -110,8 +110,7 @@ namespace snakeplusplus
|
||||
|
||||
void GameEngine::UpdatePlayerSpeed(void)
|
||||
{
|
||||
PlayerDirection input = controls.GetPlayerInput();
|
||||
switch (input) {
|
||||
switch (GetPlayerInput()) {
|
||||
case kUp:
|
||||
player.speed.x = 0;
|
||||
player.speed.y = -1;
|
||||
|
@ -17,7 +17,6 @@ namespace snakeplusplus
|
||||
sf::Vector2f GetGameBoundaries(void);
|
||||
private:
|
||||
std::vector< std::vector<char> > gameBoard;
|
||||
PlayerInput controls;
|
||||
PlayerOutput graphics;
|
||||
Snake player;
|
||||
Food playerFood;
|
||||
|
@ -5,22 +5,17 @@
|
||||
|
||||
namespace snakeplusplus
|
||||
{
|
||||
PlayerInput::PlayerInput(void)
|
||||
{
|
||||
lastPlayerInput = kNone;
|
||||
}
|
||||
|
||||
PlayerDirection PlayerInput::GetPlayerInput(void)
|
||||
PlayerDirection GetPlayerInput(void)
|
||||
{
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||
lastPlayerInput = kLeft;
|
||||
return kLeft;
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||
lastPlayerInput = kUp;
|
||||
return kUp;
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
||||
lastPlayerInput = kDown;
|
||||
return kDown;
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||
lastPlayerInput = kRight;
|
||||
return lastPlayerInput;
|
||||
return kRight;
|
||||
return kNone;
|
||||
}
|
||||
|
||||
bool PlayerOutput::IsOpen(void)
|
||||
|
@ -8,14 +8,7 @@ const int kGridSize = 25;
|
||||
|
||||
namespace snakeplusplus
|
||||
{
|
||||
class PlayerInput
|
||||
{
|
||||
public:
|
||||
PlayerInput(void);
|
||||
PlayerDirection GetPlayerInput(void);
|
||||
private:
|
||||
PlayerDirection lastPlayerInput;
|
||||
};
|
||||
|
||||
class PlayerOutput
|
||||
{
|
||||
|
@ -17,6 +17,8 @@ namespace snakeplusplus
|
||||
void Snake::Reset(void)
|
||||
{
|
||||
while (!body.empty()) Pop();
|
||||
speed.x = 0;
|
||||
speed.y = 0;
|
||||
}
|
||||
|
||||
Food::Food(void)
|
||||
|
Loading…
Reference in New Issue
Block a user