mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
fixed some issues stemming from the removal of the window-size constant variables
This commit is contained in:
parent
84cee5e307
commit
abe018f99b
@ -11,6 +11,7 @@
|
|||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "RenderManager.h"
|
#include "RenderManager.h"
|
||||||
|
#include "ConfigLoader.h"
|
||||||
|
|
||||||
typedef std::function<void()> gamefunction;
|
typedef std::function<void()> gamefunction;
|
||||||
|
|
||||||
@ -48,6 +49,8 @@ public:
|
|||||||
RenderManager renderManager;
|
RenderManager renderManager;
|
||||||
Map* map; // game specific, might not be needed for all types of games
|
Map* map; // game specific, might not be needed for all types of games
|
||||||
|
|
||||||
|
ConfigLoader* config;
|
||||||
|
|
||||||
std::vector<Entity*>& tiles;
|
std::vector<Entity*>& tiles;
|
||||||
std::vector<Entity*>& players;
|
std::vector<Entity*>& players;
|
||||||
std::vector<Entity*>& projectiles;
|
std::vector<Entity*>& projectiles;
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "PowerupComponent.h"
|
#include "PowerupComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <VEGO.h>
|
||||||
|
|
||||||
#include "Textures.h"
|
#include "Textures.h"
|
||||||
|
|
||||||
@ -76,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() % (SCREEN_SIZE_WIDTH - spawnRect.w);
|
spawnRect.x = rand() % (VEGO_Game().config->getFinalConfig().at("width").get<int>() - spawnRect.w);
|
||||||
spawnRect.y = rand() % (SCREEN_SIZE_HEIGHT - spawnRect.h);
|
spawnRect.y = rand() % (VEGO_Game().config->getFinalConfig().at("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 }))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <VEGO.h>
|
||||||
|
|
||||||
IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* entityB, Vector2D posModA, Vector2D posModB)
|
IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* entityB, Vector2D posModA, Vector2D posModB)
|
||||||
{
|
{
|
||||||
@ -66,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 > SCREEN_SIZE_WIDTH) {
|
collider->x + posMod.x > VEGO_Game().config->getFinalConfig().at("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 > SCREEN_SIZE_WIDTH)
|
collider->x + collider->w + posMod.x > VEGO_Game().config->getFinalConfig().at("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 > SCREEN_SIZE_HEIGHT)
|
collider->y + posMod.y > VEGO_Game().config->getFinalConfig().at("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 > SCREEN_SIZE_HEIGHT)
|
collider->y + collider->h + posMod.y > VEGO_Game().config->getFinalConfig().at("height"))
|
||||||
intersections.set((size_t) Direction::DOWN);
|
intersections.set((size_t) Direction::DOWN);
|
||||||
|
|
||||||
return intersections;
|
return intersections;
|
||||||
|
|||||||
@ -31,13 +31,13 @@ GameInternal::~GameInternal() = default;
|
|||||||
|
|
||||||
SDL_AppResult GameInternal::init()
|
SDL_AppResult GameInternal::init()
|
||||||
{
|
{
|
||||||
ConfigLoader* loader = new ConfigLoader();
|
config = new ConfigLoader;
|
||||||
|
|
||||||
this->gameInstance = GameFactory::instance().create(this);
|
this->gameInstance = GameFactory::instance().create(this);
|
||||||
loader->setCustomConfig(this->gameInstance->getConfigFilePath());
|
config->setCustomConfig(this->gameInstance->getConfigFilePath());
|
||||||
loader->init();
|
config->init();
|
||||||
|
|
||||||
json config = loader->getFinalConfig();
|
json finalConfig = config->getFinalConfig();
|
||||||
|
|
||||||
GameInternal::assets = new AssetManager(&manager);
|
GameInternal::assets = new AssetManager(&manager);
|
||||||
GameInternal::textureManager = new TextureManager(&manager);
|
GameInternal::textureManager = new TextureManager(&manager);
|
||||||
@ -45,7 +45,7 @@ SDL_AppResult GameInternal::init()
|
|||||||
GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if (config.at("fullscreen"))
|
if (finalConfig.at("fullscreen"))
|
||||||
{
|
{
|
||||||
flags = SDL_WINDOW_FULLSCREEN;
|
flags = SDL_WINDOW_FULLSCREEN;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ SDL_AppResult GameInternal::init()
|
|||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = SDL_CreateWindow(config.at("title").get<std::string>().c_str(), config.at("width"), config.at("height"), flags);
|
window = SDL_CreateWindow(finalConfig.at("title").get<std::string>().c_str(), finalConfig.at("width"), finalConfig.at("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;
|
||||||
@ -72,7 +72,7 @@ SDL_AppResult GameInternal::init()
|
|||||||
|
|
||||||
// bad
|
// bad
|
||||||
SDL_Surface* icon;
|
SDL_Surface* icon;
|
||||||
if((icon = SDL_LoadBMP(config.at("icon").get<std::string>().c_str())))
|
if((icon = SDL_LoadBMP(finalConfig.at("icon").get<std::string>().c_str())))
|
||||||
{
|
{
|
||||||
SDL_SetWindowIcon(window, icon);
|
SDL_SetWindowIcon(window, icon);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user