float spieler_x;
float spieler_y;
float ball_x;
float ball_y;
float ball_speed_x;
float ball_speed_y;
int runde;
void setup(){
spieler_x = 20;
spieler_y = 20;
//**Ball starting position**
ball_x = 500;
ball_y = 350;
ball_speed_x = -4;
ball_speed_y = 0;
size(1000, 780);
rectMode(CENTER);
}
void draw(){
background(0);
rect(spieler_x, spieler_y, 25, 160);
rect(ball_x, ball_y, 10, 10);
if(spieler_y < 720) {
if(keyCode == DOWN) {
spieler_y = spieler_y + 5; } }
if(keyCode == UP){
if(spieler_y > 80) {
spieler_y = spieler_y - 5; } }
ball_x = ball_x + ball_speed_x;
ball_y = ball_y + ball_speed_y;
//**When the ball hits the platform**
if(ball_x < 40) {
if(ball_y < (spieler_y + 80) && ball_y > (spieler_y -80)) {
ball_speed_x = (-ball_speed_x) + 1;
ball_speed_y = ball_speed_y - (spieler_y - ball_y) * 0.05;
} else {
ball_x = 500;
ball_y = 350;
ball_speed_x = -4;
ball_speed_y = 0;
runde = 0;
// **These should be the walls**
if(ball_y > 760 || ball_y < 20) {
ball_speed_y = -ball_speed_y;
}
if(ball_x > 980) {
ball_speed_x *= -ball_speed_x;
}
}
}
text("runde: " + runde, 1300, 20); }
So i am trying to make a pong game and this is the code. The the thing is that the walls on the outside aren’t working and i don’t know why.
thx