#pragma once

#include <vector>

#include <Util.h>

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


struct Ball
{
	Ball(sf::Vector2f position_in, sf::Vector2f vel_in);

	sf::Vector2f pos;
	sf::Vector2f velocity;
	sf::Vector2f previousPos{};
	bool alive{true};
};

struct Brick
{
	Brick(sf::Vector2f position_in);

	sf::Vector2f pos;
	bool alive{true};
};

struct Player 
{
	Player() = default;
	Player(sf::Vector2f position_in);

	sf::Vector2f pos{};
	sf::Vector2f previousPos{};
	float score{};
	int lives{3};
	bool left{false};
	bool right{false};
};

class Game 
{
public:
	Game();

	void run();
	void runNoImgui();

private:
	void imgui();

	void render();

	void input();

	void collision();

	void movement();

	void updateEntities();

	void checkEndGame();

	void checkBallCollision();

	void resetGame();

	bool parseConfigFile();


private:
	sf::Clock clock; 
	sf::RenderWindow window;

	Player player;
	std::vector<Ball> balls;
	std::vector<Brick> bricks;
	std::vector<Brick> specialBricks;
	std::vector<sf::Vector2f> ballsToAdd;
	sf::CircleShape tempCircle;
	sf::RectangleShape tempRect;

	// mostly used for imgui
	sf::Vector2f brickSize{};
	sf::Vector2f playerSize{};
	sf::Vector2f playerStartPos{};
	sf::Vector2f brickHalfSize{};
	sf::Vector2f playerHalfSize{};
	int rowSize{};
	int columnSize{};
	int totalSpecialBricks{};
	int totalBricks{rowSize * columnSize};
	unsigned int framerate{};
	float playerSpeed{};
	float ballRadius{};
	float ballMaxSpeed{};
	Color ballColor{};
	Color brickColor{};
	Color playerColor{};
	Color specialBrickColor{};
	bool windowCollasped{false};
	static constexpr unsigned int numPhysicsUpdates{4};
};