mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-13 14:53:41 +00:00
Implemented requested changes
This commit is contained in:
parent
d7f11e7ebd
commit
23c750c409
19
src/Map.cpp
19
src/Map.cpp
@ -24,6 +24,7 @@
|
|||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "TileComponent.h"
|
#include "TileComponent.h"
|
||||||
#include "VEGO.h"
|
#include "VEGO.h"
|
||||||
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */)
|
void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */)
|
||||||
{
|
{
|
||||||
@ -111,7 +112,7 @@ void Map::loadMapTmx(const char* path)
|
|||||||
return property.getName() == "zIndex";
|
return property.getName() == "zIndex";
|
||||||
});
|
});
|
||||||
|
|
||||||
if (zIndexIterator != properties.end() && std::is_same<decltype(zIndexIterator->getType()), int>::value) {
|
if (zIndexIterator != properties.end() && std::is_nothrow_convertible<decltype(zIndexIterator->getType()), int>::value) {
|
||||||
zIndex = zIndexIterator->getIntValue();
|
zIndex = zIndexIterator->getIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,16 +120,16 @@ void Map::loadMapTmx(const char* path)
|
|||||||
|
|
||||||
for (auto i = 0u; i < tileSets.size(); i++) {
|
for (auto i = 0u; i < tileSets.size(); i++) {
|
||||||
auto tilesetTexture = VEGO_Game().textureManager->loadTexture(texturePaths.at(i).c_str());
|
auto tilesetTexture = VEGO_Game().textureManager->loadTexture(texturePaths.at(i).c_str());
|
||||||
int texX, texY;
|
tmx::Vector2i textureSize;
|
||||||
SDL_QueryTexture(tilesetTexture, nullptr, nullptr, &texX, &texY);
|
SDL_QueryTexture(tilesetTexture, nullptr, nullptr, &(textureSize.x), &(textureSize.y));
|
||||||
|
|
||||||
const auto tileCountX = texX / mapTileSize.x;
|
const auto tileCountX = textureSize.x / mapTileSize.x;
|
||||||
const auto tileCountY = texY / mapTileSize.y;
|
const auto tileCountY = textureSize.y / mapTileSize.y;
|
||||||
|
|
||||||
for (auto idx = 0ul; idx < mapSize.x * mapSize.y; idx++) {
|
for (auto idx = 0ul; idx < mapSize.x * mapSize.y; idx++) {
|
||||||
|
|
||||||
if (!(idx < tiles.size() && tiles[idx].ID >= tileSets.at(i).getFirstGID()
|
if (idx >= tiles.size() || tiles[idx].ID < tileSets.at(i).getFirstGID()
|
||||||
&& tiles[idx].ID < (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount()))) {
|
|| tiles[idx].ID >= (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +144,8 @@ void Map::loadMapTmx(const char* path)
|
|||||||
v *= mapTileSize.y;
|
v *= mapTileSize.y;
|
||||||
|
|
||||||
//normalise the UV
|
//normalise the UV
|
||||||
u /= texX;
|
u /= textureSize.x;
|
||||||
v /= texY;
|
v /= textureSize.y;
|
||||||
|
|
||||||
//vert pos
|
//vert pos
|
||||||
const float tilePosX = static_cast<float>(x) * mapTileSize.x;
|
const float tilePosX = static_cast<float>(x) * mapTileSize.x;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user