#pragma once

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <tmxlite/Map.hpp>
#include "Shared.hpp"
#include "Player.hpp"
#include "NumText.hpp"
#include "Portal.hpp"
#include "Kebab.hpp"
#include "SFMLOrthogonalLayer.hpp"

#define LAYERCOUNT 5

using namespace sf;

struct Global {
 	int lives;
	unsigned score;
	unsigned high;
	bool restart;
	RenderWindow window;
	Music music;
	bool reachedEast;
};

class Core {
public:
	Core() = delete;
	Core(Global* lg);
	virtual ~Core();
	void run();
private:
	void think(float delta);
	void loop(float delta);
	void render();

	Global* g;
	View _view;
	Shared _settings;
 	Player _player;
	tmx::Map map;

	MapLayer _layer[LAYERCOUNT];

	Texture _background_tx;
	Sprite _background;
	Texture _evm_tx;
	Sprite _evm;
	Texture _fog_tx;
	Sprite _fog;

	Sprite _head;
	Texture _head_tx;

	Sprite _frame;
	Texture _frame_tx;

	Sprite _hud_score;
	Sprite _hud_highscore;
	Sprite _hud_time;
	Sprite _hud_energy;
	Texture _hud_tx;

	Texture _font;
	NumText _score_text;
	NumText _highscore_text;
	NumText _time_text;
	NumText _energy_text;

	RectangleShape debug;
	RectangleShape debug2;

	std::vector<Corrupted> _corrupted;
	std::vector<Kebab> keb;
	Clock _corr_clock;

	Portal _p1;
	Portal _p2;
	Portal _p3;

	Texture splashtx;
	Sprite splash;

	int _lives;

	Clock _s1c;

	Sprite _trixie;
	Texture _trix;

	bool timegranted;

	Texture ggtex;
	std::vector<Sprite> gg;

	SoundBuffer boom;
	Sound sht;

	std::vector<IntRect> jedi;
	Clock jediClock;
};