-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShoot.pde
More file actions
82 lines (71 loc) · 1.64 KB
/
Shoot.pde
File metadata and controls
82 lines (71 loc) · 1.64 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
class Shoot {
private PVector location;
private PVector velocity;
private float velocityMag;
private int endMillis;
private int drawScale;
private boolean endByTime;
private boolean isFinished;
Shoot(PVector _location, PVector _direction, boolean _endByTime) {
velocityMag = 10;
location = _location.get();
endByTime = _endByTime;
velocity = _direction.get().normalize().mult(velocityMag);
if (endByTime) {
endMillis = millis() + int(1000.0 * 0.8);
}
drawScale = 2;
soundManager.playShootSound();
}
public boolean isFinished() {
return isFinished;
}
public PVector getLocation() {
return location;
}
public void update() {
updateLogic();
updateRender();
}
public void updateLogic() {
checkFinished();
if (!isFinished) {
move();
}
}
private void checkFinished() {
if (endByTime) {
isFinished = millis() > endMillis;
} else {
isFinished = location.x > width || location.x < 0 || location.y > height || location.y < 0;
}
}
private void updateRender() {
if (!isFinished()) {
render();
}
}
private void move() {
location.add(velocity);
updateEdgePosition();
}
private void updateEdgePosition() {
if (endByTime) {
}
if (location.x > width) {
location.x = 0;
} else if (location.x < 0) {
location.x = width;
}
if (location.y > height) {
location.y = 0;
} else if (location.y < 0) {
location.y = height;
}
}
private void render() {
fill(255);
stroke(255);
ellipse(location.x, location.y, drawScale, drawScale);
}
}