-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.cpp
executable file
·66 lines (56 loc) · 1.07 KB
/
enemy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "enemy.h"
Enemy::Enemy(Sprite::Set& sprites) : Entity(sprites)
{
setTransformOriginPoint(pixmap().width()/2, pixmap().height()/2);
rotation(rand() % 360);
speed(0, 100);
}
/**
* Handles the movement and rotation
*
* @param elapsed_time Time elapsed from the last move call.
*/
void Enemy::move(const float elapsed_time)
{
rotate(int(100*elapsed_time));
Entity::move(elapsed_time);
}
/**
* Kills the enemy.
*
* @param callback Function that will be called after the die animation ends.
*/
void Enemy::die(std::function<void ()> callback)
{
animation("die", 0, callback);
playSound("qrc:/assets/sounds/explosion.wav");
Entity::die();
}
/**
* Rotates the enemy.
*
* @param angle
*/
void Enemy::rotate(const unsigned int angle)
{
rotation(rotation_ + angle);
}
/**
* "rotation" accessor.
*
* @return rotation_
*/
unsigned int Enemy::rotation() const
{
return rotation_;
}
/**
* "rotation" mutator.
*
* @param value
*/
void Enemy::rotation(const unsigned int value)
{
rotation_ = value;
setRotation(rotation_);
}