You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
80 lines
1.7 KiB
9 years ago
|
#include "Map.h"
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
|
||
|
Map::Map() {
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
|
||
|
Map::~Map() {
|
||
|
}
|
||
|
|
||
|
Tile* Map::getTile(sf::Vector2i position_) {
|
||
9 years ago
|
|
||
|
// If the position is within bounds
|
||
9 years ago
|
if (position_.x > CELLS_WIDTH || position_.x < 0
|
||
|
|| position_.y > CELLS_HEIGHT || position_.y < 0) {
|
||
|
return nullptr;
|
||
|
}
|
||
9 years ago
|
else
|
||
|
// Return the value specified
|
||
|
return tileArray[position_.x][position_.y];
|
||
9 years ago
|
}
|
||
|
|
||
|
bool Map::isTileSolid(sf::Vector2i position_) {
|
||
9 years ago
|
|
||
|
// If the position is within bounds
|
||
9 years ago
|
if (position_.x >= CELLS_WIDTH || position_.x < 0
|
||
|
|| position_.y >= CELLS_HEIGHT || position_.y < 0) {
|
||
9 years ago
|
return true; // If it isn't say that the tile is solid
|
||
9 years ago
|
}
|
||
|
else
|
||
9 years ago
|
// Return whether the tile is solid
|
||
9 years ago
|
return tileArray[position_.x][position_.y]->isSolid();
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
Tile* Map::getTile(int x_, int y_) {
|
||
9 years ago
|
|
||
|
// 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_];
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
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;
|
||
|
}
|
||
9 years ago
|
}
|
||
|
|
||
|
void Map::Init() {
|
||
9 years ago
|
|
||
|
// Fill up the map with a random scatter of solid and passable tiles
|
||
|
|
||
9 years ago
|
int q;
|
||
|
|
||
|
for (int x = 0; x < CELLS_WIDTH; x++) {
|
||
|
for (int y = 0; y < CELLS_HEIGHT; y++) {
|
||
|
q = rand() % 100;
|
||
9 years ago
|
if (q > 65) {
|
||
9 years ago
|
tileArray[x][y] = new Tile(true, 100.0, sf::Color::Cyan);
|
||
|
}
|
||
|
else {
|
||
|
tileArray[x][y] = new Tile(false, 0.0, sf::Color::Red);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|