0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 12:33:43 +00:00
SDL_Minigame/src/ProjectileComponent.cpp
Sara Varga 2e7a1b45cf refactor: removed Components.h file
consisted of includes of all components -> components included when not necessary
TODO: had to add 3 component includes in Entity.h because of template function; move if possible
2024-05-01 13:47:42 +02:00

44 lines
1.2 KiB
C++

#include "ProjectileComponent.h"
#include "CollisionHandler.h"
#include "SoundManager.h"
#include "TransformComponent.h"
#include "Entity.h"
#include "Game.h"
#include "HealthComponent.h"
#include "Vector2D.h"
#include <cassert>
#include <cstdio>
void ProjectileComponent::init()
{
transformComponent = &entity->getComponent<TransformComponent>();
transformComponent->direction = direction;
SoundManager::playSound(this->entity->getManager().getGame(), THROW_EGG);
}
void ProjectileComponent::update()
{
distance += speed;
IntersectionBitSet boundsIntersection = this->entity->getManager().getGame()->collisionHandler->getIntersectionWithBounds(entity);
if ((boundsIntersection | IntersectionBitSet("1100")).all() || (boundsIntersection | IntersectionBitSet("0011")).all()) {
this->entity->destroy();
}
if (distance > range) {
this->entity->destroy();
}
Entity* player;
if ((player = this->entity->getManager().getGame()->collisionHandler->getAnyIntersection<Entity*>(
entity,
Vector2D(0,0),
{Entity::GroupLabel::PLAYERS},
{entity->getTeam()},
true)) != nullptr) {
player->getComponent<HealthComponent>().modifyHealth();
this->entity->destroy();
}
}