mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
Revert "Helper functions"
This commit is contained in:
parent
2b411c5f6e
commit
b9aeb9dcc4
@ -27,14 +27,8 @@ public:
|
|||||||
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner);
|
void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, Entity* owner);
|
||||||
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath);
|
void createPowerup(Vector2D pos, std::function<void (Entity*)> pickupFunc, std::string texturePath);
|
||||||
|
|
||||||
/*!
|
Vector2D calculateSpawnPosition();
|
||||||
* \brief Calculates a random spawn position for an object within a given area
|
PowerupType calculateType();
|
||||||
* \param size The size (collision box) of the object
|
|
||||||
* \param spawnArea The area within which a spawn position will be calculated
|
|
||||||
* \returns Spawn Coordinates for the object
|
|
||||||
*/
|
|
||||||
Vector2D calculateSpawnPosition(Vector2D size, Vector2D spawnArea);
|
|
||||||
template <typename T> [[deprecated]] T calculateRandomType(int amount);
|
|
||||||
|
|
||||||
//texture management
|
//texture management
|
||||||
void addTexture(std::string id, const char* path);
|
void addTexture(std::string id, const char* path);
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
#include "PowerupComponent.h"
|
#include "PowerupComponent.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
AssetManager::AssetManager(Manager* manager) : man(manager) {}
|
AssetManager::AssetManager(Manager* manager) : man(manager) {}
|
||||||
|
|
||||||
@ -74,39 +73,33 @@ void AssetManager::createPowerup(Vector2D pos, std::function<void (Entity*)> pic
|
|||||||
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
powerups.addGroup((size_t)Entity::GroupLabel::POWERUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2D AssetManager::calculateSpawnPosition()
|
||||||
Vector2D AssetManager::calculateSpawnPosition(Vector2D size, Vector2D spawnArea)
|
|
||||||
{
|
{
|
||||||
Vector2D spawnPos = Vector2D(-1, -1);
|
Vector2D spawnPos = Vector2D(-1, -1);
|
||||||
|
bool conflict = false;
|
||||||
for(int i = 0; i <= SPAWN_ATTEMPTS; i++)
|
for (int i = 0; i <= SPAWN_ATTEMPTS; i++)
|
||||||
{
|
{
|
||||||
|
SDL_Rect spawnRect;
|
||||||
SDL_Rect spawnRect = {
|
spawnRect.h = spawnRect.w = 32;
|
||||||
rand() % (int)(spawnArea.x - size.x),
|
spawnRect.x = rand() % (SCREEN_SIZE_WIDTH - spawnRect.w);
|
||||||
rand() % (int)(spawnArea.y - size.y),
|
spawnRect.y = rand() % (SCREEN_SIZE_HEIGHT - spawnRect.h);
|
||||||
size.x,
|
conflict = false;
|
||||||
size.y
|
for (auto cc : this->man->getGame()->collisionHandler->getColliders({ Entity::GroupLabel::MAPTILES }))
|
||||||
};
|
{
|
||||||
|
if (SDL_HasIntersection(&spawnRect, &cc->collider) && strcmp(cc->tag, "projectile"))
|
||||||
std::vector<ColliderComponent*> colliders = this->man->getGame()->collisionHandler->getColliders({Entity::GroupLabel::MAPTILES});
|
{
|
||||||
bool conflict = std::any_of(colliders.begin(), colliders.end(),
|
conflict = true;
|
||||||
[&](const auto& cc) {
|
break;
|
||||||
return SDL_HasIntersection(&spawnRect, &cc->collider);} );
|
}
|
||||||
|
}
|
||||||
if(!conflict)
|
if (conflict) continue;
|
||||||
{
|
spawnPos = Vector2D(spawnRect.x, spawnRect.y);
|
||||||
spawnPos = Vector2D(spawnRect.x, spawnRect.y);
|
}
|
||||||
break;
|
return spawnPos;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return spawnPos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
PowerupType AssetManager::calculateType()
|
||||||
T AssetManager::calculateRandomType(int amount)
|
|
||||||
{
|
{
|
||||||
T type = T(rand() % amount);
|
PowerupType type = PowerupType(rand() % 3);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user