Cleaned up some naming and added WASD controls

This commit is contained in:
Trimutex 2023-08-18 17:51:58 -05:00
parent 35244daa02
commit c57fbc714c
4 changed files with 25 additions and 19 deletions

View File

@ -12,26 +12,27 @@ namespace snakeplusplus
return;
}
void GameEngine::StartGame()
void GameEngine::Start()
{
//ApplySettings();
PrepareGameBoard();
graphics.StartGameWindow();
GameLoop();
Loop();
return;
}
void GameEngine::GameLoop(void)
void GameEngine::Reset()
{
graphics.CheckContinue();
player.Reset();
PrepareGameBoard();
isGameOver = 0;
}
void GameEngine::Loop(void)
{
while (graphics.IsOpen())
{
if (isGameOver)
{
graphics.CheckContinue();
player.Reset();
PrepareGameBoard();
isGameOver = 0;
}
if (isGameOver) {Reset();}
UpdatePlayerSpeed();
PlaceNewSnakePart(MovePlayer());
RegenerateFood();

View File

@ -12,17 +12,17 @@ namespace snakeplusplus
{
public:
GameEngine();
void StartGame(void);
void Start(void);
void Reset(void);
sf::Vector2f GetGameBoundaries(void);
private:
std::vector< std::vector<char> > gameBoard;
PlayerOutput graphics;
Snake player;
Food playerFood;
bool useSFML = 1;
bool isGameOver = 0;
void DisplayEndScreen(void);
void GameLoop(void);
void Loop(void);
sf::Vector2f MovePlayer(void);
void PlaceNewSnakePart(sf::Vector2f location);
void RegenerateFood(void);

View File

@ -3,5 +3,5 @@
int main(void)
{
snakeplusplus::GameEngine game;
game.StartGame();
game.Start();
}

View File

@ -1,17 +1,22 @@
#include "playerinterface.hpp"
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
namespace snakeplusplus
{
PlayerDirection GetPlayerInput(void)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::A))
return kLeft;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::W))
return kUp;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::S))
return kDown;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)
|| sf::Keyboard::isKeyPressed(sf::Keyboard::D))
return kRight;
return kNone;
}