implemented TileMap, still need Shader for it with billboarding and all that jizz XD
This commit is contained in:
54
TSE_Core/src/BehaviourScripts/TileMap.cpp
Normal file
54
TSE_Core/src/BehaviourScripts/TileMap.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "TileMap.hpp"
|
||||
|
||||
TSE::TileMapChunk::TileMapChunk(int _chunksize, const Vector2 &_pos, SortingOrder _order)
|
||||
{
|
||||
chunksize = _chunksize;
|
||||
pos = _pos;
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set)
|
||||
{
|
||||
Sprite s;
|
||||
set->GetSpriteAt(Spriteindex, s);
|
||||
sprites[p] = s;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::RemoveTile(Vector2 p)
|
||||
{
|
||||
sprites.erase(p);
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::SetOrdering(SortingOrder _order)
|
||||
{
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMap::RemoveTile(Vector2 p)
|
||||
{
|
||||
Vector2 chunkInnerPos = LocalToChunkPos(p);
|
||||
Vector2 chunkIndex = p - chunkInnerPos;
|
||||
if(chunks.contains(chunkIndex))
|
||||
chunks[chunkIndex].RemoveTile(chunkInnerPos);
|
||||
}
|
||||
|
||||
void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex)
|
||||
{
|
||||
Vector2 chunkInnerPos = LocalToChunkPos(p);
|
||||
Vector2 chunkIndex = p - chunkInnerPos;
|
||||
if(!chunks.contains(chunkIndex))
|
||||
{
|
||||
chunks[chunkIndex] = TileMapChunk(chunkSize, chunkIndex, order);
|
||||
}
|
||||
chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, set);
|
||||
}
|
||||
|
||||
TSE::Vector2 TSE::TileMap::LocalToChunkPos(const Vector2 &v)
|
||||
{
|
||||
return Vector2((int)v.x % chunkSize, (int)v.y % chunkSize);
|
||||
}
|
||||
|
||||
TSE::Vector2 TSE::TileMap::ChunkToLocalPos(const Vector2 &v, const TileMapChunk &chunk)
|
||||
{
|
||||
return v + chunk.pos * chunkSize;
|
||||
}
|
||||
Reference in New Issue
Block a user