Browse Source

Add more Ground and Above layers

master
Riyyi 10 years ago
parent
commit
cbf33e2ffa
  1. 57
      src/data/map/level1.json
  2. 32
      src/data/map/level1.tmx
  3. 22
      src/map.cpp
  4. 6
      src/map.h
  5. 12
      src/mapload.cpp
  6. 2
      src/state/maingame.cpp

57
src/data/map/level1.json

File diff suppressed because one or more lines are too long

32
src/data/map/level1.tmx

File diff suppressed because one or more lines are too long

22
src/map.cpp

@ -13,12 +13,16 @@ TileSet::~TileSet() {
Map::Map() {
this->ground1 = new Layer();
this->ground2 = new Layer();
this->ground3 = new Layer();
this->above1 = new Layer();
this->above2 = new Layer();
this->above3 = new Layer();
this->collision = new Layer();
this->tileSet = new TileSet();
}
void Map::CheckCollision(sf::RenderWindow *window, Entity *entity) {
void Map::CheckCollision(Entity *entity) {
// Get check section
sf::Vector2f checkWidth = sf::Vector2f(
(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) {
Layer* layer = this->ground1;
this->Render(window, layer);
layer = this->ground2;
this->Render(window, layer);
layer = this->ground3;
this->Render(window, layer);
}
void Map::RenderAbove(sf::RenderWindow *window) {
Layer* layer = this->above1;
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) {
@ -134,6 +150,10 @@ void Map::Render(sf::RenderWindow *window, Layer *layer) {
Map::~Map() {
delete this->tileSet;
delete this->ground1;
delete this->ground2;
delete this->ground3;
delete this->above1;
delete this->above2;
delete this->above3;
delete this->collision;
}

6
src/map.h

@ -55,14 +55,18 @@ class Map
{
public:
Map();
void CheckCollision(sf::RenderWindow *window, Entity *entity);
void CheckCollision(Entity *entity);
void RenderGround(sf::RenderWindow *window);
void RenderAbove(sf::RenderWindow *window);
~Map();
int height;
Layer* ground1;
Layer* ground2;
Layer* ground3;
Layer* above1;
Layer* above2;
Layer* above3;
Layer* collision;
// "nextobjectid":1,
// "orientation":"orthogonal",

12
src/mapload.cpp

@ -52,9 +52,21 @@ void MapLoad::LoadLayer(const rapidjson::Document& document, Map *map) {
if(document["layers"][i]["properties"]["name"] == "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") {
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") {
current = map->collision;
}

2
src/state/maingame.cpp

@ -34,7 +34,7 @@ void MainGame::Update(sf::RenderWindow* window) {
this->player->Update(window, inputManager, timeElapsed);
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));
if(inputManager.IsPressed(InputManager::LoadMap)) {

Loading…
Cancel
Save