forked from odaki/TWANG
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Enemy.h
57 lines (51 loc) · 1.1 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
56
57
#include "Arduino.h"
#include <stdint.h> // uint8_t type variables
class Enemy
{
public:
void Spawn(int pos, bool dir, uint8_t speed, uint16_t wobble);
void Tick();
void Kill();
bool Alive();
int _pos;
uint16_t _wobble;
uint8_t playerSide;
private:
bool _dir;
uint8_t _speed;
bool _alive;
int _origin;
};
void Enemy::Spawn(int pos, bool dir, uint8_t speed, uint16_t 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;
}