//
//  MapLayer.h
//  GlobalGameJam15
//
//  Created by Cesar Parent on 24/01/2015.
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#ifndef __GlobalGameJam15__MapLayer__
#define __GlobalGameJam15__MapLayer__

#include <PixelKit/PixelKit.h>
#include <vector>
#include <stack>
#include "Defines.h"

using namespace PixelKit;

class Entity;
class Tile;

typedef enum
{
	kTileDirt = 0,
	kTileWall,
	kTileFloor
} TileMask;

class MapLayer : public Layer
{
public:
	
	float flicker;
	
	MapLayer(Game& game, Entity* character);
	virtual ~MapLayer();

	
	virtual bool moveAllowed(Point<int> targetTile);
	virtual Point<float> playerPosition();
	virtual void update(int timeInterval) override;
	virtual float distanceToPlayer(int x, int y);
	virtual Point<float> orthoDistance(int x, int y);
	int aliveNeighbours(int tileX, int tileY);
	
protected:
	
	Entity* _player;
	std::vector<Tile*> _tiles;
	Uint8 _map[kMapWidth][kMapHeight];
	Uint8 _checkMap[kMapWidth][kMapHeight];
	
	virtual void _createMap();
	virtual void _layTiles();
	
private:
	
	void fillRandomMap();
	void cellullarStep();
	bool checkMap();
	int floodFillStep(int x, int y, Uint8 newUID, std::stack<Point<int>>& stack);
	int floodFill(int x, int y, Uint8 newUID);
	
};

#endif /* defined(__GlobalGameJam15__MapLayer__) */
