-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
51 lines (42 loc) · 846 Bytes
/
sketch.js
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
let leftscore = 0;
let rightscore = 0;
function setup() {
createCanvas(600, 400);
ding = loadSound('ding.mp3');
puck = new Puck();
left = new Paddle(true);
right = new Paddle(false);
}
function draw() {
background(0);
puck.checkPaddleRight(right);
puck.checkPaddleLeft(left);
left.show();
right.show();
left.update();
right.update();
puck.update();
puck.edges();
puck.show();
fill(255);
textSize(32);
text(leftscore, 32, 40);
text(rightscore, width - 64, 40);
}
function keyReleased() {
left.move(0);
right.move(0);
}
function keyPressed() {
console.log(key);
if (key == 'A') {
left.move(-10);
} else if (key == 'Z') {
left.move(10);
}
if (key == 'J') {
right.move(-10);
} else if (key == 'M') {
right.move(10);
}
}