-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChaotic.pde
executable file
·71 lines (64 loc) · 1.89 KB
/
Chaotic.pde
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
/*
This class is a dynamic enemy type that will zig-zag down the screen.
They will be fast and difficult to catch, but if one is caught the player
will increase their max speed relative to the speed of the enemy.
These enemies cannot damage the player but will only show up rarely later in the game
*/
PImage chaotic;
class Chaotic
{
float size;
float xVel;
float yVel;
float xPos;
float yPos;
boolean isDead; // true if caught by the player
boolean hasAttacked; // true if hits player
PImage skin;
Chaotic(float _size, float _xVel, float _yVel, float _xPos)
{
size = _size;
xVel = _xVel;
yVel = _yVel;
xPos = _xPos;
yPos = 100.0; // starts above the top of the window
isDead = true; // all enemies start off "dead" and are made "alive" when they are ready to be deployed
hasAttacked = false;
skin = chaotic;
}
void display()
{
// This will display the image for the chaotic enemey at its specified size and location
image(skin, xPos, yPos, size*1.2, size);
}
void move()
{
// This will advance the location of the chaotic enemy based on its velocities, IF it is not dead
// This method will also change the xVelocity of the enemy based on its location so it moves in a zig-zag path
float r = random(0,1);
if (yPos > height + 50)
{
isDead = true;
}
else if (xPos < size/2 + 20 || xPos > width - (size/2) - 20)
{
xVel *= -1;
}
else if (r < 0.01) // randomly switches direction
{
xVel *= -1;
}
yPos += yVel;
xPos += xVel;
}
void respawn(float _xVel, float _yVel, float _xPos)
{
// This will reset the enemy object at the top of the window, giving it a new x-position and velocity, essentially recycling the enemy and "reviving" it
isDead = false;
xVel = _xVel;
yVel = _yVel;
yPos = -100;
xPos = _xPos;
hasAttacked = false;
}
}