#include "pch.h" #include "Tile.h" #include "Item.h" #include "Texture.h" int Tile::m_Count{ 0 }; const float Tile::m_Size{ 64.f }; Texture* Tile::m_pGoldTextures{ nullptr }; Tile::Tile(int x, int y, int itemType) : m_Position{ x * m_Size, y * m_Size } , m_X{ x } , m_Y{ y } , m_Item{ itemType } { m_DrawBorder[int(Direction::UP)] = false; m_DrawBorder[int(Direction::DOWN)] = false; m_DrawBorder[int(Direction::LEFT)] = false; m_DrawBorder[int(Direction::RIGHT)] = false; m_Vertices.push_back(Point2f{ m_Position.x , m_Position.y }); m_Vertices.push_back(Point2f{ m_Position.x + m_Size , m_Position.y }); m_Vertices.push_back(Point2f{ m_Position.x + m_Size , m_Position.y + m_Size }); m_Vertices.push_back(Point2f{ m_Position.x , m_Position.y + m_Size }); if (m_pGoldTextures == nullptr) { m_pGoldTextures = new Texture{ "Resources/Sprites/gold_tiles.png" }; } m_Count++; } int Tile::GetX() const { return m_X; } int Tile::GetY() const { return m_Y; } Tile::~Tile() { m_Count--; if (m_Count == 0) { delete m_pGoldTextures; m_pGoldTextures = nullptr; } } void Tile::SetBorder(Direction dir, bool value) { m_DrawBorder[int(dir)] = value; } void Tile::DrawVertices() const { float vertexSize = 4; glLineWidth(1); glColor4f(.5f, .5f, .5f, 1); glBegin(GL_LINE_LOOP); for (Point2f vertex : m_Vertices) { glVertex2f(vertex.x, vertex.y); } glEnd(); glColor4f(0, 0, 1, 1); for (Point2f vertex : m_Vertices) { utils::FillRect(Point2f{ vertex.x - vertexSize / 2, vertex.y - vertexSize / 2 }, vertexSize, vertexSize); } } std::vector Tile::GetVertices() const { return m_Vertices; } std::vector Tile::GetLedgeVertices() const { float grabDistance{ 8 }; std::vector vertices{ Point2f { m_Vertices[0].x, m_Vertices[0].y + Tile::m_Size - grabDistance },Point2f { m_Vertices[1].x, m_Vertices[1].y + Tile::m_Size - grabDistance }, m_Vertices[2], m_Vertices[3] }; return vertices; } void Tile::DrawItem() const { //Draw gold/item overlay switch (Item::Type(m_Item)) { case Item::Type::GOLD_CHUNK_SMALL: m_pGoldTextures->Draw(Point2f{ m_Position.x, m_Position.y }, Rectf{ 0, 0, m_Size, m_Size }); break; case Item::Type::GOLD_CHUNK_BIG: m_pGoldTextures->Draw(Point2f{ m_Position.x, m_Position.y }, Rectf{ 64, 0, m_Size, m_Size }); break; default: break; } }