Prettied it up, comments, refactors
This commit is contained in:
@@ -10,41 +10,64 @@ Map::Map() {
|
||||
Map::~Map() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tile* Map::getTile(sf::Vector2i position_) {
|
||||
|
||||
// If the position is within bounds
|
||||
if (position_.x > CELLS_WIDTH || position_.x < 0
|
||||
|| position_.y > CELLS_HEIGHT || position_.y < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return tileArray[position_.x][position_.y];
|
||||
else
|
||||
// Return the value specified
|
||||
return tileArray[position_.x][position_.y];
|
||||
}
|
||||
|
||||
bool Map::isTileSolid(sf::Vector2i position_) {
|
||||
|
||||
// If the position is within bounds
|
||||
if (position_.x >= CELLS_WIDTH || position_.x < 0
|
||||
|| position_.y >= CELLS_HEIGHT || position_.y < 0) {
|
||||
return true;
|
||||
return true; // If it isn't say that the tile is solid
|
||||
}
|
||||
else
|
||||
// Return whether the tile is solid
|
||||
return tileArray[position_.x][position_.y]->isSolid();
|
||||
}
|
||||
|
||||
Tile* Map::getTile(int x_, int y_) {
|
||||
return tileArray[x_][y_];
|
||||
|
||||
// If the position is within bounds
|
||||
if (x_ > CELLS_WIDTH || x_ < 0
|
||||
|| y_ > CELLS_HEIGHT || y_ < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
// Return the value specified
|
||||
return tileArray[x_][y_];
|
||||
}
|
||||
|
||||
void Map::setTile(sf::Vector2i position, Tile* data) {
|
||||
delete tileArray[position.x][position.y];
|
||||
tileArray[position.x][position.y] = data;
|
||||
void Map::overwriteTile(sf::Vector2i position_, Tile* data) {
|
||||
// If the position is within bounds
|
||||
if (position_.x >= CELLS_WIDTH || position_.x < 0
|
||||
|| position_.y >= CELLS_HEIGHT || position_.y < 0) {
|
||||
return; // If it isn't just return
|
||||
}
|
||||
else { // If it is, then delete the old data, replace it with the new
|
||||
delete tileArray[position_.x][position_.y];
|
||||
tileArray[position_.x][position_.y] = data;
|
||||
}
|
||||
}
|
||||
|
||||
void Map::Init() {
|
||||
|
||||
// Fill up the map with a random scatter of solid and passable tiles
|
||||
|
||||
int q;
|
||||
|
||||
for (int x = 0; x < CELLS_WIDTH; x++) {
|
||||
for (int y = 0; y < CELLS_HEIGHT; y++) {
|
||||
q = rand() % 100;
|
||||
if (q > 90) {
|
||||
if (q > 65) {
|
||||
tileArray[x][y] = new Tile(true, 100.0, sf::Color::Cyan);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user