setBackdrop('bg.jpg');
var ball = createSprite("ball.png");
var p1 = createSprite("orange.jpg");
var p2 = createSprite("blue.jpg");
forever(function() {
});
p1.x = 631;
p2.x = 10;
var score1 = 0;
var score2 = 0;
var speed = 10;
a = a-0.01;
sound.play('wert.mp3');
function touchBorder() {
if (p1.y < 0) {
p1.y = 0;
}
if (p2.y < 0) {
p2.y = 0;
}
if (p2.y > 425) {
p2.y = 425;
}
if (p1.y > 425) {
p1.y = 425;
}
if (ball.x < 0) {
speed = 5;
score1 += 1;
ball.x = 320;
ball.y = 240;
ball.direction = Math.random()*-90+-45;
}
if (ball.x > 640) {
speed = 5;
score2 += 1;
ball.x = 320;
ball.y = 240;
ball.direction = Math.random()*90+45;
}
if (ball.y < 0 || ball.y > 480) {
ball.direction = -ball.direction - 180;
}
}
function playContral() {
if (key.down) {
p1.y += 10;
}
if (key.up) {
p1.y -= 10;
}
if (key.w) {
p2.y -= 10;
}
if (key.s) {
p2.y += 10;
}
if(key.r){
ball.x = 320;
ball.y = 240;
ball.direction = Math.random()*-90+-45;
}
if(score1 == 30 ){
print("p1 win", 180, 180, '#fd7e24', 100);
stop();
}
if(score2 == 30 ){
print("p2 win", 180, 180, '#157df9', 100);
stop();
}
}
function touchplayer() {
if (ball.touched(p1) || ball.touched(p2)) {
sound.play('BonusCube.mp3');
ball.direction = -ball.direction + Math.random()*16;
speed = speed +0.5;
}
}
forever(function() {
touchBorder();
playContral();
touchplayer();
ball.stepForward(speed);
print(score2, 30, 20, '#157df9', 40);
print(score1, 580, 20, '#fd7e24', 40);
});
https://koding.school/projects/36ys6vpj