0 Members and 1 Guest are viewing this topic.
class DrawTileMapDungeon : public sf::Drawable//, public sf::Transformable{ public: void load (const Texture tileset, int ( &TileMap )[500][500]); void update (int ( &TileMap )[500][500]); private: virtual void draw (sf::RenderTarget& target, sf::RenderStates states) const; VertexArray m_vertices; Texture m_tileset; Vector2u tileSize = {64, 64};};
#include "DrawTileMapDungeon.h"//==================================================================================================void DrawTileMapDungeon::load(const Texture tileset, int ( &TileMap )[500][500]){ m_tileset = tileset; m_vertices.setPrimitiveType(sf::Quads); m_vertices.resize(500 * 500 * 4);}//==================================================================================================void DrawTileMapDungeon::update(int ( &TileMap )[500][500]){ int tu = 0; int tv = 0; for(unsigned int x = 0; x < 500; ++x) for(unsigned int y = 0; y < 500; ++y) { switch(TileMap[y]) { case 1: tu = 0;tv = 2;break; case 2: tu = 1;tv = 2;break; case 3: tu = 2;tv = 2;break; case 4: tu = 3;tv = 2;break; case 5: tu = 4;tv = 2;break; case 6: tu = 0;tv = 3;break; case 7: tu = 1;tv = 3;break; case 8: tu = 2;tv = 3;break; case 9: tu = 3;tv = 3;break; case 10: tu = 4;tv = 3;break; default:tu = 0;tv = 0;break; } sf::Vertex* tile64 = &m_vertices[(x + y * 500) * 4]; tile64[0].position = sf::Vector2f(x * tileSize.x, y * tileSize.y); tile64[1].position = sf::Vector2f((x + 1) * tileSize.x, y * tileSize.y); tile64[2].position = sf::Vector2f((x + 1) * tileSize.x, (y + 1) * tileSize.y); tile64[3].position = sf::Vector2f(x * tileSize.x, (y + 1) * tileSize.y); tile64[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y); tile64[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y); tile64[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y); tile64[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y); }}//==================================================================================================void DrawTileMapDungeon::draw(sf::RenderTarget& target, sf::RenderStates states) const{ //states.transform *= getTransform(); states.texture = &m_tileset; target.draw(m_vertices, states);}//==================================================================================================