Hi,
I solved my problem, and I'm writing this post in case anyone else would like to use my solution.
Basically it was to create a tile class, cycle through the vector of characters stored in the Dungeon class to get the characters and their x and y positions, and to place a tile there based on its name via a string.
Tile.h
class Tile
{
public:
Tile();
Tile(const std::string tileType);
Tile(const std::string tileType, int x, int y);
void update();
void draw(sf::RenderWindow &window);
private:
sf::Sprite m_sprite;
sf::Texture m_texture;
sf::Vector2f m_pos;
std::string m_id;
};
Tile.cpp
Tile::Tile()
{
}
Tile::Tile(const std::string tileType)
{
}
Tile::Tile(const std::string tileType, int x, int y)
{
int posX = x * 16;
int posY = y * 16;
m_texture.loadFromFile(tileType + ".png");
m_sprite.setTexture(m_texture);
m_sprite.setPosition(sf::Vector2f(posX, posY));
m_id = tileType;
}
void Tile::update()
{
}
void Tile::draw(sf::RenderWindow &window)
{
window.draw(m_sprite);
}
Then back in main() I use this code to populate a tile vector with the correct tiles, and draw them.
std::vector<Tile*> tileVector;
//enum Tile
//{
// Unused = ' ',
// Floor = '.',
// Corridor = ',',
// Wall = '#',
// ClosedDoor = '+',
// OpenDoor = '-',
// UpStairs = '<',
// DownStairs = '>'
//};
for (int x = 0; x <= 79; x++)
{
for (int y = 0; y <= 24; y++)
{
if (d.getTile(x, y) == ' ')
{
tileVector.push_back(new Tile("floor", x, y));
}
if (d.getTile(x, y) == '#')
{
tileVector.push_back(new Tile("wall", x, y));
}
if (d.getTile(x, y) == '.')
{
tileVector.push_back(new Tile("empty", x, y));
}
if (d.getTile(x, y) == '+')
{
tileVector.push_back(new Tile("closedDoor", x, y));
}
}
}
while (window->isOpen())
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
window->close();
}
window->clear();
int size = tileVector.size();
for (int i = 0; i < size; i++)
{
tileVector.at(i)->draw(*window);
}
window->display();
}
Thanks for the suggestions everyone.
edit: here's a picture for you to see what it turned out like if you're interested in these algorithms