#ifndef WORLD_H
#define WORLD_H

#include <irrlicht.h>
#include "entity.h"
#include "connection.h"
#include "Player.h"

using namespace irr;

class World : public IEventReceiver
{
private:
	core::array<Entity*> entities;
	core::array<Connection*> connections;
	Player* player;
	scene::ISceneManager* smgr;

public:
	World(scene::ISceneManager* smgr);

	~World()
	{
		destroyLevel();
		delete player;
	}

	void destroyLevel()
	{
		player->setTarget(NULL);
		player->draggingConnection = NULL;
		for (u32 i = 0; i < entities.size(); ++i)
		{
			delete entities[i];
		}
		entities.clear();
		for (u32 i = 0; i < connections.size(); ++i)
		{
			delete connections[i];
		}
		connections.clear();
	}
	void createLevel();

	void add(Entity* entity);

	void update(float deltaTime);

	void drawUI();
	void drawNum(int& X, int Y, int num);

	video::ITexture* lifeImg;
	video::ITexture* levelImg;
	video::ITexture* numImg;

	int level;

	bool clicked, play;
	bool playerCanDie;

public:
	virtual bool OnEvent(const SEvent& e);
};

#endif