#pragma once

#include "Util.h"
#include "Player.h"
#include "Fruit.h"
#include "GameConfig.h"

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <imgui-SFML.h>
#include <imgui.h>

enum class GameState
{
	playing,
	lose,
	win
};

class Game 
{
public:
	Game(bool useImgui_in);

	void run();

	bool init();

private:
	void imgui();

	void render();

	void input();

	void collision();

	void movement();

	void resetGame();

	bool parseConfigFile();

	void soundSystem();

	void scoreSystem();

	void failState();

	void winState();

	void setNewBounds();


private:
	GameConfig config;
	sf::Clock clock; 
	sf::RenderWindow window;
	sf::Font font;
	sf::Text score;
	
	sf::SoundBuffer failSoundBuffer;
	sf::SoundBuffer winSoundBuffer;
	sf::SoundBuffer bgMusicBuffer;
	sf::SoundBuffer eatSoundBuffer;
	sf::SoundBuffer moveSoundBuffer;

	sf::Sound failSound;
	sf::Sound winSound;
	sf::Sound bgMusic;
	sf::Sound eatSound;
	sf::Sound moveSound;

	sf::RectangleShape tempRect;
	sf::RectangleShape gameBoundary;
	
	//sf::Sound failSound;
	
	Player player{};
	Fruit fruit{};

	size_t frameCount{};
	size_t fruitEaten{};
	GameState state{GameState::playing};
	bool useImgui;
	bool fail{};
	bool win{};
	bool running{true};
};