-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLineTripper.cpp
More file actions
106 lines (95 loc) · 1.7 KB
/
LineTripper.cpp
File metadata and controls
106 lines (95 loc) · 1.7 KB
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
103
104
105
106
#include <cstdlib>
#include <math.h>
#include "LineTripper.h"
LineTripper::LineTripper()
{
switch (rand() % 4)
{
case 0:
y = 0;
x = rand() % width;
break;
case 1:
y = height;
x = rand() % width;
break;
case 2:
y = rand() % height;
x = 0;
break;
case 3:
y = rand() % height;
x = width;
break;
}
aimX = rand() % width;
aimY = rand() % height;
speed = 0;
size = 5;
}
LineTripper::LineTripper(double xin, double yin)
{
x = xin;
y = yin;
aimX = rand() % width;
aimY = rand() % height;
speed = 0;
size = 5;
}
LineTripper::~LineTripper()
{
}
const double LINETRIPPER_SPEED = 10;
void LineTripper::update()
{
//bounce
double randomAngle = ((double)rand() / RAND_MAX) * 180 - 90;
if (x > width)
{
moveAngle = 180 + randomAngle;
}
else if (x < 0)
{
moveAngle = 0 + randomAngle;
}
else if (y > height)
{
moveAngle = 270 + randomAngle;
}
else if (y < 0)
{
moveAngle = 90 + randomAngle;
}
if (speed < 0.4){
if (state == 0){
//0=shooting, 1=targetting
state = 1;
if ((rand() % 2) == 0){
aimX = ThePlayer->x;
aimY = ThePlayer->y;
} else {
aimX = rand() % width;
aimY = rand() % height;
}
}
double delta_y = aimY - y;
double delta_x = aimX - x;
angle = atan2(delta_y, delta_x);
angle = angle * 180 / PI;//convert to degrees
if (speed < 0.2){
moveAngle = angle;
speed = LINETRIPPER_SPEED;
state = 0;
}
}
speed *= .98;
y += speed * Dsin(moveAngle);
x += speed * Dcos(moveAngle);
possibleCollideWithFollower();
possibleCollideWithPlayer();
}
void LineTripper::collideWithPlayer()
{
}
void LineTripper::collideWithFollower()
{}