bg = loadImage("strand.jpg");
bl = loadImage("ball.png");
sp = loadImage("spieler2.png");
createCanvas(windowWidth, windowHeight);
pos = createVector(width * 0.33, height * 0.9);
pos2 = createVector(width * 0.66, height * 0.9);
posB = createVector(width * 0.33, height / 2);
image(bg, 0, 0, width, height);
line(width / 2, height, width / 2, height / 2);
text(punkte + " : " + punkte2, width / 2, height * 0.12);
let bounce = (links && pos.x - rad + vx1 < 3);
if (links && pos.x - rad + vx1 > 0 && !bounce) {
if (vx1 > -vxmax) vx1 -= vxmax/15;
} else if (links && bounce) {
if (vx1 < vxmax) vx1 += vxmax/15;
if ((!bounce && !links && !rechts)|| pos.x + rad + vx1 > width / 2) vx1 = 0;
if (spring && pos.y + rad + vy > height - 10) vy = -height/70;
if (pos.y + rad + vy < height) {
image(sp,pos.x, pos.y, rad * 2, rad*2);
let bounce2 = (rechts2 && pos2.x + rad + vx2 > width - 4);
if (comp && schwier == 1)vxmax = width/206;
if (comp && schwier == 2)vxmax = width/186;
if (comp && schwier == 3)vxmax = width/166;
if (rechts2 && pos2.x + rad + vx2 < width && !bounce2) {
if (vx2 < vxmax) vx2 += vxmax/15;
} else if (rechts2 && bounce2) {
if (links2 && !bounce2) {
if (vx2 > -vxmax) vx2 -= vxmax/15;
if ((!bounce2 && !links2 && !rechts2)|| pos2.x - rad + vx2 < width / 2 + 5) vx2 = 0;
if (spring2 && pos2.y + rad + vy2 > height - 10) vy2 = -height/70;
if (pos2.y + rad + vy2 < height) {
image(sp,pos2.x, pos2.y, rad * 2, rad*2);
if (posB.y + rad / 2 + vyB < height) {
let col = collideCircleCircle(posB.x, posB.y + vyB, rad, pos.x, pos.y + vy, rad * 2);
let col2 = collideCircleCircle(posB.x, posB.y + vyB, rad, pos2.x, pos2.y + vy2, rad * 2);
if (vy == 0) vyB = -height/100;
vxB = betrag(pos.x, posB.x) / 5.5;
if (vyB > 0)vyB = -height/125
if (vy2 == 0) vyB = -height/100;
if (betrag(vyB) < 2) vyB = -height/100;
vxB = -betrag(pos2.x, posB.x) / 5.5;
if (vyB > 0)vyB = -height/125;
if (posB.x - rad + vxB < 1 || posB.x + rad + vxB > width - 1 || collideLineCircle(width / 2, height, width / 2, height / 1.95, posB.x + vxB, posB.y + vyB, rad)) {
if (collideLineCircle(width / 2, height/1.92, width / 2, height / 2, posB.x + vxB, posB.y + vyB, rad) && vyB > 0) vyB *= -1;
image(bl,posB.x, posB.y, rad, rad);
if (posB.y + rad >= height) {
if (posB.x < width / 2) punkte2 += 1;
if (posB.x > width / 2) punkte += 1;
pos = createVector(width * 0.33, height * 0.9);
pos2 = createVector(width * 0.66, height * 0.9);
if (posB.x < width / 2)posB = createVector(width * 0.33, height / 2);
if (posB.x > width / 2)posB = createVector(width * 0.66, height / 2);
if (posB.x > pos2.x-rad/1.5 && pos2.x +rad+vx2 < width-2) {
if (posB.x < pos2.x-rad/1.5) {
if (pos2.y - posB.y < height/4 && posB.x > width/2) {
text("Volleyball", width/2, height/4);
rect(width/2, height/2.5, width/10, height/20);
rect(width/2, height/1.8, width/10, height/20);
text("1 Player", width/2, height/2.5+height/70);
text("2 Players", width/2, height/1.8+height/70);
text("Difficulty:" + " " +schwier + " +/-", width/1.5, height/2.5+height/70);
if (mouseIsPressed && mouseY > height/2.5-height/20/2 && mouseY < height/2.5+height/20/2 && mouseX > width/2-width/10/2 && mouseX < width/2+width/10/2) {
if (mouseIsPressed && mouseY > height/1.8-height/20/2 && mouseY < height/1.8+height/20/2 && mouseX > width/2-width/10/2 && mouseX < width/2+width/10/2) {
if (key == "a") links = true;
if (key == "d") rechts = true;
if (keyCode == LEFT_ARROW) links2 = true;
if (keyCode == RIGHT_ARROW) rechts2 = true;
if (key == "l") spring2 = true;
if (key == " ") spring = true;
if (!start && schwier < 3 && key == "+") schwier += 1;
if (!start && schwier > 1 && key == "-") schwier -= 1;
if (key == "a") links = false;
if (key == "d") rechts = false;
if (key == " ") spring = false;
if (keyCode == LEFT_ARROW) links2 = false;
if (keyCode == RIGHT_ARROW) rechts2 = false;
if (key == "l") spring2 = false;
function betrag(x, y=0) {