Can you help me making this game with codes

Simulate two numbers of balls with a certain radius both colliding with the 4 sides of the screen and colliding with the balls themselves. At the moment of collision, the balls must move in the opposite direction. A progressing time in the game and the total score obtained should be displayed on the screen. +10 points will be scored when the balls are hit with a rectangular stick. After 30 seconds, the game will switch to “GAME OVER” mode. After waiting 5 seconds, the game will restart. The game screen will also show the maximum achieved score.

Please help me

Hi @processinglearner,

Is this a homework assignment? If so, you should mark it accordingly…

Can you show how far you got with it and where you have difficulties ?

Cheers
— mnse

1 Like

Welcome to the forum!

This looks like homework to me and we don’t provide full code solutions. Even if it isn’t homework then providing the solution code will not help you learn Processing.

Start off simple and create a single ball that moves then make it bounce off the screen sides or at least try to. Then come back here with your code for further help.

int xPos = 400;
int yPos = 300;

int speedX = 8;
int speedY = 8;

int xPos1 = 0;
int yPos1 = 0;

int speedX1 = 8;
int speedY1 = 8;

int radius = 50;

int score = 0;

boolean mouseClick = false;

void setup()
{
size( 800, 600 );
}

void draw()
{

background( 251 );

int time = frameCount / 60;

fill(255, 0, 0);
textSize(64);
text("Time: " + time, 540, 80);

//strokeWeight( 5 );
//stroke( 0, 0, 255 );//Mavi renk
noStroke();
//noFill();
fill( 255, 0, 0 ); //Kırmızı renk
ellipse( xPos, yPos, radius * 2, radius * 2 );
fill( 0, 255, 0 ); //Yeşil renk
ellipse( xPos1, yPos1, radius * 2, radius * 2 );

xPos += speedX;
yPos += speedY;

xPos1 += speedX1;
yPos1 += speedY1;

if( xPos - radius < 0 )
{
xPos = radius;
speedX *= -1;
}

if( xPos + radius >= width )
{
xPos = width - radius;
speedX *= -1;
}

if( yPos - radius < 0 )
{
yPos = radius;
speedY *= -1;
}

if( yPos + radius >= height )
{
yPos = height - radius;
speedY *= -1;
}

if( xPos1 - radius < 0 )
{
xPos1 = radius;
speedX1 *= -1;
}

if( xPos1 + radius >= width )
{
xPos1 = width - radius;
speedX1 *= -1;
}

if( yPos1 - radius < 0 )
{
yPos1 = radius;
speedY1 *= -1;
}

if( yPos1 + radius >= height )
{
yPos1 = height - radius;
speedY1 *= -1;
}

if( mouseClick == true )
{
if( ( mouseX > xPos - radius && mouseX < xPos + radius
&& mouseY > yPos - radius && mouseY < yPos + radius )
||
( mouseX > xPos1 - radius && mouseX < xPos1 + radius
&& mouseY > yPos1 - radius && mouseY < yPos1 + radius ))
{
score += 10;
}
else
score -= 0;

}

fill(0, 0, 255);
textSize(64);
text("Score " + score, 40, 80);

if( time == 30 )
{
fill(255, 0, 255);
textSize(64);
text(“GAME OVER!!”, 300, 300);
delay( 1000 );

frameCount = 1;
score = 0;

}

rect( mouseX, mouseY, 200, 50 );

if( xPos > mouseX && xPos < mouseX + 200 )
{
if( yPos + radius > mouseY )
{
yPos = mouseY - radius;

  //speedX *= -1;
  speedY *= -1;
  score += 10;
}

}

if( xPos1 > mouseX && xPos1 < mouseX + 200 )
{
if( yPos1 + radius > mouseY )
{
yPos1 = mouseY - radius;

  //speedX *= -1;
  speedY1 *= -1;
  score += 10;
}

}
}

void mousePressed()
{
mouseClick = true;
}

Firstly, thank you for the answer
i did like that, but i can’t collide the balls and the sides of the bar don’t strike correctly

Hi @processinglearner,

take a look here and compare it to your approach …

Cheers
— mnse