mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
Compare commits
2 Commits
b1c5e2187d
...
eab7dab429
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eab7dab429 | ||
|
|
91f15671c0 |
@ -24,13 +24,11 @@ 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/tmxlite/tmxlite EXCLUDE_FROM_ALL)
|
add_subdirectory(extern/tmxlite/tmxlite EXCLUDE_FROM_ALL)
|
||||||
include_directories(extern/nlohmann_json/include)
|
add_subdirectory(extern/nlohmann_json 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})
|
||||||
include/ConfigLoader.h
|
|
||||||
src/ConfigLoader.cpp)
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR})
|
||||||
|
|
||||||
@ -39,6 +37,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC # should be private when all SDL fu
|
|||||||
SDL3_image::SDL3_image-static
|
SDL3_image::SDL3_image-static
|
||||||
SDL3_mixer::SDL3_mixer-static
|
SDL3_mixer::SDL3_mixer-static
|
||||||
SDL3_ttf::SDL3_ttf-static
|
SDL3_ttf::SDL3_ttf-static
|
||||||
|
nlohmann_json::nlohmann_json
|
||||||
tmxlite
|
tmxlite
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"fullscreen": false,
|
"fullscreen": false,
|
||||||
"title": "VGG (Very Good Game)",
|
"title": "VGG (Very Good Game)",
|
||||||
"height": 100,
|
"screen_height": 100,
|
||||||
"width": 100,
|
"screen_width": 100,
|
||||||
"icon": "./engine/internalAssets/iconImage.bmp"
|
"icon": "./engine/internalAssets/iconImage.bmp"
|
||||||
}
|
}
|
||||||
@ -17,8 +17,8 @@ public:
|
|||||||
json getFinalConfig();
|
json getFinalConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
json baseConfig;
|
|
||||||
std::optional<json> customConfig;
|
std::optional<std::string> customConfigPath;
|
||||||
json finalConfig;
|
json finalConfig;
|
||||||
|
|
||||||
json loadConfigFromJSON(const std::string& path);
|
json loadConfigFromJSON(const std::string& path);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ public:
|
|||||||
|
|
||||||
virtual void init() = 0;
|
virtual void init() = 0;
|
||||||
virtual void update(uint_fast16_t diffTime) = 0;
|
virtual void update(uint_fast16_t diffTime) = 0;
|
||||||
virtual std::optional<std::string> getConfigFilePath() {return std::nullopt;}
|
virtual std::optional<std::string> setConfigFilePath() {return std::nullopt;}
|
||||||
|
|
||||||
GameInternal* gameInternal; //!< \deprecated
|
GameInternal* gameInternal; //!< \deprecated
|
||||||
};
|
};
|
||||||
|
|||||||
@ -77,8 +77,8 @@ Vector2D AssetManager::calculateSpawnPosition()
|
|||||||
{
|
{
|
||||||
SDL_Rect spawnRect;
|
SDL_Rect spawnRect;
|
||||||
spawnRect.h = spawnRect.w = 32;
|
spawnRect.h = spawnRect.w = 32;
|
||||||
spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("width").get<int>() - spawnRect.w);
|
spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("screen_width").get<int>() - spawnRect.w);
|
||||||
spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("height").get<int>() - spawnRect.h);
|
spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("screen_height").get<int>() - spawnRect.h);
|
||||||
conflict = false;
|
conflict = false;
|
||||||
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -67,20 +67,20 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V
|
|||||||
|
|
||||||
// all 4 directions and both sides to allow checking for fully out of bounds
|
// all 4 directions and both sides to allow checking for fully out of bounds
|
||||||
if (collider->x + posMod.x < 0 ||
|
if (collider->x + posMod.x < 0 ||
|
||||||
collider->x + posMod.x > VEGO_Game().config->getFinalConfig().at("width")) {
|
collider->x + posMod.x > VEGO_Game().config->getFinalConfig().at("screen_width")) {
|
||||||
intersections.set((size_t) Direction::LEFT);
|
intersections.set((size_t) Direction::LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collider->x + collider->w + posMod.x < 0 ||
|
if (collider->x + collider->w + posMod.x < 0 ||
|
||||||
collider->x + collider->w + posMod.x > VEGO_Game().config->getFinalConfig().at("width"))
|
collider->x + collider->w + posMod.x > VEGO_Game().config->getFinalConfig().at("screen_width"))
|
||||||
intersections.set((size_t) Direction::RIGHT);
|
intersections.set((size_t) Direction::RIGHT);
|
||||||
|
|
||||||
if (collider->y + posMod.y < 0 ||
|
if (collider->y + posMod.y < 0 ||
|
||||||
collider->y + posMod.y > VEGO_Game().config->getFinalConfig().at("height"))
|
collider->y + posMod.y > VEGO_Game().config->getFinalConfig().at("screen_height"))
|
||||||
intersections.set((size_t) Direction::UP);
|
intersections.set((size_t) Direction::UP);
|
||||||
|
|
||||||
if (collider->y + collider->h + posMod.y < 0 ||
|
if (collider->y + collider->h + posMod.y < 0 ||
|
||||||
collider->y + collider->h + posMod.y > VEGO_Game().config->getFinalConfig().at("height"))
|
collider->y + collider->h + posMod.y > VEGO_Game().config->getFinalConfig().at("screen_height"))
|
||||||
intersections.set((size_t) Direction::DOWN);
|
intersections.set((size_t) Direction::DOWN);
|
||||||
|
|
||||||
return intersections;
|
return intersections;
|
||||||
|
|||||||
@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
ConfigLoader::ConfigLoader() {
|
ConfigLoader::ConfigLoader() {}
|
||||||
//TODO: look into adaptive paths for better handling as this requires the implemented game
|
|
||||||
// to have ./engine in the root folder
|
|
||||||
baseConfig = loadConfigFromJSON("./engine/config.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigLoader::~ConfigLoader() {}
|
ConfigLoader::~ConfigLoader() {}
|
||||||
|
|
||||||
void ConfigLoader::init() {
|
void ConfigLoader::init() {
|
||||||
if (!customConfig.has_value()) {
|
//TODO: look into adaptive paths for better handling as this requires the implemented game
|
||||||
|
// to have ./engine in the root folder
|
||||||
|
const json baseConfig = loadConfigFromJSON("./engine/config.json");
|
||||||
|
|
||||||
|
if (!customConfigPath.has_value()) {
|
||||||
finalConfig = baseConfig;
|
finalConfig = baseConfig;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finalConfig = mergeConfigs(baseConfig, customConfig.value());
|
|
||||||
|
finalConfig = mergeConfigs(baseConfig, loadConfigFromJSON(customConfigPath.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
||||||
@ -32,9 +33,7 @@ json ConfigLoader::loadConfigFromJSON(const std::string& path) {
|
|||||||
|
|
||||||
|
|
||||||
void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) {
|
void ConfigLoader::setCustomConfig(const std::optional<std::string>& path) {
|
||||||
if (path.has_value()) {
|
customConfigPath = path;
|
||||||
customConfig = loadConfigFromJSON(path.value());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {
|
json ConfigLoader::mergeConfigs(json baseConfig, json customConfig) {
|
||||||
|
|||||||
@ -31,10 +31,10 @@ GameInternal::~GameInternal() = default;
|
|||||||
|
|
||||||
SDL_AppResult GameInternal::init()
|
SDL_AppResult GameInternal::init()
|
||||||
{
|
{
|
||||||
config = new ConfigLoader;
|
config = new ConfigLoader();
|
||||||
|
|
||||||
this->gameInstance = GameFactory::instance().create(this);
|
this->gameInstance = GameFactory::instance().create(this);
|
||||||
config->setCustomConfig(this->gameInstance->getConfigFilePath());
|
config->setCustomConfig(this->gameInstance->setConfigFilePath());
|
||||||
config->init();
|
config->init();
|
||||||
|
|
||||||
json finalConfig = config->getFinalConfig();
|
json finalConfig = config->getFinalConfig();
|
||||||
@ -62,7 +62,9 @@ SDL_AppResult GameInternal::init()
|
|||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = SDL_CreateWindow(finalConfig.at("title").get<std::string>().c_str(), finalConfig.at("width"), finalConfig.at("height"), flags);
|
window = SDL_CreateWindow(finalConfig.at("title").get<std::string>().c_str(),
|
||||||
|
finalConfig.at("screen_width"), finalConfig.at("screen_height"), flags);
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl;
|
std::cout << "ERROR: Window couldnt be created! " << SDL_GetError() << std::endl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user