0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-13 14:53:41 +00:00

incorporate requests into code

This commit is contained in:
ineslelin 2024-12-17 22:48:49 +01:00
parent a49753e39a
commit 7e088594ae
2 changed files with 9 additions and 8 deletions

View File

@ -27,8 +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(int width, int height); Vector2D calculateSpawnPosition(Vector2D size, Vector2D spawnArea);
template <typename T> T calculateType(int amount); 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);

View File

@ -74,17 +74,18 @@ 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(int width, int height) Vector2D AssetManager::calculateSpawnPosition(Vector2D size, Vector2D spawnArea)
{ {
Vector2D spawnPos = Vector2D(-1, -1); Vector2D spawnPos = Vector2D(-1, -1);
for(int i = 0; i <= SPAWN_ATTEMPTS; i++) for(int i = 0; i <= SPAWN_ATTEMPTS; i++)
{ {
SDL_Rect spawnRect = { SDL_Rect spawnRect = {
rand() % (SCREEN_SIZE_WIDTH - width), rand() % (int)(spawnArea.x - size.x),
rand() % (SCREEN_SIZE_HEIGHT - height), rand() % (int)(spawnArea.y - size.y),
width, size.x,
height size.y
}; };
std::vector<ColliderComponent*> colliders = this->man->getGame()->collisionHandler->getColliders({Entity::GroupLabel::MAPTILES}); std::vector<ColliderComponent*> colliders = this->man->getGame()->collisionHandler->getColliders({Entity::GroupLabel::MAPTILES});
@ -103,7 +104,7 @@ Vector2D AssetManager::calculateSpawnPosition(int width, int height)
} }
template <typename T> template <typename T>
T AssetManager::calculateType(int amount) T AssetManager::calculateRandomType(int amount)
{ {
T type = T(rand() % amount); T type = T(rand() % amount);
return type; return type;