Browse Source

Add Map render Ground and Above

Render layer Ground below and Above above Player.
master
Riyyi 10 years ago
parent
commit
9b6b33845d
  1. 4
      src/data/map/level1.json
  2. 4
      src/data/map/level1.tmx
  3. 14
      src/map.cpp
  4. 6
      src/map.h
  5. 3
      src/state/maingame.cpp

4
src/data/map/level1.json

File diff suppressed because one or more lines are too long

4
src/data/map/level1.tmx

File diff suppressed because one or more lines are too long

14
src/map.cpp

@ -18,7 +18,17 @@ Map::Map() {
this->tileSet = new TileSet();
}
void Map::Render(sf::RenderWindow* window) {
void Map::RenderGround(sf::RenderWindow* window) {
Layer* layer = this->ground1;
this->Render(window, layer);
}
void Map::RenderAbove(sf::RenderWindow* window) {
Layer* layer = this->above1;
this->Render(window, layer);
}
void Map::Render(sf::RenderWindow* window, Layer *layer) {
// Get render section
sf::Vector2f renderWidth = sf::Vector2f((window->getView().getCenter().x - window->getSize().x / 2) / this->tilewidth,
(window->getView().getCenter().x + window->getSize().x / 2) / this->tilewidth);
@ -30,7 +40,7 @@ void Map::Render(sf::RenderWindow* window) {
sf::Sprite tile;
for (int y = renderHeight.x; y < renderHeight.y; y++) {
for (int x = renderWidth.x; x < renderWidth.y; x++) {
index = this->ground1->data[y][x];
index = layer->data[y][x];
if(index != 0) {
tile.setTexture(*this->tileSet->tile[index]);
tile.setPosition(sf::Vector2f(x * this->tileSet->tileWidth, y * this->tileSet->tileHeight));

6
src/map.h

@ -53,7 +53,8 @@ class Map
{
public:
Map();
void Render(sf::RenderWindow* window);
void RenderGround(sf::RenderWindow* window);
void RenderAbove(sf::RenderWindow* window);
~Map();
@ -74,6 +75,9 @@ public:
int tilewidth;
// "version":1,
int width;
private:
void Render(sf::RenderWindow* window, Layer *layer);
};
//sf::Sprite* sprite;

3
src/state/maingame.cpp

@ -43,8 +43,9 @@ void MainGame::Update(sf::RenderWindow* window) {
}
void MainGame::Render(sf::RenderWindow* window) {
this->map->Render(window);
this->map->RenderGround(window);
this->entityManager->Render(window);
this->map->RenderAbove(window);
}
void MainGame::Destroy(sf::RenderWindow* window) {

Loading…
Cancel
Save