#pragma once

#include "Log.hpp"

#define CW 20
#define CH 12 

class Collider: public IEntity {
public:
	enum {
		AIR, SAND, FALLINGSAND, SOLID, SPIKE, LEVER
	};
	bool isSafe(int x, int y) {
		int tile = m_tile[getTile(x, y)];
		return tile == -1 ? true : tile != FALLINGSAND && tile != SPIKE;
	}
	bool isSolid(int x, int y) {
		int tile = m_tile[getTile(x, y)];
		return tile == -1 ? true : tile != AIR && tile != LEVER;
	}
	int getBlock(int x, int y) {
		return m_tile[getTile(x, y)];
	}
	void setBlock(int x, int y, int type) {
		m_tile[getTile(x, y)] = type;
	}
	void populate(std::vector<int> data) {
		std::copy(data.begin(), data.end(), m_tile);
		std::copy(data.begin(), data.end(), m_base);
	}
	float getLocalX() {
		return m_localX;
	}
	void setLocalX(float localX) {
		m_localX = localX;
	}
	void update(float delta) {
		std::copy(m_base, m_base + CW * CH, m_tile);
	}

private:
	int getTile(int x, int y) {
		if(x < 0 || y < 0 || x >= CW || y >= CH) {
			return -1;
		}
		return x + CW * y;
	}
	int m_tile[CW * CH];
	int m_base[CW * CH];
	float m_localX;
};
