-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpong_complete.pde
More file actions
40 lines (31 loc) · 1.1 KB
/
pong_complete.pde
File metadata and controls
40 lines (31 loc) · 1.1 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
int p1, p2 = 0; //Keep track of the player's scores
Ball ball; //Initialize the ball
Paddle player, ai; //Initialize player paddle and computer paddle
void setup() {
size(1000, 650);//Size of the screen
background(0);//Initialize a black background color
textSize(60); //Set the text size to 60
ball = new Ball();//Create a ball
//Instantiate player
PVector playerPos = new PVector(20, 20);
PVector paddleSize = new PVector(20, 150);
player = new Paddle(playerPos, paddleSize);
//Instantiate computer
PVector aiPos = new PVector(960, 20);
ai = new Paddle(aiPos, paddleSize);
}
void draw() {
background(0); //Clear the screen every loop
//TODO Move the paddles
player.pos.y = mouseY-player.dim.y/2; //Fill in the position of the paddle relative to the mouse
ai.pos.y = ball.pos.y-ai.dim.y/2; //Fill in the position of the paddle relative to the ball
//TODO Draw the paddles
player.drawPaddle();
ai.drawPaddle();
//Display the score
fill(0, 0, 255);
text("P1: " + p1, 50, 50, 200, 200);
text("P2: " + p2, 810, 50, 200, 200);
//TODO Draw the ball
ball.drawBall();
}