-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.h
52 lines (47 loc) · 1.06 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
#include "Arduino.h"
class Enemy
{
public:
void Spawn(int position, int direction, int speed, int patrolWidth);
void Tick();
void Kill();
bool Alive();
int _position;
int _patrolWidth;
int playerSide;
private:
int _direction;
int _speed;
int _alive;
int _origin;
};
void Enemy::Spawn(int position, int direction, int speed, int patrolWidth){
_position = position;
_direction = direction;
_patrolWidth = patrolWidth;
_origin = position;
_speed = speed;
_alive = 1;
}
void Enemy::Tick(){
if(_alive){
if(_patrolWidth > 0)
_position = _origin + (sin((millis()/3000.0)*_speed)*_patrolWidth);
else{
if(_direction == 0)
_position -= _speed;
else
_position += _speed;
if(_position > 1000)
Kill();
if(_position <= 0)
Kill();
}
}
}
bool Enemy::Alive(){
return _alive;
}
void Enemy::Kill(){
_alive = 0;
}