0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 09:03:42 +00:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Freezarite
0441ad493a
Merge b5cae00daebf33b602c8d7e96301e60f98e1eec1 into a8052b4bbbbaa72b5832bdd4e689bdeb14c41edf 2024-11-30 14:55:50 +01:00
freezarite
b5cae00dae Extra map for MapTiles generated by TMX file now works like intended.
removed textures map from AssetManager as it is no longer used.
Updated SpriteComponent to now check if it is a normal Texture or a MapTileTexture.
Added if condition in TextureManager::LoadMapTileTexture to check if the texture was able to be loaded by SDL
2024-11-30 14:55:40 +01:00
freezarite
136196f6a5 Merge remote-tracking branch 'origin/textureManagerChanges' into textureManagerChanges
# Conflicts:
#	.gitmodules
#	CMakeLists.txt
#	include/AssetManager.h
#	include/Map.h
#	include/TileComponent.h
#	src/AssetManager.cpp
#	src/Map.cpp
#	src/TileComponent.cpp
2024-11-19 19:14:20 +01:00
freezarite
549178fc7c removed doxigen (idk how it got in here) 2024-11-05 18:45:34 +01:00
freezarite
6bedb08d9b changes to make chickengame work with updated textureManager
future changes regarding the removal of the character selection needed
2024-11-05 18:38:53 +01:00
freezarite
6de979d794 so much happened idk what to write here :c 2024-11-05 12:45:26 +01:00
8 changed files with 28 additions and 8 deletions

2
.gitignore vendored
View File

@ -6,6 +6,8 @@ Makefile
install_manifest.txt
.cache/
build/
cmake-build-debug/
.idea/
# Compiled files
*.suo

View File

@ -36,14 +36,12 @@ public:
void addMusic(std::string id, const char* path);
SDL_Texture* getTexture(std::string id);
Mix_Chunk* getSound(std::string id);
Mix_Music* getMusic(std::string id);
private:
Manager* man;
std::map<std::string, SDL_Texture*> textures;
std::map<std::string, Mix_Chunk*> soundEffects;
std::map<std::string, Mix_Music*> music;
};

View File

@ -51,6 +51,7 @@ public:
~SpriteComponent();
void setTexture(Textures texture);
void setMapTileTexture(const char* path);
void init() override;
void update() override;

View File

@ -16,6 +16,9 @@ class TextureManager
for (auto& it : this->texture_cache) {
SDL_DestroyTexture(it.second);
}
for (auto& it : this->mapTile_texture_cache) {
SDL_DestroyTexture(it.second);
}
}
void addSingleTexture(Textures texture, const char* filePath);

View File

@ -31,9 +31,6 @@ void AssetManager::addMusic(std::string id, const char* path)
music.emplace(id, this->man->getGame()->soundManager->loadMusic(path));
}
SDL_Texture* AssetManager::getTexture(std::string id) {
return textures.at(id);
}
Mix_Chunk* AssetManager::getSound(std::string id) {
return soundEffects.at(id);

View File

@ -98,6 +98,8 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he
// loading music
// assets->addMusic("background_music", "assets/sound/background_music.mp3");
this->gameInstance = GameFactory::instance().create(this);
this->gameInstance->init();
}

View File

@ -3,6 +3,7 @@
#include <SDL_timer.h>
#include <cstring>
#include <memory>
#include <magic_enum/magic_enum.hpp>
#include "AnimationHandler.h"
#include "Direction.h"
@ -18,11 +19,13 @@
SpriteComponent::SpriteComponent(Textures texture, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(0), textureYOffset(0)
{
this->textureEnum = texture;
this->path = "";
}
SpriteComponent::SpriteComponent(Textures texture, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset)
{
this->textureEnum = texture;
this->path = "";
}
SpriteComponent::SpriteComponent(const char* path, int xOffset, int yOffset, int zIndex) : RenderObject(zIndex, VEGO_Game().renderManager), textureXOffset(xOffset), textureYOffset(yOffset) {
@ -44,6 +47,8 @@ SpriteComponent::SpriteComponent(
playAnimation(defaultAnimation);
this->textureEnum = texture;
this->path = "";
}
SpriteComponent::~SpriteComponent() {}
@ -55,7 +60,12 @@ void SpriteComponent::setTexture(Textures texture)
void SpriteComponent::init()
{
setTexture(this->textureEnum);
if (this->path == "") {
setTexture(this->textureEnum);
}
else {
setMapTileTexture(this->path);
}
this->transform = &entity->getComponent<TransformComponent>();
@ -97,4 +107,8 @@ void SpriteComponent::playAnimation(std::string type)
void SpriteComponent::setDirection(Direction direction)
{
this->flipped = direction == Direction::RIGHT;
}
}
void SpriteComponent::setMapTileTexture(const char *path) {
this->texture = VEGO_Game().textureManager->loadMapTileTexture(path);
}

View File

@ -46,10 +46,13 @@ SDL_Texture* TextureManager::loadMapTileTexture(const char *path) {
//returns tile if it exists already
if(mapTile_texture_cache.contains(std::string(path)))
return mapTile_texture_cache.at(std::string(path));
return mapTile_texture_cache.find(std::string(path))->second;
auto newTexture = IMG_LoadTexture(VEGO_Game().renderer, path);
if (newTexture == nullptr)
throw std::runtime_error(std::string("Couldn't load texture '") + path + "'");
this->mapTile_texture_cache.emplace(std::string(path), newTexture);
return newTexture;