Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var player1 = {x: 10, y: 200};
- var player2 = {x: totalWidth-20, y: 200};
- var ball = {x: totalWidth/2-5,
- y: totalHeight/2-5,
- xSpeed: 3,
- ySpeed: 3};
- function update(){
- fill = "black";
- rectangle(player1.x, player1.y, 10, 80, "white");
- rectangle(player2.x, player2.y, 10, 80, "white");
- rectangle(ball.x, ball.y, 10, 10, "white");
- if (ball.y < totalHeight-10){ ball.ySpeed = -ball.ySpeed; }
- if (ball.y < 0) { ball.ySpeed = -ball.ySpeed; }
- if (ball.x < totalWidth-30 &&
- ball.y > player2.y &&
- ball.y < player2.y+80)
- {
- ball.xSpeed = -ball.xSpeed;
- }
- else if (ball.x > totalWidth-30)
- {
- ball.x = totalWidth/2-5;
- }
- if (ball.x < 20 &&
- ball.y > player1.y &&
- ball.y < player1.y +80)
- {
- ball.xSpeed = -ball.xSpeed;
- }
- else if (ball.x <20)
- {
- ball.x = totalWidth/2-5;
- }
- if (keyboard.w) {player1.y -= 5;}
- if (keyboard.s) {player1.y += 5;}
- if (keyboard.up) {player2.y -= 5;}
- if (keyboard.down) {player2.y += 5;}
- ball.x += ball.xSpeed;
- ball.y += ball.ySpeed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement