mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 21:23:41 +00:00
ref: powerup component now pickup component, assetmanager removed
assetmanager was redundant therefore any traces and usages were removed
This commit is contained in:
parent
e0c35aa690
commit
325f6e8e8d
@ -12,10 +12,10 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "RenderManager.h"
|
#include "RenderManager.h"
|
||||||
#include "ConfigLoader.h"
|
#include "ConfigLoader.h"
|
||||||
|
#include "PickupManager.h"
|
||||||
|
|
||||||
typedef std::function<void()> gamefunction;
|
typedef std::function<void()> gamefunction;
|
||||||
|
|
||||||
class AssetManager;
|
|
||||||
class CollisionHandler;
|
class CollisionHandler;
|
||||||
class TextureManager;
|
class TextureManager;
|
||||||
class SoundManager;
|
class SoundManager;
|
||||||
@ -41,7 +41,7 @@ public:
|
|||||||
/* static */ SDL_Renderer* renderer = nullptr;
|
/* static */ SDL_Renderer* renderer = nullptr;
|
||||||
/* static */ SDL_Event event;
|
/* static */ SDL_Event event;
|
||||||
/* static */ CollisionHandler* collisionHandler;
|
/* static */ CollisionHandler* collisionHandler;
|
||||||
/* static */ AssetManager* assets;
|
/* static */ PickupManager* pickupManager;
|
||||||
/* static */ TextureManager* textureManager;
|
/* static */ TextureManager* textureManager;
|
||||||
/* static */ SoundManager* soundManager;
|
/* static */ SoundManager* soundManager;
|
||||||
|
|
||||||
|
|||||||
@ -3,15 +3,15 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
|
|
||||||
class PowerupComponent : public Component
|
class PickupComponent : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Powerup Component object
|
* @brief Construct a new Powerup Component object
|
||||||
* @param func The function to be called when the powerup is picked up
|
* @param func The function to be called when the powerup is picked up
|
||||||
*/
|
*/
|
||||||
PowerupComponent(std::function<void (Entity*)> func);
|
PickupComponent(std::function<void (Entity*)> func);
|
||||||
~PowerupComponent() {};
|
~PickupComponent() {};
|
||||||
|
|
||||||
void update(uint_fast16_t diffTime) override;
|
void update(uint_fast16_t diffTime) override;
|
||||||
|
|
||||||
@ -11,25 +11,16 @@
|
|||||||
class Vector2D;
|
class Vector2D;
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
enum class PowerupType
|
class PickupManager
|
||||||
{
|
|
||||||
HEART,
|
|
||||||
WALKINGSPEED,
|
|
||||||
SHOOTINGSPEED
|
|
||||||
};
|
|
||||||
|
|
||||||
class AssetManager
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AssetManager(Manager* manager);
|
PickupManager(Manager* manager);
|
||||||
~AssetManager();
|
~PickupManager();
|
||||||
|
|
||||||
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, Textures texture);
|
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, Textures texture);
|
||||||
|
|
||||||
Vector2D calculateSpawnPosition();
|
Vector2D calculateSpawnPosition();
|
||||||
PowerupType calculateType();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -1,7 +1,6 @@
|
|||||||
#include "GameInternal.h"
|
#include "GameInternal.h"
|
||||||
|
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
#include "AssetManager.h"
|
|
||||||
#include "RenderManager.h"
|
#include "RenderManager.h"
|
||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
#include "SDL3/SDL_init.h"
|
#include "SDL3/SDL_init.h"
|
||||||
@ -39,10 +38,10 @@ SDL_AppResult GameInternal::init()
|
|||||||
|
|
||||||
json finalConfig = config->getFinalConfig();
|
json finalConfig = config->getFinalConfig();
|
||||||
|
|
||||||
GameInternal::assets = new AssetManager(&manager);
|
GameInternal::pickupManager = new PickupManager(&manager);
|
||||||
GameInternal::textureManager = new TextureManager(&manager);
|
GameInternal::textureManager = new TextureManager(&manager);
|
||||||
GameInternal::soundManager = new SoundManager();
|
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;
|
int flags = 0;
|
||||||
if (finalConfig.at("fullscreen"))
|
if (finalConfig.at("fullscreen"))
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "PowerupComponent.h"
|
#include "PickupComponent.h"
|
||||||
#include "GameInternal.h"
|
#include "GameInternal.h"
|
||||||
#include "CollisionHandler.h"
|
#include "CollisionHandler.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
@ -7,12 +7,12 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
PowerupComponent::PowerupComponent(std::function<void (Entity*)> func)
|
PickupComponent::PickupComponent(std::function<void (Entity*)> func)
|
||||||
{
|
{
|
||||||
this->pickupFunc = func;
|
this->pickupFunc = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerupComponent::update(uint_fast16_t diffTime)
|
void PickupComponent::update(uint_fast16_t diffTime)
|
||||||
{
|
{
|
||||||
Entity* player;
|
Entity* player;
|
||||||
if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection<Entity*>(
|
if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection<Entity*>(
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "AssetManager.h"
|
#include "PickupManager.h"
|
||||||
|
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "SoundManager.h"
|
#include "SoundManager.h"
|
||||||
@ -12,17 +12,17 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "PowerupComponent.h"
|
#include "PickupComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <VEGO.h>
|
#include <VEGO.h>
|
||||||
|
|
||||||
#include "Textures.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());
|
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
|
||||||
@ -35,11 +35,11 @@ void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pic
|
|||||||
}
|
}
|
||||||
|
|
||||||
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
|
powerups.addComponent<ColliderComponent>("powerup", 0.6f);
|
||||||
powerups.addComponent<PowerupComponent>(pickupFunc);
|
powerups.addComponent<PickupComponent>(pickupFunc);
|
||||||
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D AssetManager::calculateSpawnPosition()
|
Vector2D PickupManager::calculateSpawnPosition()
|
||||||
{
|
{
|
||||||
Vector2D spawnPos = Vector2D(-1, -1);
|
Vector2D spawnPos = Vector2D(-1, -1);
|
||||||
bool conflict = false;
|
bool conflict = false;
|
||||||
@ -63,9 +63,3 @@ Vector2D AssetManager::calculateSpawnPosition()
|
|||||||
}
|
}
|
||||||
return spawnPos;
|
return spawnPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerupType AssetManager::calculateType()
|
|
||||||
{
|
|
||||||
PowerupType type = PowerupType(rand() % 3);
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
@ -6,7 +6,6 @@
|
|||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
|
|
||||||
#include "GameInternal.h"
|
#include "GameInternal.h"
|
||||||
#include "AssetManager.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Mix_Music* SoundManager::loadMusic(const char* fileName)
|
Mix_Music* SoundManager::loadMusic(const char* fileName)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user