Replaced setTile with insertTile and removeTile.
This commit is contained in:
parent
f0a9c3320d
commit
637ea180c3
3 changed files with 35 additions and 11 deletions
|
@ -39,16 +39,23 @@ Game::Game(sf::RenderWindow& window) :
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Game::generate() {
|
Game::generate() {
|
||||||
for (int x = 0; x < 10; x++)
|
for (int x = 0; x < 11; x++)
|
||||||
for (int y = 0; y < 10; y++)
|
mTileManager.insertTile(TileManager::TilePosition(x, 0), TileManager::Type::WALL);
|
||||||
mTileManager.setTile(TileManager::TilePosition(x, y), TileManager::Type::WALL);
|
for (int x = 0; x < 11; x++)
|
||||||
|
mTileManager.insertTile(TileManager::TilePosition(x, 10), TileManager::Type::WALL);
|
||||||
|
for (int y = 1; y < 9; y++)
|
||||||
|
mTileManager.insertTile(TileManager::TilePosition(0, y), TileManager::Type::WALL);
|
||||||
|
for (int y = 1; y < 9; y++)
|
||||||
|
mTileManager.insertTile(TileManager::TilePosition(10, y), TileManager::Type::WALL);
|
||||||
|
|
||||||
for (int x = 1; x < 9; x++)
|
for (int x = 1; x < 10; x++)
|
||||||
for (int y = 1; y < 9; y++)
|
for (int y = 1; y < 10; y++)
|
||||||
mTileManager.setTile(TileManager::TilePosition(x, y), TileManager::Type::FLOOR);
|
mTileManager.insertTile(TileManager::TilePosition(x, y), TileManager::Type::FLOOR);
|
||||||
|
|
||||||
for (int x = 1; x < 5; x++)
|
for (int x = 1; x < 5; x++) {
|
||||||
mTileManager.setTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL);
|
mTileManager.removeTile(TileManager::TilePosition(x, 4));
|
||||||
|
mTileManager.insertTile(TileManager::TilePosition(x, 4), TileManager::Type::WALL);
|
||||||
|
}
|
||||||
|
|
||||||
mWorld.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, mPathfinder,
|
mWorld.insert(std::shared_ptr<Sprite>(new Enemy(mWorld, mPathfinder,
|
||||||
sf::Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
|
sf::Vector2f(400.0f, 200.0f), Yaml("enemy.yaml"))));
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "TileManager.h"
|
#include "TileManager.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <Thor/Resources.hpp>
|
#include <Thor/Resources.hpp>
|
||||||
|
@ -85,17 +86,32 @@ TileManager::Tile::getTilePosition() const {
|
||||||
* @param type Type of tile to be inserted.
|
* @param type Type of tile to be inserted.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
TileManager::setTile(const TilePosition& position, Type type) {
|
TileManager::insertTile(const TilePosition& position, Type type) {
|
||||||
|
#ifndef NDEBUG
|
||||||
for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
|
for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
|
||||||
if ((*it)->getTilePosition() == position) {
|
if ((*it)->getTilePosition() == position) {
|
||||||
mTiles.erase(it);
|
// Inserted multiple tiles at the same position.
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
std::shared_ptr<Tile> tile = std::shared_ptr<Tile>(new Tile(type, position));
|
std::shared_ptr<Tile> tile = std::shared_ptr<Tile>(new Tile(type, position));
|
||||||
mTiles.push_back(tile);
|
mTiles.push_back(tile);
|
||||||
mWorld.insert(tile);
|
mWorld.insert(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TileManager::removeTile(const TilePosition& position) {
|
||||||
|
for (auto it = mTiles.begin(); it != mTiles.end(); it++) {
|
||||||
|
if ((*it)->getTilePosition() == position) {
|
||||||
|
mWorld.remove(*it);
|
||||||
|
mTiles.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \copydoc sf::Drawable::draw
|
* \copydoc sf::Drawable::draw
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,7 +40,8 @@ public:
|
||||||
public:
|
public:
|
||||||
TileManager(World& world);
|
TileManager(World& world);
|
||||||
|
|
||||||
void setTile(const TilePosition& position, Type type);
|
void insertTile(const TilePosition& position, Type type);
|
||||||
|
void removeTile(const TilePosition& position);
|
||||||
|
|
||||||
// Private types.
|
// Private types.
|
||||||
private:
|
private:
|
||||||
|
|
Reference in a new issue