[Added] Enemy player detection and shooting, [Moved] Lots of entity code to cpp files to avoid circular dependencies

This commit is contained in:
Ninjaws
2024-12-17 20:08:35 +01:00
parent e8c78770b5
commit 2400b0500a
21 changed files with 820 additions and 701 deletions
+1 -33
View File
@@ -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