refactor: add game listener

This commit is contained in:
2021-12-13 19:45:01 +01:00
parent 61166023df
commit 2148c0050c
6 changed files with 46 additions and 16 deletions

View File

@@ -106,7 +106,7 @@ bool World::saveMap(const std::string& fileName) const {
}
void World::tick(std::uint64_t delta) {
if(m_Game->getGameState() != GameState::Game) return;
if (m_Game->getGameState() != GameState::Game) return;
tickMobs(delta);
for (TowerPtr tower : m_Towers) {
@@ -295,7 +295,7 @@ void World::OnExplosion(utils::shape::Circle explosion, float centerDamage, Towe
void World::OnMobCastleDamage(Mob* damager, TeamCastle* enemyCastle, float damage) {
enemyCastle->damage(damage);
if (enemyCastle->getLife() <= 0) {
getWorldNotifier().notifyListeners(&WorldListener::OnGameEnd);
m_Game->notifyListeners(&GameListener::OnGameEnd);
}
}
@@ -306,10 +306,6 @@ void World::OnMobDamage(Mob* target, float damage, Tower* source) {
}
}
void World::OnGameEnd(){
m_Game->setGameState(GameState::EndGame);
}
Team& World::getRedTeam() {
return m_Game->getRedTeam();
}