-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullets.cpp
More file actions
77 lines (63 loc) · 1.76 KB
/
Bullets.cpp
File metadata and controls
77 lines (63 loc) · 1.76 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
#include "Bullets.h"
#include "Messages_defs.h"
Bullets::Bullets(SDLGame* game) :
GameObjectPool(game),
bulletImage_(game->getServiceLocator()->getTextures()->getTexture(Resources::WhiteRect)),
tempGun_(SDLK_q)
{
for (auto o : getAllObjects()) {
o->addC(&bulletImage_);
o->addC(&naturalMove_);
o->addC(&deactivate_);
}
addC(&tempGun_);
setId(msg::BulletsShooter);
setActive(false);
}
Bullets::~Bullets() {}
void Bullets::createBullet(Vector2D p, Vector2D d) {
Bullet *b = getUnusedObject();
if (b != nullptr) {
b->setActive(true);
b->setWidth(1);
b->setHeight(5);
b->setPosition(p-Vector2D(width_ / 2, height_));
b->setVelocity(d * 5);
b->setRotation(Vector2D(0, -1).angle(d));
}
}
void Bullets::receive(const void * senderObj, const msg::Message & msg) {
switch (msg.type_) {
case msg::GAME_START:
this->getGame()->send(this, msg::BulletsInfoMsg(getId(), msg::Broadcast, &getAllObjects()));
break;
case msg::ROUND_START:
setActive(true);
break;
case msg::ROUND_OVER:
deactiveAllObjects();
setActive(false);
break;
case msg::BULLET_ASTEROID_COLLISION: {
const msg::BulletAsteroidCollision m_ = static_cast<const msg::BulletAsteroidCollision&>(msg);
m_.bullet_->setActive(false);
break;
}
//Crear bala
case msg::FIGHTER_SHOOT: {
const msg::Shoot m_ = static_cast<const msg::Shoot&>(msg);
createBullet(m_.pos_, m_.dir_);
//Reproducir Sonido (GunShot)
this->getGame()->getServiceLocator()->getAudios()->setChannelVolume(20);
this->getGame()->getServiceLocator()->getAudios()->playChannel(Resources::GunShot, 0);
break;
}
case msg::BULLET_HOLE_COLLISION: {
const msg::BulletHoleCollision m_ = static_cast<const msg::BulletHoleCollision&>(msg);
m_.bullet_->setActive(false);
break;
}
default:
break;
}
}