Weapon system now searches parents for health component (stops at first health component).
This commit is contained in:
@@ -11,25 +11,23 @@ WeaponSystem::WeaponSystem(World* world, EventBroker* eventBroker, IRenderer* re
|
||||
|
||||
void WeaponSystem::Update(double dt)
|
||||
{
|
||||
for (int i = m_EShootVector.size(); i > 0; i--)
|
||||
{
|
||||
//TODO: check if player has enough ammo and if weapon has a cooldown or not
|
||||
|
||||
for (int i = m_EShootVector.size(); i > 0; i--) {
|
||||
//pick the object
|
||||
PickData pickDataFromShot = m_Renderer->Pick(std::get<1>(m_EShootVector[i - 1]));
|
||||
if (pickDataFromShot.Entity == EntityID_Invalid) {
|
||||
m_EShootVector.erase(m_EShootVector.begin() + i - 1);
|
||||
continue;
|
||||
}
|
||||
//if its a player, do PlayerDamage event
|
||||
const bool hasHealthComponent = m_World->HasComponent(pickDataFromShot.Entity, "Health");
|
||||
if (hasHealthComponent) {
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
//TODO: damage based on weapontype/class?
|
||||
//TODO: multiple shots at the same time? (shotgunner)
|
||||
ePlayerDamage.DamageAmount = 25;
|
||||
ePlayerDamage.PlayerDamagedID = pickDataFromShot.Entity;
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
EntityID entityID = pickDataFromShot.Entity;
|
||||
while (entityID != EntityID_Invalid) {
|
||||
// If has health
|
||||
if (m_World->HasComponent(entityID, "Health")) {
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
//TODO: damage based on weapontype/class?
|
||||
//TODO: multiple shots at the same time? (shotgunner)
|
||||
ePlayerDamage.DamageAmount = 25;
|
||||
ePlayerDamage.PlayerDamagedID = entityID;
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
break;
|
||||
} else {
|
||||
entityID = m_World->GetParent(entityID);
|
||||
}
|
||||
}
|
||||
m_EShootVector.erase(m_EShootVector.begin() + i - 1);
|
||||
}
|
||||
@@ -44,8 +42,10 @@ bool WeaponSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool WeaponSystem::OnShoot(const Events::Shoot& e) {
|
||||
bool WeaponSystem::OnShoot(const Events::Shoot& e)
|
||||
{
|
||||
//screen center, based on current resolution!
|
||||
//TODO: check if player has enough ammo and if weapon has a cooldown or not
|
||||
Rectangle screenResolution = m_Renderer->Resolution();
|
||||
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
|
||||
m_EShootVector.push_back(std::make_pair(e.shooter, centerScreen));
|
||||
|
||||
Reference in New Issue
Block a user