forked from bdring/TWANG
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Enemy.h
55 lines (50 loc) · 1.02 KB
/
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
#include "Arduino.h"
class Enemy
{
public:
void Spawn(int pos, int dir, int speed, int wobble);
void Tick();
void Kill();
bool Alive();
int _pos;
int _wobble;
int playerSide;
private:
int _dir;
int _speed;
int _alive;
int _origin;
};
void Enemy::Spawn(int pos, int dir, int speed, int wobble){
_pos = pos;
_dir = dir; // 0 = left, 1 = right
_wobble = wobble; // 0 = no, >0 = yes, value is width of wobble
_origin = pos;
_speed = speed;
_alive = 1;
}
void Enemy::Tick(){
if(_alive){
if(_wobble > 0){
_pos = _origin + (sin((millis()/3000.0)*_speed)*_wobble);
}else{
if(_dir == 0){
_pos -= _speed;
}else{
_pos += _speed;
}
if(_pos > 1000) {
Kill();
}
if(_pos <= 0) {
Kill();
}
}
}
}
bool Enemy::Alive(){
return _alive;
}
void Enemy::Kill(){
_alive = 0;
}