-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPong_Processing.pde
More file actions
135 lines (106 loc) · 2.79 KB
/
Pong_Processing.pde
File metadata and controls
135 lines (106 loc) · 2.79 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
int bound_h = 10, line_w = 6;
boolean[] keysDown;
boolean menu = true, game_over = false;
Player player1, player2;
Ball ball;
void setup() {
size(1200, 800);
frameRate(60);
keysDown = new boolean[256];
player1 = new Player("RIGHT");
player2 = new Player("LEFT");
ball = new Ball();
}
void keyPressed() {
if (keyCode < 256)
keysDown[keyCode] = true;
}
void keyReleased() {
if (keyCode < 256)
keysDown[keyCode] = false;
}
void draw() {
background(0);
noStroke();
// Moving section:
if(!menu && !game_over) {
if (keysDown[79]) // O
player1.move("UP");
if (keysDown[76]) // L
player1.move("DOWN");
if (keysDown[87]) // W
player2.move("UP");
if (keysDown[83]) // S
player2.move("DOWN");
ball.move();
}
//if(key == 'x' && !menu)
//game_over = true;
// Checking section:
player1.checkBounds();
player2.checkBounds();
ball.checkCollision();
ball.checkScore();
if(player1.score == 11 || player2.score == 11)
game_over = true;
// Drawing section:
fill(255);
rect(0, 0, width, bound_h); // Draw top bound
rect(0, height - bound_h, width, bound_h); // Draw bottom bound
fill(150);
if(!menu && !game_over) {
for (int i = bound_h + 10; i < height - bound_h; i += 60) {
rect(width / 2 - line_w / 2, i, line_w, 40); // Draw dashed center line
}
}
fill(255);
if(!menu)
ball.draw();
player1.draw();
player2.draw();
if(!menu) {
fill(255);
textAlign(CENTER , CENTER);
textSize(40);
text(player1.score, width / 4 * 3, height / 4);
text(player2.score, width / 4, height / 4);
}
if(game_over) {
String left_txt = "WINNER", right_txt = "LOSER";
if(player1.score > player2.score) {
left_txt = "LOSER"; right_txt = "WINNER";
}
fill(255);
textAlign(CENTER, CENTER);
textSize(60);
text(right_txt, width / 4 * 3, height / 2);
text(left_txt, width / 4, height / 2);
textSize(40);
text("Press SPACE to play again", width / 2, height / 2 + 300);
if(keyPressed && key == ' ') {
player1.reset("RIGHT");
player2.reset("LEFT");
ball.reset();
game_over = false;
}
}
if(menu) {
fill(255);
textAlign(CENTER, CENTER);
textSize(40);
text("↑ O", width / 6 * 5, height / 4);
text("↓ L", width / 6 * 5, height / 4 * 3);
text("W ↑", width / 6, height / 4);
text("S ↓", width / 6, height / 4 * 3);
textSize(150);
text("PONG", width / 2, height / 2 - 35);
textSize(40);
text("Press SPACE to start", width / 2, height / 2 + 65);
textSize(20);
text("v1.0.0", width - 40, 40);
text("Made by Paweł Sampir (2024)", width / 2, height - 40);
if(keyPressed && key == ' ') {
menu = false;
}
}
}