forked from Critters/TWANG
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEnemy.h
57 lines (52 loc) · 847 Bytes
/
Enemy.h
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
#include "Arduino.h"
class Enemy
{
public:
void Spawn(int pos, char dir, int sp, int wobble);
void Tick();
void Kill();
bool Alive();
int _pos;
int _wobble;
char playerSide;
private:
char _dir;
int _sp;
bool _alive;
int _origin;
};
void Enemy::Spawn(int pos, char dir, int sp, int wobble) {
_pos = pos;
_dir = dir; // 0 = left, 1 = right
_wobble = wobble; // 0 = no, >0 = yes, value is width of wobble
_origin = pos;
_sp = sp;
_alive = true;
}
void Enemy::Tick() {
if (_alive) {
if (_wobble > 0) {
_pos = _origin + (sin((millis() / 3000.0)*_sp)*_wobble);
}
else {
if (_dir == 0) {
_pos -= _sp;
}
else {
_pos += _sp;
}
if (_pos > 1000) {
Kill();
}
if (_pos <= 0) {
Kill();
}
}
}
}
bool Enemy::Alive() {
return _alive;
}
void Enemy::Kill() {
_alive = false;
}