-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines.pde
93 lines (78 loc) · 2.33 KB
/
lines.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
/*
* lines.pde
*
* Class for lines and shot lines
*
* Created on: January 12, 2020
* Author: Sean LaPlante
*/
class Line {
/*
* Handles holding information needed for a line
*/
public PVector startPoint;
public PVector endPoint;
Line(float startX, float startY, float endX, float endY) {
/*
* Create a line from 4 points. The PVector objects are created
* here.
*/
startPoint = new PVector(startX, startY);
endPoint = new PVector(endX, endY);
}
Line(PVector start, PVector end) {
/*
* Creates a line using 2 PVectors as reference.
* If the provided PVector references are changed in
* the calling environment, the line will be changed.
*/
startPoint = start;
endPoint = end;
}
private PVector getHeading() {
/*
* Get the heading
*/
PVector heading = PVector.sub(endPoint, startPoint);
return heading.normalize();
}
boolean isVerticle() {
return startPoint.x == endPoint.x;
}
void display() {
pushMatrix();
stroke(255);
strokeWeight(1);
line(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
popMatrix();
}
}
class ShotLines {
/*
* Manages the shot lines for the game
*/
public Line launchLine;
private int numLines;
ShotLines(int n) {
numLines = n;
}
void display() {
// Set the launch line, used by MainGame
launchLine = new Line(ENGINE.screen.launchPoint.x, ENGINE.screen.launchPoint.y, mouseX, mouseY);
Ball ghostBall = new Ball(ENGINE.launchPointBall.location.copy());
ghostBall.isSimulated = true; // Won't destroy blocks or pickup items
PVector velocity = launchLine.getHeading();
velocity.setMag(SHOT_SPEED);
ghostBall.fire();
ghostBall.setVelocity(velocity);
for (int i = 0; i < 600; i++) {
if (ghostBall.bounceCount >= numLines) {
break;
}
ghostBall.move();
if (i % 4 == 0 && !ghostBall.isDone) {
ghostBall.display();
}
}
}
}