Fixed food generation and removed unused code

Fixed food generation and removed unused code
This commit is contained in:
TriantaTV 2022-08-15 22:15:56 -05:00
parent 08ee516f0e
commit 0d3988a7ff
5 changed files with 5 additions and 12 deletions

View File

@ -28,10 +28,6 @@ void GameState::startNewGame()
int snakeDirection = 0; int snakeDirection = 0;
Snake player(sf::Vector2f(25,25)); Snake player(sf::Vector2f(25,25));
SnakeFood playerFood(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);
while (gameWindow.isOpen()) while (gameWindow.isOpen())
{ {

View File

@ -2,7 +2,6 @@
#ifndef GAMESTATE_H #ifndef GAMESTATE_H
#define GAMESTATE_H #define GAMESTATE_H
#include <SFML\Graphics.hpp> #include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
class GameState class GameState
{ {

View File

@ -1,6 +1,5 @@
#include <iostream> #include <iostream>
#include <SFML\Graphics.hpp> #include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include "Snake.h" #include "Snake.h"
// Test for collision between two objects // Test for collision between two objects

View File

@ -13,12 +13,11 @@ SnakeFood::SnakeFood(sf::Vector2f snakeFoodSize)
snakeFoodObject.setFillColor(sf::Color::Red); snakeFoodObject.setFillColor(sf::Color::Red);
} }
void SnakeFood::GenerateNewLocation(int maxLocation) int SnakeFood::GenerateNewLocation(int maxLocation)
{ {
sf::Vector2f newPosition; int newPosition;
std::default_random_engine generator; std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(0, maxLocation); std::uniform_int_distribution<int> distribution(0, maxLocation);
newPosition.x = distribution(generator); newPosition = distribution(generator);
newPosition.y = distribution(generator); return newPosition;
snakeFoodObject.setPosition(newPosition);
} }

View File

@ -10,7 +10,7 @@ public:
sf::RectangleShape snakeFoodObject; sf::RectangleShape snakeFoodObject;
SnakeFood(); SnakeFood();
SnakeFood(sf::Vector2f snakeFoodSize); SnakeFood(sf::Vector2f snakeFoodSize);
void GenerateNewLocation(int maxLocation); int GenerateNewLocation(int maxLocation);
}; };
#endif #endif