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

so much happened idk what to write here :c

This commit is contained in:
freezarite 2024-11-05 12:45:26 +01:00
parent 65e00c2314
commit 6de979d794
10 changed files with 39 additions and 17 deletions

3
.gitmodules vendored
View File

@ -14,3 +14,6 @@
path = extern/SDL_ttf path = extern/SDL_ttf
url = https://github.com/libsdl-org/SDL_ttf.git url = https://github.com/libsdl-org/SDL_ttf.git
branch = release-2.22.x branch = release-2.22.x
[submodule "extern/magic_enum"]
path = extern/magic_enum
url = https://github.com/Neargye/magic_enum.git

View File

@ -21,6 +21,7 @@ add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_mixer EXCLUDE_FROM_ALL)
add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL) add_subdirectory(extern/SDL_ttf EXCLUDE_FROM_ALL)
add_subdirectory(extern/magic_enum EXCLUDE_FROM_ALL)
file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE SOURCES ${ENGINE_SOURCE_DIR}/src/*.cpp)
add_library(${PROJECT_NAME} ${SOURCES}) add_library(${PROJECT_NAME} ${SOURCES})
@ -33,6 +34,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL fu
SDL2_image::SDL2_image-static SDL2_image::SDL2_image-static
SDL2_mixer::SDL2_mixer-static SDL2_mixer::SDL2_mixer-static
SDL2_ttf::SDL2_ttf-static SDL2_ttf::SDL2_ttf-static
magic_enum::magic_enum
) )
if(CMAKE_BUILD_TYPE MATCHES "Debug") if(CMAKE_BUILD_TYPE MATCHES "Debug")

@ -0,0 +1 @@
Subproject commit df88fe4fdd97714fadfd3ef17de0b4401f804052

1
extern/magic_enum vendored Submodule

@ -0,0 +1 @@
Subproject commit a72a0536c716fdef4f029fb43e1fd7e7b3d9ac9b

View File

@ -25,7 +25,7 @@ public:
~AssetManager(); ~AssetManager();
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, TexturesEnum textureEnum, Entity* owner); void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, TexturesEnum textureEnum, Entity* owner);
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath); void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, TexturesEnum texture);
Vector2D calculateSpawnPosition(); Vector2D calculateSpawnPosition();
PowerupType calculateType(); PowerupType calculateType();

View File

@ -2,6 +2,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <TextureEnumBase.h>
class GameInternal; class GameInternal;
class Map class Map
@ -21,6 +22,6 @@ public:
* \return Boolean for success * \return Boolean for success
* *
*/ */
static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */); static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<TexturesEnum, bool>>* textureDict /* backreference */);
static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict); static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<TexturesEnum, bool>>* textureDict);
}; };

View File

@ -3,8 +3,10 @@
#include <SDL.h> #include <SDL.h>
#include <string> #include <string>
#include <map> #include <map>
#include <magic_enum/magic_enum.hpp>
#include "Component.h" #include "Component.h"
#include "TextureEnumBase.h"
class SpriteComponent; class SpriteComponent;
class TransformComponent; class TransformComponent;
@ -17,17 +19,27 @@ public:
SDL_Rect tileRect; SDL_Rect tileRect;
int tileID; int tileID;
const char* path; TexturesEnum texture;
TileComponent() = default; TileComponent() = default;
TileComponent(int x, int y, int w, int h, int id, const std::map<int, std::pair<std::string, bool>>* textureDict); TileComponent(int x, int y, int w, int h, int id, const std::map<int, std::pair<TexturesEnum, bool>>* textureDict);
~TileComponent() = default; ~TileComponent() = default;
void init() override; void init() override;
bool hasCollision(){return this->collision;} bool hasCollision() {
std::string getName(){return this->tileName;} return this->collision;
}
std::string getName() {
#ifdef TEXTURE_ENUM_DEFINED
return std::string(magic_enum::enum_name(this->texture));
#else
return "Undefined Enum";
#endif
}
private: private:
bool collision; bool collision;
std::string tileName;
}; };

View File

@ -59,13 +59,13 @@ void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale,
projectile.addGroup((size_t)Entity::GroupLabel::PROJECTILE); projectile.addGroup((size_t)Entity::GroupLabel::PROJECTILE);
} }
void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath) { void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, TexturesEnum texture) {
auto& powerups(man->addEntity()); auto& powerups(man->addEntity());
powerups.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects powerups.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects
try { try {
powerups.addComponent<SpriteComponent>(texturePath.c_str()); powerups.addComponent<SpriteComponent>(texture);
} }
catch (std::runtime_error e) { catch (std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;

View File

@ -10,7 +10,7 @@
#include "SDL_error.h" #include "SDL_error.h"
#include "TileComponent.h" #include "TileComponent.h"
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<TexturesEnum, bool>>* textureDict /* backreference */)
{ {
std::string tileIDstr; std::string tileIDstr;
char singleChar = 0; char singleChar = 0;
@ -56,11 +56,13 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, co
mapFile.close(); mapFile.close();
} }
void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<TexturesEnum, bool>>* textureDict) // tile entity
{ {
auto& tile(game->manager.addEntity()); auto& tile(game->manager.addEntity());
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict); tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict);
if(tile.getComponent<TileComponent>().hasCollision()) tile.addComponent<ColliderComponent>(tile.getComponent<TileComponent>().getName().data()); if(tile.getComponent<TileComponent>().hasCollision())
tile.addComponent<ColliderComponent>(tile.getComponent<TileComponent>().getName().data());
tile.addGroup((size_t)Entity::GroupLabel::MAPTILES); tile.addGroup((size_t)Entity::GroupLabel::MAPTILES);
} }

View File

@ -9,7 +9,8 @@
#include "TextureEnumBase.h" #include "TextureEnumBase.h"
TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map<int, std::pair<std::string, bool>>* textureDict)
TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map<int, std::pair<TexturesEnum, bool>>* textureDict)
{ {
this->tileRect.x = x; this->tileRect.x = x;
this->tileRect.y = y; this->tileRect.y = y;
@ -24,8 +25,7 @@ TileComponent::TileComponent(int x, int y, int w, int h, int id, const std::map<
} }
this->collision = it->second.second; this->collision = it->second.second;
this->tileName = it->second.first; this->texture = it->second.first;
this->path = it->second.first.data();
} }
void TileComponent::init() void TileComponent::init()
@ -33,7 +33,7 @@ void TileComponent::init()
this->entity->addComponent<TransformComponent>(this->tileRect.x, this->tileRect.y, this->tileRect.w, this->tileRect.h, 1); this->entity->addComponent<TransformComponent>(this->tileRect.x, this->tileRect.y, this->tileRect.w, this->tileRect.h, 1);
this->transform = &entity->getComponent<TransformComponent>(); this->transform = &entity->getComponent<TransformComponent>();
this->entity->addComponent<SpriteComponent>(this->path); this->entity->addComponent<SpriteComponent>(this->texture);
this->sprite = &entity->getComponent<SpriteComponent>(); this->sprite = &entity->getComponent<SpriteComponent>();
} }