-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCarrier.cpp
More file actions
92 lines (77 loc) · 1.57 KB
/
Carrier.cpp
File metadata and controls
92 lines (77 loc) · 1.57 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
#include <cstdlib>
#include <math.h>
#include "Carrier.h"
#include "MissileHolder.h"
Carrier::Carrier()
{
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;
}
size = 5;
}
Carrier::Carrier(double xin, double yin)
{
x = xin;
y = yin;
size = 5;
}
Carrier::~Carrier()
{
}
const double CARRIER_SPEED = 1.5;
const int FRAMES_PER_Missile = 90;
void Carrier::update()
{
numFramesSinceMissile++;
if (numFramesSinceMissile > FRAMES_PER_Missile)
{
numFramesSinceMissile = 0;
GenericObject* player = ThePlayer;
double y_to_player= (player->y) - y;
double x_to_player = (player->x) - x;
double angle_to_player = atan2(y_to_player, x_to_player);
((MissileHolder*)(holderArray[MISSILE]))->AddMissile(x, y, angle_to_player * 180 / PI);
}
double randomAngle = ((double)rand() / RAND_MAX)*180-90;
if (x > width)
{
angle = 180 + randomAngle;
}
else if (x < 0)
{
angle = 0 + randomAngle;
}
else if (y > height)
{
angle = 270 + randomAngle;
}
else if (y < 0)
{
angle = 90 + randomAngle;
}
y += CARRIER_SPEED * Dsin(angle);
x += CARRIER_SPEED * Dcos(angle);
possibleCollideWithFollower();
possibleCollideWithPlayer();
}
void Carrier::collideWithPlayer()
{
}
void Carrier::collideWithFollower()
{}