From ed55551853448ef2e245c6b71f370dfe70b12094 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 23 Sep 2014 15:46:21 +0200 Subject: Some work to allow more dynamic tile sizes --- src/view/MapView.cpp | 18 +++++++++--------- src/view/MapView.hpp | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/view/MapView.cpp b/src/view/MapView.cpp index 8a0bdbf..3eb3248 100644 --- a/src/view/MapView.cpp +++ b/src/view/MapView.cpp @@ -50,12 +50,12 @@ MapView::MapView(const std::shared_ptr &window0, amask = 0xff000000; #endif - SDL_Surface *surface = SDL_CreateRGBSurface(0, 16*tiles.size(), 16, 32, rmask, gmask, bmask, amask); + SDL_Surface *surface = SDL_CreateRGBSurface(0, getTileSize()*tiles.size(), getTileSize(), 32, rmask, gmask, bmask, amask); SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); for (size_t i = 0; i < tiles.size(); i++) { SDL_Rect rect = { - .x = int(16*i), + .x = int(getTileSize()*i), .y = 0, .w = 0, .h = 0, @@ -85,7 +85,7 @@ void MapView::render(float centerX, float centerY) { std::pair viewport = window->getViewport(); float pixels = std::max(viewport.first/16.0f, viewport.second/12.0f); - int tilePixels = 16 * std::ceil(pixels / 16); + int tilePixels = getTileSize() * std::ceil(pixels / getTileSize()); float tilesW = viewport.first / tilePixels; float tilesH = viewport.second / tilePixels; @@ -102,10 +102,10 @@ void MapView::render(float centerX, float centerY) { continue; SDL_Rect src = { - .x = int(16*(tile-1)), + .x = int(getTileSize()*(tile-1)), .y = 0, - .w = 16, - .h = 16, + .w = getTileSize(), + .h = getTileSize(), }; SDL_Rect dst = { @@ -124,10 +124,10 @@ void MapView::render(float centerX, float centerY) { Model::Direction dir = entity->getDirection(); SDL_Rect src = { - .x = 16*dir, + .x = getTileSize()*dir, .y = 0, - .w = 16, - .h = 16, + .w = getTileSize(), + .h = getTileSize(), }; SDL_Rect dst = { diff --git a/src/view/MapView.hpp b/src/view/MapView.hpp index e5f0e50..373c714 100644 --- a/src/view/MapView.hpp +++ b/src/view/MapView.hpp @@ -44,6 +44,10 @@ private: SDL_Texture *tileTexture; std::map entityTextures; + int getTileSize() { + return 16; + } + public: MapView(const std::shared_ptr &window0, const std::shared_ptr &map0, -- cgit v1.2.3