Some work to allow more dynamic tile sizes
This commit is contained in:
parent
d41e2dae45
commit
ed55551853
2 changed files with 13 additions and 9 deletions
|
@ -50,12 +50,12 @@ MapView::MapView(const std::shared_ptr<Window> &window0,
|
||||||
amask = 0xff000000;
|
amask = 0xff000000;
|
||||||
#endif
|
#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);
|
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
||||||
|
|
||||||
for (size_t i = 0; i < tiles.size(); i++) {
|
for (size_t i = 0; i < tiles.size(); i++) {
|
||||||
SDL_Rect rect = {
|
SDL_Rect rect = {
|
||||||
.x = int(16*i),
|
.x = int(getTileSize()*i),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.w = 0,
|
.w = 0,
|
||||||
.h = 0,
|
.h = 0,
|
||||||
|
@ -85,7 +85,7 @@ void MapView::render(float centerX, float centerY) {
|
||||||
std::pair<int, int> viewport = window->getViewport();
|
std::pair<int, int> viewport = window->getViewport();
|
||||||
|
|
||||||
float pixels = std::max(viewport.first/16.0f, viewport.second/12.0f);
|
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 tilesW = viewport.first / tilePixels;
|
||||||
float tilesH = viewport.second / tilePixels;
|
float tilesH = viewport.second / tilePixels;
|
||||||
|
@ -102,10 +102,10 @@ void MapView::render(float centerX, float centerY) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SDL_Rect src = {
|
SDL_Rect src = {
|
||||||
.x = int(16*(tile-1)),
|
.x = int(getTileSize()*(tile-1)),
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.w = 16,
|
.w = getTileSize(),
|
||||||
.h = 16,
|
.h = getTileSize(),
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_Rect dst = {
|
SDL_Rect dst = {
|
||||||
|
@ -124,10 +124,10 @@ void MapView::render(float centerX, float centerY) {
|
||||||
Model::Direction dir = entity->getDirection();
|
Model::Direction dir = entity->getDirection();
|
||||||
|
|
||||||
SDL_Rect src = {
|
SDL_Rect src = {
|
||||||
.x = 16*dir,
|
.x = getTileSize()*dir,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.w = 16,
|
.w = getTileSize(),
|
||||||
.h = 16,
|
.h = getTileSize(),
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_Rect dst = {
|
SDL_Rect dst = {
|
||||||
|
|
|
@ -44,6 +44,10 @@ private:
|
||||||
SDL_Texture *tileTexture;
|
SDL_Texture *tileTexture;
|
||||||
std::map<std::string, SDL_Texture *> entityTextures;
|
std::map<std::string, SDL_Texture *> entityTextures;
|
||||||
|
|
||||||
|
int getTileSize() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapView(const std::shared_ptr<Window> &window0,
|
MapView(const std::shared_ptr<Window> &window0,
|
||||||
const std::shared_ptr<const Model::Map> &map0,
|
const std::shared_ptr<const Model::Map> &map0,
|
||||||
|
|
Reference in a new issue