Add Map render Ground and Above
Render layer Ground below and Above above Player.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+12
-2
@@ -18,7 +18,17 @@ Map::Map() {
|
|||||||
this->tileSet = new TileSet();
|
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
|
// Get render section
|
||||||
sf::Vector2f renderWidth = sf::Vector2f((window->getView().getCenter().x - window->getSize().x / 2) / this->tilewidth,
|
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);
|
(window->getView().getCenter().x + window->getSize().x / 2) / this->tilewidth);
|
||||||
@@ -30,7 +40,7 @@ void Map::Render(sf::RenderWindow* window) {
|
|||||||
sf::Sprite tile;
|
sf::Sprite tile;
|
||||||
for (int y = renderHeight.x; y < renderHeight.y; y++) {
|
for (int y = renderHeight.x; y < renderHeight.y; y++) {
|
||||||
for (int x = renderWidth.x; x < renderWidth.y; x++) {
|
for (int x = renderWidth.x; x < renderWidth.y; x++) {
|
||||||
index = this->ground1->data[y][x];
|
index = layer->data[y][x];
|
||||||
if(index != 0) {
|
if(index != 0) {
|
||||||
tile.setTexture(*this->tileSet->tile[index]);
|
tile.setTexture(*this->tileSet->tile[index]);
|
||||||
tile.setPosition(sf::Vector2f(x * this->tileSet->tileWidth, y * this->tileSet->tileHeight));
|
tile.setPosition(sf::Vector2f(x * this->tileSet->tileWidth, y * this->tileSet->tileHeight));
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ class Map
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Map();
|
Map();
|
||||||
void Render(sf::RenderWindow* window);
|
void RenderGround(sf::RenderWindow* window);
|
||||||
|
void RenderAbove(sf::RenderWindow* window);
|
||||||
~Map();
|
~Map();
|
||||||
|
|
||||||
|
|
||||||
@@ -74,6 +75,9 @@ public:
|
|||||||
int tilewidth;
|
int tilewidth;
|
||||||
// "version":1,
|
// "version":1,
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Render(sf::RenderWindow* window, Layer *layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
//sf::Sprite* sprite;
|
//sf::Sprite* sprite;
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ void MainGame::Update(sf::RenderWindow* window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainGame::Render(sf::RenderWindow* window) {
|
void MainGame::Render(sf::RenderWindow* window) {
|
||||||
this->map->Render(window);
|
this->map->RenderGround(window);
|
||||||
this->entityManager->Render(window);
|
this->entityManager->Render(window);
|
||||||
|
this->map->RenderAbove(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainGame::Destroy(sf::RenderWindow* window) {
|
void MainGame::Destroy(sf::RenderWindow* window) {
|
||||||
|
|||||||
Reference in New Issue
Block a user