mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 05:43:43 +00:00
Merge branch 'BA' into dev
This commit is contained in:
commit
0695c6cacb
@ -12,10 +12,10 @@
|
||||
#include "Entity.h"
|
||||
#include "RenderManager.h"
|
||||
#include "ConfigLoader.h"
|
||||
#include "PickupManager.h"
|
||||
|
||||
typedef std::function<void()> gamefunction;
|
||||
|
||||
class AssetManager;
|
||||
class CollisionHandler;
|
||||
class TextureManager;
|
||||
class SoundManager;
|
||||
@ -41,7 +41,7 @@ public:
|
||||
/* static */ SDL_Renderer* renderer = nullptr;
|
||||
/* static */ SDL_Event event;
|
||||
/* static */ CollisionHandler* collisionHandler;
|
||||
/* static */ AssetManager* assets;
|
||||
/* static */ PickupManager* pickupManager;
|
||||
/* static */ TextureManager* textureManager;
|
||||
/* static */ SoundManager* soundManager;
|
||||
|
||||
|
||||
@ -3,15 +3,15 @@
|
||||
#include <functional>
|
||||
#include "Component.h"
|
||||
|
||||
class PowerupComponent : public Component
|
||||
class PickupComponent : public Component
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Powerup Component object
|
||||
* @param func The function to be called when the powerup is picked up
|
||||
*/
|
||||
PowerupComponent(std::function<void (Entity*)> func);
|
||||
~PowerupComponent() {};
|
||||
PickupComponent(std::function<void (Entity*)> func);
|
||||
~PickupComponent() {};
|
||||
|
||||
void update(uint_fast16_t diffTime) override;
|
||||
|
||||
@ -11,25 +11,16 @@
|
||||
class Vector2D;
|
||||
class Manager;
|
||||
|
||||
enum class PowerupType
|
||||
{
|
||||
HEART,
|
||||
WALKINGSPEED,
|
||||
SHOOTINGSPEED
|
||||
};
|
||||
|
||||
class AssetManager
|
||||
class PickupManager
|
||||
{
|
||||
public:
|
||||
|
||||
AssetManager(Manager* manager);
|
||||
~AssetManager();
|
||||
PickupManager(Manager* manager);
|
||||
~PickupManager();
|
||||
|
||||
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, Textures texture);
|
||||
|
||||
Vector2D calculateSpawnPosition();
|
||||
PowerupType calculateType();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#include "GameInternal.h"
|
||||
|
||||
#include "CollisionHandler.h"
|
||||
#include "AssetManager.h"
|
||||
#include "RenderManager.h"
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include "SDL3/SDL_init.h"
|
||||
@ -39,10 +38,10 @@ SDL_AppResult GameInternal::init()
|
||||
|
||||
json finalConfig = config->getFinalConfig();
|
||||
|
||||
GameInternal::assets = new AssetManager(&manager);
|
||||
GameInternal::pickupManager = new PickupManager(&manager);
|
||||
GameInternal::textureManager = new TextureManager(&manager);
|
||||
GameInternal::soundManager = new SoundManager();
|
||||
GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
|
||||
GameInternal::collisionHandler = new CollisionHandler(manager); //why no pointer?
|
||||
|
||||
int flags = 0;
|
||||
if (finalConfig.at("fullscreen"))
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "PowerupComponent.h"
|
||||
#include "PickupComponent.h"
|
||||
#include "GameInternal.h"
|
||||
#include "CollisionHandler.h"
|
||||
#include "Entity.h"
|
||||
@ -7,12 +7,12 @@
|
||||
#include "Constants.h"
|
||||
#include <cstdint>
|
||||
|
||||
PowerupComponent::PowerupComponent(std::function<void (Entity*)> func)
|
||||
PickupComponent::PickupComponent(std::function<void (Entity*)> func)
|
||||
{
|
||||
this->pickupFunc = func;
|
||||
}
|
||||
|
||||
void PowerupComponent::update(uint_fast16_t diffTime)
|
||||
void PickupComponent::update(uint_fast16_t diffTime)
|
||||
{
|
||||
Entity* player;
|
||||
if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection<Entity*>(
|
||||
@ -1,4 +1,4 @@
|
||||
#include "AssetManager.h"
|
||||
#include "PickupManager.h"
|
||||
|
||||
#include "TextureManager.h"
|
||||
#include "SoundManager.h"
|
||||
@ -12,17 +12,17 @@
|
||||
#include "Constants.h"
|
||||
#include "Entity.h"
|
||||
#include "Vector2D.h"
|
||||
#include "PowerupComponent.h"
|
||||
#include "PickupComponent.h"
|
||||
#include <iostream>
|
||||
#include <VEGO.h>
|
||||
|
||||
#include "Textures.h"
|
||||
|
||||
AssetManager::AssetManager(Manager* manager) : man(manager) {}
|
||||
PickupManager::PickupManager(Manager* manager) : man(manager) {}
|
||||
|
||||
AssetManager::~AssetManager() {}
|
||||
PickupManager::~PickupManager() {}
|
||||
|
||||
void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, Textures texture) {
|
||||
void PickupManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, Textures texture) {
|
||||
|
||||
auto& powerups(man->addEntity());
|
||||
powerups.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, 1); //32x32 is standard size for objects
|
||||
@ -35,11 +35,11 @@ void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pic
|
||||
}
|
||||
|
||||
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
|
||||
powerups.addComponent<PowerupComponent>(pickupFunc);
|
||||
powerups.addComponent<PickupComponent>(pickupFunc);
|
||||
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
||||
}
|
||||
|
||||
Vector2D AssetManager::calculateSpawnPosition()
|
||||
Vector2D PickupManager::calculateSpawnPosition()
|
||||
{
|
||||
Vector2D spawnPos = Vector2D(-1, -1);
|
||||
bool conflict = false;
|
||||
@ -62,10 +62,4 @@ Vector2D AssetManager::calculateSpawnPosition()
|
||||
spawnPos = Vector2D(spawnRect.x, spawnRect.y);
|
||||
}
|
||||
return spawnPos;
|
||||
}
|
||||
|
||||
PowerupType AssetManager::calculateType()
|
||||
{
|
||||
PowerupType type = PowerupType(rand() % 3);
|
||||
return type;
|
||||
}
|
||||
@ -6,7 +6,6 @@
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
|
||||
#include "GameInternal.h"
|
||||
#include "AssetManager.h"
|
||||
|
||||
/*
|
||||
Mix_Music* SoundManager::loadMusic(const char* fileName)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user