[Added] Enemy player detection and shooting, [Moved] Lots of entity code to cpp files to avoid circular dependencies
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
#ifndef PBULLET_H
|
||||
#define PBULLET_H
|
||||
|
||||
#include "services/CollectableService.h"
|
||||
#include "services/AssetService.h"
|
||||
#include "services/EnemyService.h"
|
||||
#include "entities/Bullet.h"
|
||||
#include <iostream>
|
||||
|
||||
class PBullet : public Bullet
|
||||
{
|
||||
@@ -17,36 +14,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void objCollision() override
|
||||
{
|
||||
/** Check for collisions with creates */
|
||||
for (auto &crate : CollectableService::getInstance().getCrates())
|
||||
{
|
||||
if(this->position.x + this->size > crate.getObject().getPosition().x && this->position.x-this->size < crate.getObject().getPosition().x + crate.getObject().getSize().x &&
|
||||
this->position.y + this->size > crate.getObject().getPosition().y && this->position.y-this->size < crate.getObject().getPosition().y + crate.getObject().getSize().y) {
|
||||
crate.setHit(true);
|
||||
AssetService::getInstance().playSound(ESound::CRATE_BREAK);
|
||||
// AssetService::getInstance().playSound(ESound::JELLY_FREED);
|
||||
this->hasCollided = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &enemy : EnemyService::getInstance().getEnemies())
|
||||
{
|
||||
/** If the enemy is already falling of the map, dont allow bullets to hit it anymore */
|
||||
if(enemy.getHealth() == 0)
|
||||
continue;
|
||||
|
||||
if(this->position.x + this->size > enemy.getObject().getPosition().x && this->position.x-this->size < enemy.getObject().getPosition().x + enemy.getObject().getSize().x &&
|
||||
this->position.y + this->size > enemy.getObject().getPosition().y && this->position.y-this->size < enemy.getObject().getPosition().y + enemy.getObject().getSize().y) {
|
||||
enemy.takeDamage();
|
||||
if(enemy.getHealth() == 0) {
|
||||
AssetService::getInstance().playSound(ESound::ENEMY_DEFEATED);
|
||||
}
|
||||
this->hasCollided = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
void objCollision() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user