-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cpp
More file actions
124 lines (99 loc) · 3.26 KB
/
GameManager.cpp
File metadata and controls
124 lines (99 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "GameManager.h"
#include "Messages_defs.h"
#include "Asteroids.h"
#include "SDLAudioManager.h"
#include "Logger.h"
GameManager::GameManager(SDLGame* game) :
Container(game),
gameCtrl_(SDLK_RETURN),
livesViewer_(game->getServiceLocator()->getTextures()->getTexture(Resources::Badges), { 400, 376, 200, 188 })
{
running_ = false;
gameOver_ = true;
score_ = 0;
lives_ = maxLives_;
winner_ = 0;
addC(&gameCtrl_);
addC(&scoreView_);
addC(&gameStatusView_);
addC(&livesViewer_);
addC(&fighterAsteroidCollision_);
addC(&bulletsAsteroidsCollision_);
addC(&fighterHoleCollision_);
addC(&bulletsHoleCollision_);
addC(&asteroidHoleCollision_);
}
GameManager::~GameManager() {}
void GameManager::receive(const void * senderObj, const msg::Message & m)
{
Container::receive(senderObj, m);
switch (m.type_) {
case msg::GAME_START:
setGameOver(false);
setWinner(0);
setLives(maxLives_);
setScore(0);
cout << "Game Start" << endl;
break;
case msg::ROUND_START:
Logger::instance()->log("Round Start");
setRunning(true);
setWinner(0);
this->getGame()->getServiceLocator()->getAudios()->playMusic(Resources::ImperialMarch, -1); //Reproducir backgorund music (ImperialMarch)
break;
case msg::ASTEROID_DESTROYED: {
const msg::AsteroidDestroyed m_ = static_cast<const msg::AsteroidDestroyed&>(m);
int auxScore = getScore();
setScore(auxScore + m_.points_);
break;
}
case msg::NO_MORE_ASTEROIDS:
setRunning(false);
setGameOver(true);
setWinner(1);
//Stop music
this->getGame()->getServiceLocator()->getAudios()->haltMusic(); //para la musica de fondo
this->getGame()->send(this, msg::Message(msg::ROUND_OVER, getId(), msg::Broadcast));
Logger::instance()->log("Round Over");
this->getGame()->send(this, msg::Message(msg::GAME_OVER, getId(), msg::Broadcast));
break;
case msg::FIGHTER_ASTEROID_COLLISION: {
this->getGame()->getServiceLocator()->getAudios()->playChannel(Resources::Explosion, 0); //Sonido Explosion
setRunning(false);
int myHp = getLives();
myHp--;
setLives(myHp);
this->getGame()->send(this, msg::Message(msg::ROUND_OVER, getId(), msg::Broadcast));
Logger::instance()->log("Round Over");
this->getGame()->getServiceLocator()->getAudios()->haltMusic(); //Para la musica de fondo
if (getLives() == 0) {
setGameOver(true);
setWinner(2);
this->getGame()->send(this, msg::Message(msg::GAME_OVER, getId(), msg::Broadcast));
//sonido abucheo al perder
this->getGame()->getServiceLocator()->getAudios()->playMusic(Resources::Boooo, 1);
}
break;
}
case msg::FIGHTER_HOLE_COLLISION: {
this->getGame()->getServiceLocator()->getAudios()->playChannel(Resources::Explosion, 0); //Sonido Explosion
setRunning(false);
int myHp = getLives();
myHp--;
setLives(myHp);
this->getGame()->send(this, msg::Message(msg::ROUND_OVER, getId(), msg::Broadcast));
Logger::instance()->log("Round Over");
this->getGame()->getServiceLocator()->getAudios()->haltMusic(); //Para la musica de fondo
if (getLives() == 0) {
setGameOver(true);
setWinner(2);
this->getGame()->send(this, msg::Message(msg::GAME_OVER, getId(), msg::Broadcast));
//sonido abucheo al perder
this->getGame()->getServiceLocator()->getAudios()->playMusic(Resources::Boooo, 1);
}
break;
}
default:
break;
}
}