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