-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulletSpawn.cpp
48 lines (44 loc) · 881 Bytes
/
BulletSpawn.cpp
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
#include "BulletSpawn.h"
#include "Event.h"
#include "EventQueue.h"
BulletSpawn::BulletSpawn(const sf::Vector2f &position, Direction direction) :
position_(position),
unitVelocity_(0.0f, 0.0f),
rotation_(0.0f)
{
switch (direction)
{
case Direction::Up:
unitVelocity_.y = -1.0f;
rotation_ = -45.0f;
break;
case Direction::Down:
unitVelocity_.y = 1.0f;
rotation_ = 135.0f;
break;
case Direction::Left:
unitVelocity_.x = -1.0f;
rotation_ = -135.0f;
break;
case Direction::Right:
unitVelocity_.x = 1.0f;
rotation_ = 45.0f;
break;
}
}
void BulletSpawn::spawnBullet(float speed)
{
EventQueue::getInstance().send(
new EventSpawnBullet(
position_,
unitVelocity_ * speed,
rotation_));
}
const sf::Vector2f &BulletSpawn::getPosition() const
{
return position_;
}
float BulletSpawn::getRotation() const
{
return rotation_;
}