-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_game.pde
114 lines (93 loc) · 3 KB
/
main_game.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* main_game.pde
*
* Class that represents the main game
*
* Created on: January 12, 2020
* Author: Sean LaPlante
*/
class MainGame {
/*
* This is where the main game logic exists
*/
public Hud hud;
public Action action;
public GameScreen screen;
public Ball launchPointBall;
public Line launchLine;
public World world;
public ArrayList<Ball> balls;
private ArrayList<Ball> deleteBalls;
MainGame() {
balls = new ArrayList<Ball>();
deleteBalls = new ArrayList<Ball>();
action = null;
hud = new Hud();
screen = new GameScreen(0, width, hud.topLine, hud.bottomLine); // left, right, top, bottom of play area
launchPointBall = new Ball(screen.launchPoint); // Pass in the PVector so that if the screen launchPoint is updated, so is this.
world = new World();
}
void deleteBall(Ball ball) {
/*
* Handle deleting a ball
*/
deleteBalls.add(ball);
}
void display() {
/*
* Called on each iteration of the draw loop
*/
hud.display();
action = getAction(action);
action.display();
// Delete any balls that should be deleted
for (Ball ball : deleteBalls) {
balls.remove(ball);
}
deleteBalls.clear();
// Display the balls
for (Ball ball : balls) {
ball.display();
}
// Display the world items (blocks and collectibles)
world.display();
// Display the current launch point and number of balls
launchPointBall.display();
displayNumBalls();
}
void handleInput(InputType input) {
/*
* Called on each input event to handle input
*/
if (input == InputType.TOUCH_START && hud.isTouchInHud()) {
hud.handleInput(input);
return;
}
if (action != null) {
action.handleInput(input);
return;
}
}
private void displayNumBalls() {
/*
* Display the number of balls above the launch point ball
*/
int num = 0;
if (action.action == GameAction.EXECUTING_SHOT && action.state == GameActionState.ACTION_ACTIVE) {
ExecuteShot execShotAction = (ExecuteShot)action;
num = hud.numBalls - execShotAction.launchCount;
} else {
num = hud.numBalls;
}
if (num <= 0) {
return;
}
String message = "x" + str(num);
pushMatrix();
fill(255);
textSize(SMALL_TEXT_SIZE);
textAlign(CENTER);
text(message, launchPointBall.location.x, (launchPointBall.location.y - (BALL_RADIUS * 2)));
popMatrix();
}
}