-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobstacle.h
102 lines (89 loc) · 1.97 KB
/
obstacle.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//Includes header file
#include "header.h"
//Obsacle object class
#define REMOVE 0
#define ADD 1
class Obstacle {
public:
/*
* Obstacle constructor
*/
Obstacle() {}
/*
* Draws obstacle
*/
void drawObstacle() {
LCD.DrawCircle(x,y, SIZE);
LCD.DrawLine(0, 200, 319, 200);
}
/*
* Moves obstacle
*/
void moveObstacle() {
x -= speed;
if (x < 0) {
resetPosition();
}
accel();
}
/*
* Resets obstacle position
*/
void resetPosition() {
x = 300;
maxSpeed = rand() % 5 + 2;
//Randomize y position
switch (rand() % 3) {
case 0:
y = 190;
break;
case 1:
y = 180;
break;
case 2:
y = 160;
break;
}
}
/*
* Resets obstacle speed
*/
void resetSpeed() {
speed = 1;
}
/*
* Accelerates object to max speed
*/
void accel() {
if (speed < maxSpeed) {
speed += 1;
} else if (speed > maxSpeed) {
speed -= 1;
}
}
/*
* Returns x position of obstacle
*
* @return x: x position of obstacle
*/
int getX() {
return x;
}
/*
* Returns y position of obstacle
*
* @return y: y position of obstacle
*/
int getY() {
return y;
}
private:
//Obstacle size
const int SIZE = 9;
//Obstacle position
int x = 300;
int y = 190;
//Obstacle speed
int speed = 2;
int maxSpeed = 2;
};