1
General / Re: [XCode] Trying to use C++11 features
« on: May 28, 2016, 09:35:48 pm »
Actually I just got everything to work. Essentially what I did was make the Tiles const pointers
Made some functions constant, made the tiles 2d vector in dungeon store const Tile *, and change their functions to go with it.
So I suppose thank you guys
//Tile.cpp
Tile::Tile() : color(*new sf::Color(0,0,0)), canMoveIn(false), name("void") {}
Tile::Tile(sf::Color c, bool moveIn, std::string n) : color(c), name(n) {
this->canMoveIn = moveIn;
}
const Tile *Tile::FLOOR = new Tile::Tile(sf::Color(0, 126, 0), true, "floor");
const Tile *Tile::WALL = new Tile::Tile(sf::Color(126, 126, 126), false, "wall");
const Tile *Tile::VOID = new Tile::Tile();
Tile::Tile() : color(*new sf::Color(0,0,0)), canMoveIn(false), name("void") {}
Tile::Tile(sf::Color c, bool moveIn, std::string n) : color(c), name(n) {
this->canMoveIn = moveIn;
}
const Tile *Tile::FLOOR = new Tile::Tile(sf::Color(0, 126, 0), true, "floor");
const Tile *Tile::WALL = new Tile::Tile(sf::Color(126, 126, 126), false, "wall");
const Tile *Tile::VOID = new Tile::Tile();
Made some functions constant, made the tiles 2d vector in dungeon store const Tile *, and change their functions to go with it.
//Dungeon.cpp
Dungeon::Dungeon(int width, int height) : width(width/Tile::TILE_SIZE), height(height/Tile::TILE_SIZE), tiles(this->height) {
//I had a BAD_ACCESS error or something here so I did the following line of code.
tiles = vector<vector<const Tile *>>(this->height);
for (int y = 0; y < this->height; y++) {
tiles.push_back(vector<const Tile *>(this->width));
for(int x = 0; x < this->width; x++) {
tiles[y].push_back(Tile::VOID);
}
}
for (int x = 0; x < this->width; x++) {
for (int y = 0; y < this->height; y++) {
tiles[y][x] = rand() % 10 < 5 ? Tile::FLOOR : Tile::WALL;
}
}
}
const Tile * Dungeon::tile(int x, int y ) {
if (x < 0 || x >= width || y < 0 || y >= height) {
return Tile::VOID;
}
return tiles[y][x];
}
Dungeon::Dungeon(int width, int height) : width(width/Tile::TILE_SIZE), height(height/Tile::TILE_SIZE), tiles(this->height) {
//I had a BAD_ACCESS error or something here so I did the following line of code.
tiles = vector<vector<const Tile *>>(this->height);
for (int y = 0; y < this->height; y++) {
tiles.push_back(vector<const Tile *>(this->width));
for(int x = 0; x < this->width; x++) {
tiles[y].push_back(Tile::VOID);
}
}
for (int x = 0; x < this->width; x++) {
for (int y = 0; y < this->height; y++) {
tiles[y][x] = rand() % 10 < 5 ? Tile::FLOOR : Tile::WALL;
}
}
}
const Tile * Dungeon::tile(int x, int y ) {
if (x < 0 || x >= width || y < 0 || y >= height) {
return Tile::VOID;
}
return tiles[y][x];
}
So I suppose thank you guys