This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FreezeField.pde
95 lines (86 loc) · 2.3 KB
/
FreezeField.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class FreezeField {
float xPos, yPos;
float radius;
float boxLength;
float collisionDistance;
float turretCollisionThreshold;
float duration, timer;
float textDuration, textTimer;
boolean active;
boolean dropped;
FreezeField(float fR) {
radius = 0;
boxLength = 25;
collisionDistance = (float)Math.sqrt(2*Math.pow(boxLength, 2));
turretCollisionThreshold = 3;
duration = 1.7*fR;
timer = 0;
textDuration = 2*fR;
textTimer = 0;
active = false;
dropped = false;
}
//getters
float getX() { return xPos; }
float getY() { return yPos; }
float getRadius() { return radius; }
float getTurretCollThreshold() { return turretCollisionThreshold; }
boolean isDropped() { return dropped; }
boolean isActive() { return active; }
//checks for if the ship is close enough to this upgrade's icon
void checkForShipCollision(float shipX, float shipY, float shipSize) {
if (dropped && Math.sqrt(Math.pow(shipX-xPos, 2) + Math.pow(shipY-yPos, 2)) < shipSize/2+collisionDistance+5) {
activate();
}
}
//activates this upgrade's effect
void activate() {
active = true;
dropped = false;
timer = duration;
textTimer = textDuration;
}
//spawns the drop box for this upgrade
void drop(float x, float y) {
dropped = true;
xPos = x;
yPos = y;
}
//draws the freezing field effects
void drawFreezeField() {
if (isActive()) {
strokeWeight(5);
stroke(140, 230, 240);
noFill();
ellipse(xPos, yPos, 2*radius, 2*radius);
radius += 4.5;
timer -= 1;
textTimer -= 1;
if (textTimer > 0) { drawText(); }
if (timer <= 0) {
active = false;
timer = 0;
radius = 0;
}
}
}
//draws the box icon for this upgrade
void drawIcon() {
rectMode(CENTER);
noStroke();
fill(130, 150, 150);
rect(xPos, yPos, boxLength, boxLength);
rectMode(CORNER);
fill(140, 230, 240);
textSize(20);
textAlign(CENTER);
text("F", xPos, yPos+boxLength/4);
}
//draws the name of this upgrade
void drawText() {
textSize(50);
textAlign(CENTER);
fill(140, 230, 240);
text("Freezing Field", width/2, height/6);
}
}