0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 23:33:41 +00:00

Compare commits

..

No commits in common. "d7f11e7ebdb7174304d1a72c11b5daaf7571150c" and "ba8dca8abc5cc77942b3071c838d1e509db106b2" have entirely different histories.

3 changed files with 61 additions and 79 deletions

View File

@ -1,6 +1,5 @@
#pragma once
#include <tmxlite/Types.hpp>
#include <map>
#include <string>
@ -11,6 +10,8 @@ public:
Map() = default;
~Map() = default;
// code comment below is a test for doxygen - do not remove
/*!
*
* \brief
@ -20,17 +21,8 @@ public:
* \return Boolean for success
*
*/
[[deprecated("ID based text files are not supported anymore, use .txm maps instead")]]
static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */);
[[deprecated]]
static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict);
/*!
* \brief Loads a .tmx map
* \param path Path to the `.tmx` map file
*
*/
static void loadMapTmx(const char* path);
private:
static void addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, const char* texturePath);
};

View File

@ -2,7 +2,6 @@
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <type_traits>
@ -73,6 +72,8 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, co
void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity
{
printf("X: %d, Y: %d", x, y);
auto& tile(game->manager.addEntity());
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict);
@ -125,15 +126,11 @@ void Map::loadMapTmx(const char* path)
const auto tileCountX = texX / mapTileSize.x;
const auto tileCountY = texY / mapTileSize.y;
for (auto idx = 0ul; idx < mapSize.x * mapSize.y; idx++) {
if (!(idx < tiles.size() && tiles[idx].ID >= tileSets.at(i).getFirstGID()
&& tiles[idx].ID < (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount()))) {
continue;
}
const auto x = idx % mapSize.x;
const auto y = idx / mapSize.x;
for (auto y = 0u; y < mapSize.y; ++y) {
for (auto x = 0u; x < mapSize.x; ++x) {
const auto idx = y * mapSize.x + x;
if (idx < tiles.size() && tiles[idx].ID >= tileSets.at(i).getFirstGID()
&& tiles[idx].ID < (tileSets.at(i).getFirstGID() + tileSets.at(i).getTileCount())) {
auto idIndex = (tiles[idx].ID - tileSets.at(i).getFirstGID());
@ -150,21 +147,21 @@ void Map::loadMapTmx(const char* path)
const float tilePosX = static_cast<float>(x) * mapTileSize.x;
const float tilePosY = (static_cast<float>(y) * mapTileSize.y);
Map::addTile(tilePosX, tilePosY, mapTileSize, u, v, zIndex, texturePaths.at(i).c_str());
auto& tile(VEGO_Game().manager.addEntity());
tile.addComponent<TransformComponent>(tilePosX, tilePosY, mapTileSize.x, mapTileSize.y, 1);
tile.addComponent<SpriteComponent>(texturePaths.at(i).c_str(), v, u, zIndex); // why does uv need to be reversed?
}
}
}
}
continue;
}
if (layer->getType() == tmx::Layer::Type::Object) {
// spawn objects
continue;
}
}
}
}
void Map::addTile(float x, float y, const tmx::Vector2u& mapTileSize, int u, int v, int zIndex, const char* texturePath)
{
auto& tile(VEGO_Game().manager.addEntity());
tile.addComponent<TransformComponent>(x, y, mapTileSize.x, mapTileSize.y, 1);
tile.addComponent<SpriteComponent>(texturePath, v, u, zIndex); // why does uv need to be reversed?
}

View File

@ -64,13 +64,6 @@ void SpriteComponent::init()
void SpriteComponent::update()
{
// This code is not compatible for animated tiles
if (animated) {
srcRect.x = srcRect.w * static_cast<int>((SDL_GetTicks() / speed) % frames);
srcRect.y = animationIndex * transform->height;
}
this->destRect.x = this->transform->position.x;
this->destRect.y = this->transform->position.y;
this->destRect.w = transform->width * transform->scale;