0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 15:53:42 +00:00

Cleanup of legacy code booleans

This commit is contained in:
Benedikt Galbavy 2024-01-30 03:27:11 +01:00
parent 9a01a19385
commit e979b4aa88
6 changed files with 10 additions and 16 deletions

View File

@ -15,7 +15,7 @@ public:
AssetManager(Manager* manager); AssetManager(Manager* manager);
~AssetManager(); ~AssetManager();
void createProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel); void createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel);
//texture management //texture management
void addTexture(std::string id, const char* path); void addTexture(std::string id, const char* path);

View File

@ -17,13 +17,11 @@ public:
void init() override; void init() override;
void resetHearts(); void refreshHearts();
void createHeartComponents(int x); void createHeartComponents(int x);
private: private:
int health; int health;
Direction side; Direction side;
bool player; //true if player1 / false if player2
}; };

View File

@ -10,14 +10,12 @@ class ProjectileComponent : public Component
//can maybe be split in separate .cpp file //can maybe be split in separate .cpp file
public: public:
ProjectileComponent(int range, int speed, Vector2D direction, bool source) : range(range), speed(speed), direction(direction), source(source) {} ProjectileComponent(int range, int speed, Vector2D direction) : range(range), speed(speed), direction(direction) {}
~ProjectileComponent() {} ~ProjectileComponent() {}
void init() override; void init() override;
void update() override; void update() override;
bool getSource() { return this->source; }
private: private:
TransformComponent* transformComponent; TransformComponent* transformComponent;
@ -25,7 +23,5 @@ private:
int speed = 0; int speed = 0;
int distance = 0; int distance = 0;
const bool source; //true if from player1 / false if from player2
Vector2D direction; Vector2D direction;
}; };

View File

@ -26,12 +26,12 @@ Mix_Chunk* AssetManager::getSound(std::string id) {
return soundEffects.at(id); return soundEffects.at(id);
} }
void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, bool source, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel) { void AssetManager::createProjectile(Vector2D pos, Vector2D velocity, int scale, int range, int speed, const char* texturePath, TeamLabel teamLabel) {
auto& projectile(man->addEntity()); auto& projectile(man->addEntity());
projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale); //32x32 is standard size for objects
projectile.addComponent<SpriteComponent>(texturePath); projectile.addComponent<SpriteComponent>(texturePath);
projectile.addComponent<ProjectileComponent>(range, speed, velocity, source); projectile.addComponent<ProjectileComponent>(range, speed, velocity);
projectile.addComponent<ColliderComponent>("projectile", 0.6f); projectile.addComponent<ColliderComponent>("projectile", 0.6f);
projectile.addGroup((size_t)GroupLabel::PROJECTILE); projectile.addGroup((size_t)GroupLabel::PROJECTILE);
projectile.setTeam(teamLabel); projectile.setTeam(teamLabel);

View File

@ -8,16 +8,16 @@
void HealthComponent::init() void HealthComponent::init()
{ {
resetHearts(); refreshHearts();
} }
void HealthComponent::modifyHealth(int health) void HealthComponent::modifyHealth(int health)
{ {
this->health += health; this->health += health;
this->resetHearts(); this->refreshHearts();
} }
void HealthComponent::resetHearts() void HealthComponent::refreshHearts()
{ {
// clear hearts if exist // clear hearts if exist
for (auto& heart : this->entity->getManager().getGroup((size_t) GroupLabel::HEARTS)) { for (auto& heart : this->entity->getManager().getGroup((size_t) GroupLabel::HEARTS)) {

View File

@ -63,12 +63,12 @@ void KeyboardController::update()
if (fireVelocity.x > 0) { if (fireVelocity.x > 0) {
sprite->setDirection(Direction::RIGHT); sprite->setDirection(Direction::RIGHT);
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
false, 1, 180, 1, "assets/egg.png", this->entity->getTeam()); 1, 180, 1, "assets/egg.png", this->entity->getTeam());
} }
else { else {
sprite->setDirection(Direction::LEFT); sprite->setDirection(Direction::LEFT);
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
true, 1, 180, 1, "assets/egg.png", this->entity->getTeam()); 1, 180, 1, "assets/egg.png", this->entity->getTeam());
} }
lastFireTime = currentTicks; lastFireTime = currentTicks;