• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 15th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. var player1 = {x: 10, y: 200};
2.   var player2 = {x: totalWidth-20, y: 200};
3.
4.   var ball = {x: totalWidth/2-5,
5.               y: totalHeight/2-5,
6.               xSpeed: 3,
7.               ySpeed: 3};
8.
9.
10.   function update(){
11.
12.     fill = "black";
13.
14.     rectangle(player1.x, player1.y, 10, 80, "white");
15.     rectangle(player2.x, player2.y, 10, 80, "white");
16.
17.     rectangle(ball.x, ball.y, 10, 10, "white");
18.
19.     if (ball.y < totalHeight-10){ ball.ySpeed = -ball.ySpeed; }
20.     if (ball.y < 0)             { ball.ySpeed = -ball.ySpeed; }
21.
22.     if (ball.x < totalWidth-30 &&
23.         ball.y > player2.y &&
24.         ball.y < player2.y+80)
25.     {
26.       ball.xSpeed = -ball.xSpeed;
27.     }
28.
29.
30.       else if (ball.x > totalWidth-30)
31.     {
32.       ball.x = totalWidth/2-5;
33.     }
34.     if (ball.x < 20 &&
35.         ball.y > player1.y &&
36.         ball.y < player1.y +80)
37.     {
38.       ball.xSpeed = -ball.xSpeed;
39.     }
40.     else if (ball.x <20)
41.     {
42.       ball.x = totalWidth/2-5;
43.     }
44.
45.
46.     if (keyboard.w) {player1.y -= 5;}
47.     if (keyboard.s) {player1.y += 5;}
48.
49.     if (keyboard.up) {player2.y -= 5;}
50.     if (keyboard.down) {player2.y += 5;}
51.
52.     ball.x += ball.xSpeed;
53.     ball.y += ball.ySpeed;
54.
55.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top