summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/MapView.cpp55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/view/MapView.cpp b/src/view/MapView.cpp
index 4938c5d..d511c31 100644
--- a/src/view/MapView.cpp
+++ b/src/view/MapView.cpp
@@ -48,12 +48,11 @@ MapView::MapView(const std::shared_ptr<Window> &window0,
amask = 0xff000000;
#endif
+ SpriteCache *spriteCache = window->getSpriteCache();
+
const std::vector<std::string> &tileset = map->getTileset();
SDL_Surface *surface = SDL_CreateRGBSurface(0, getTileSize()*tileset.size(), getTileSize(), 32, rmask, gmask, bmask, amask);
- SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
-
- SpriteCache *spriteCache = window->getSpriteCache();
for (size_t i = 0; i < tileset.size(); i++) {
SDL_Rect rect = {
@@ -63,7 +62,11 @@ MapView::MapView(const std::shared_ptr<Window> &window0,
.h = 0,
};
- SDL_BlitSurface(spriteCache->get("tile", tileset[i]), nullptr, surface, &rect);
+ SDL_Surface *sprite = spriteCache->get("tile", tileset[i]);
+
+ SDL_SetSurfaceBlendMode(sprite, SDL_BLENDMODE_NONE);
+ SDL_BlitSurface(sprite, nullptr, surface, &rect);
+ SDL_SetSurfaceBlendMode(sprite, SDL_BLENDMODE_BLEND);
}
tiles = SDL_CreateTextureFromSurface(window->getRenderer(), surface);
@@ -98,27 +101,29 @@ void MapView::render(float centerX, float centerY, uint64_t time) {
int baseX = viewport.first/2 - int(centerX * tilePixels) - tilePixels/2, baseY = viewport.second/2 - int(centerY * tilePixels) - tilePixels/2;
- for (int x = minX; x <= maxX; x++) {
- for (int y = minY; y <= maxY; y++) {
- uint32_t tile = map->getTileAt(x, y);
- if (!tile)
- continue;
-
- SDL_Rect src = {
- .x = int(getTileSize()*(tile-1)),
- .y = 0,
- .w = getTileSize(),
- .h = getTileSize(),
- };
-
- SDL_Rect dst = {
- .x = baseX + x*tilePixels,
- .y = baseY + y*tilePixels,
- .w = tilePixels,
- .h = tilePixels,
- };
-
- SDL_RenderCopy(window->getRenderer(), tiles, &src, &dst);
+ for (size_t layer = 0; layer < map->getLayerCount(); layer++) {
+ for (int x = minX; x <= maxX; x++) {
+ for (int y = minY; y <= maxY; y++) {
+ uint32_t tile = map->getTileAt(layer, x, y);
+ if (!tile)
+ continue;
+
+ SDL_Rect src = {
+ .x = int(getTileSize()*(tile-1)),
+ .y = 0,
+ .w = getTileSize(),
+ .h = getTileSize(),
+ };
+
+ SDL_Rect dst = {
+ .x = baseX + x*tilePixels,
+ .y = baseY + y*tilePixels,
+ .w = tilePixels,
+ .h = tilePixels,
+ };
+
+ SDL_RenderCopy(window->getRenderer(), tiles, &src, &dst);
+ }
}
}