Moved snakeFood to be a separate class

Moved snakeFood to be a separate class and a temporary unused function was added for randomly generating the new location.
This commit is contained in:
TriantaTV
2022-08-02 21:58:58 -05:00
parent eae6b4c70d
commit c3342a14c7
3 changed files with 48 additions and 6 deletions
+8 -6
View File
@@ -1,7 +1,8 @@
#include <iostream>
// #include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include "Snake.h"
#include "SnakeFood.h"
#include "GameState.h"
GameState::GameState()
@@ -25,8 +26,9 @@ void GameState::startNewGame()
gameWindow.create(gameVideoMode, "SnakePlusPlus");
sf::Time delay = sf::milliseconds(25);
int snakeDirection = 0;
Snake Player(sf::Vector2f(25,25));
sf::RectangleShape snakeHead(sf::Vector2f(25,25));
Snake player(sf::Vector2f(25,25));
SnakeFood playerFood(sf::Vector2f(25,25));
// sf::RectangleShape snakeHead(sf::Vector2f(25,25));
sf::RectangleShape snakeFood(sf::Vector2f(25,25));
snakeFood.setFillColor(sf::Color::Red);
snakeFood.setPosition(25,25);
@@ -47,10 +49,10 @@ void GameState::startNewGame()
snakeDirection = 3;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
snakeDirection = 4;
Player.MoveSnake(snakeFood);
player.MoveSnake(playerFood.snakeFoodObject);
gameWindow.clear();
gameWindow.draw(snakeFood);
Player.DisplaySnake(gameWindow);
player.DisplaySnake(gameWindow);
gameWindow.draw(playerFood.snakeFoodObject);
gameWindow.display();
sf::sleep(delay);
}