Add more Ground and Above layers

This commit is contained in:
Riyyi
2015-03-22 15:16:50 +01:00
parent 0aff9f62bb
commit cbf33e2ffa
6 changed files with 118 additions and 13 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+21 -1
View File
@@ -13,12 +13,16 @@ TileSet::~TileSet() {
Map::Map() { Map::Map() {
this->ground1 = new Layer(); this->ground1 = new Layer();
this->ground2 = new Layer();
this->ground3 = new Layer();
this->above1 = new Layer(); this->above1 = new Layer();
this->above2 = new Layer();
this->above3 = new Layer();
this->collision = new Layer(); this->collision = new Layer();
this->tileSet = new TileSet(); this->tileSet = new TileSet();
} }
void Map::CheckCollision(sf::RenderWindow *window, Entity *entity) { void Map::CheckCollision(Entity *entity) {
// Get check section // Get check section
sf::Vector2f checkWidth = sf::Vector2f( sf::Vector2f checkWidth = sf::Vector2f(
(int)entity->getPosition().x / this->tileSet->tileWidth, (int)entity->getPosition().x / this->tileSet->tileWidth,
@@ -98,11 +102,23 @@ void Map::CheckCollision(sf::RenderWindow *window, Entity *entity) {
void Map::RenderGround(sf::RenderWindow *window) { void Map::RenderGround(sf::RenderWindow *window) {
Layer* layer = this->ground1; Layer* layer = this->ground1;
this->Render(window, layer); this->Render(window, layer);
layer = this->ground2;
this->Render(window, layer);
layer = this->ground3;
this->Render(window, layer);
} }
void Map::RenderAbove(sf::RenderWindow *window) { void Map::RenderAbove(sf::RenderWindow *window) {
Layer* layer = this->above1; Layer* layer = this->above1;
this->Render(window, layer); this->Render(window, layer);
layer = this->above2;
this->Render(window, layer);
layer = this->above3;
this->Render(window, layer);
} }
void Map::Render(sf::RenderWindow *window, Layer *layer) { void Map::Render(sf::RenderWindow *window, Layer *layer) {
@@ -134,6 +150,10 @@ void Map::Render(sf::RenderWindow *window, Layer *layer) {
Map::~Map() { Map::~Map() {
delete this->tileSet; delete this->tileSet;
delete this->ground1; delete this->ground1;
delete this->ground2;
delete this->ground3;
delete this->above1; delete this->above1;
delete this->above2;
delete this->above3;
delete this->collision; delete this->collision;
} }
+5 -1
View File
@@ -55,14 +55,18 @@ class Map
{ {
public: public:
Map(); Map();
void CheckCollision(sf::RenderWindow *window, Entity *entity); void CheckCollision(Entity *entity);
void RenderGround(sf::RenderWindow *window); void RenderGround(sf::RenderWindow *window);
void RenderAbove(sf::RenderWindow *window); void RenderAbove(sf::RenderWindow *window);
~Map(); ~Map();
int height; int height;
Layer* ground1; Layer* ground1;
Layer* ground2;
Layer* ground3;
Layer* above1; Layer* above1;
Layer* above2;
Layer* above3;
Layer* collision; Layer* collision;
// "nextobjectid":1, // "nextobjectid":1,
// "orientation":"orthogonal", // "orientation":"orthogonal",
+12
View File
@@ -52,9 +52,21 @@ void MapLoad::LoadLayer(const rapidjson::Document& document, Map *map) {
if(document["layers"][i]["properties"]["name"] == "Ground1") { if(document["layers"][i]["properties"]["name"] == "Ground1") {
current = map->ground1; current = map->ground1;
} }
else if(document["layers"][i]["properties"]["name"] == "Ground2") {
current = map->ground2;
}
else if(document["layers"][i]["properties"]["name"] == "Ground3") {
current = map->ground3;
}
else if(document["layers"][i]["properties"]["name"] == "Above1") { else if(document["layers"][i]["properties"]["name"] == "Above1") {
current = map->above1; current = map->above1;
} }
else if(document["layers"][i]["properties"]["name"] == "Above2") {
current = map->above2;
}
else if(document["layers"][i]["properties"]["name"] == "Above3") {
current = map->above3;
}
if(document["layers"][i]["properties"]["name"] == "Collision") { if(document["layers"][i]["properties"]["name"] == "Collision") {
current = map->collision; current = map->collision;
} }
+1 -1
View File
@@ -34,7 +34,7 @@ void MainGame::Update(sf::RenderWindow* window) {
this->player->Update(window, inputManager, timeElapsed); this->player->Update(window, inputManager, timeElapsed);
this->entityManager->Update(); this->entityManager->Update();
this->map->CheckCollision(window, this->player); this->map->CheckCollision(this->player);
this->camera->Update(window, this->map, sf::Vector2f(this->player->getPosition().x, this->player->getPosition().y)); this->camera->Update(window, this->map, sf::Vector2f(this->player->getPosition().x, this->player->getPosition().y));
if(inputManager.IsPressed(InputManager::LoadMap)) { if(inputManager.IsPressed(InputManager::LoadMap)) {