Some work to allow more dynamic tile sizes

This commit is contained in:
Matthias Schiffer 2014-09-23 15:46:21 +02:00
parent d41e2dae45
commit ed55551853
2 changed files with 13 additions and 9 deletions

View file

@ -50,12 +50,12 @@ MapView::MapView(const std::shared_ptr<Window> &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<int, int> 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 = {

View file

@ -44,6 +44,10 @@ private:
SDL_Texture *tileTexture;
std::map<std::string, SDL_Texture *> entityTextures;
int getTileSize() {
return 16;
}
public:
MapView(const std::shared_ptr<Window> &window0,
const std::shared_ptr<const Model::Map> &map0,