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