Fixed food generation and removed unused code
Fixed food generation and removed unused code
This commit is contained in:
parent
08ee516f0e
commit
0d3988a7ff
@ -28,10 +28,6 @@ void GameState::startNewGame()
|
||||
int snakeDirection = 0;
|
||||
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);
|
||||
|
||||
while (gameWindow.isOpen())
|
||||
{
|
||||
|
@ -2,7 +2,6 @@
|
||||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
#include <SFML\Graphics.hpp>
|
||||
#include <SFML\System.hpp>
|
||||
|
||||
class GameState
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <SFML\Graphics.hpp>
|
||||
#include <SFML\System.hpp>
|
||||
#include "Snake.h"
|
||||
|
||||
// Test for collision between two objects
|
||||
|
@ -13,12 +13,11 @@ SnakeFood::SnakeFood(sf::Vector2f snakeFoodSize)
|
||||
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::uniform_int_distribution<int> distribution(0, maxLocation);
|
||||
newPosition.x = distribution(generator);
|
||||
newPosition.y = distribution(generator);
|
||||
snakeFoodObject.setPosition(newPosition);
|
||||
newPosition = distribution(generator);
|
||||
return newPosition;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
sf::RectangleShape snakeFoodObject;
|
||||
SnakeFood();
|
||||
SnakeFood(sf::Vector2f snakeFoodSize);
|
||||
void GenerateNewLocation(int maxLocation);
|
||||
int GenerateNewLocation(int maxLocation);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user