mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 12:33:43 +00:00
so much happened idk what to write here :c
This commit is contained in:
parent
65e00c2314
commit
6de979d794
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -14,3 +14,6 @@
|
||||
path = extern/SDL_ttf
|
||||
url = https://github.com/libsdl-org/SDL_ttf.git
|
||||
branch = release-2.22.x
|
||||
[submodule "extern/magic_enum"]
|
||||
path = extern/magic_enum
|
||||
url = https://github.com/Neargye/magic_enum.git
|
||||
|
||||
@ -21,6 +21,7 @@ add_subdirectory(extern/SDL EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(extern/SDL_image EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(extern/SDL_mixer 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)
|
||||
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_mixer::SDL2_mixer-static
|
||||
SDL2_ttf::SDL2_ttf-static
|
||||
magic_enum::magic_enum
|
||||
)
|
||||
|
||||
if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||
|
||||
1
docs/doxygen-awesome-css
Submodule
1
docs/doxygen-awesome-css
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit df88fe4fdd97714fadfd3ef17de0b4401f804052
|
||||
1
extern/magic_enum
vendored
Submodule
1
extern/magic_enum
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit a72a0536c716fdef4f029fb43e1fd7e7b3d9ac9b
|
||||
@ -25,7 +25,7 @@ public:
|
||||
~AssetManager();
|
||||
|
||||
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();
|
||||
PowerupType calculateType();
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <TextureEnumBase.h>
|
||||
|
||||
class GameInternal;
|
||||
class Map
|
||||
@ -21,6 +22,6 @@ public:
|
||||
* \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 addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict);
|
||||
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<TexturesEnum, bool>>* textureDict);
|
||||
};
|
||||
|
||||
@ -3,8 +3,10 @@
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
#include "Component.h"
|
||||
#include "TextureEnumBase.h"
|
||||
|
||||
class SpriteComponent;
|
||||
class TransformComponent;
|
||||
@ -17,17 +19,27 @@ public:
|
||||
|
||||
SDL_Rect tileRect;
|
||||
int tileID;
|
||||
const char* path;
|
||||
TexturesEnum texture;
|
||||
|
||||
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;
|
||||
|
||||
void init() override;
|
||||
|
||||
bool hasCollision(){return this->collision;}
|
||||
std::string getName(){return this->tileName;}
|
||||
bool hasCollision() {
|
||||
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:
|
||||
bool collision;
|
||||
std::string tileName;
|
||||
};
|
||||
@ -59,13 +59,13 @@ void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale,
|
||||
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());
|
||||
powerups.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects
|
||||
|
||||
try {
|
||||
powerups.addComponent<SpriteComponent>(texturePath.c_str());
|
||||
powerups.addComponent<SpriteComponent>(texture);
|
||||
}
|
||||
catch (std::runtime_error e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "SDL_error.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;
|
||||
char singleChar = 0;
|
||||
@ -56,11 +56,13 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, co
|
||||
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());
|
||||
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);
|
||||
}
|
||||
@ -9,7 +9,8 @@
|
||||
|
||||
#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.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->tileName = it->second.first;
|
||||
this->path = it->second.first.data();
|
||||
this->texture = it->second.first;
|
||||
}
|
||||
|
||||
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->transform = &entity->getComponent<TransformComponent>();
|
||||
|
||||
this->entity->addComponent<SpriteComponent>(this->path);
|
||||
this->entity->addComponent<SpriteComponent>(this->texture);
|
||||
this->sprite = &entity->getComponent<SpriteComponent>();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user