# Can you help me making this game with codes

**URL:** <https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 24, 2022, 10:41am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849 "2022-11-24T10:41:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![processinglearner](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@processinglearner](https://discourse.processing.org/u/processinglearner)\
**Post date:** [November 24, 2022, 10:41am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849/1 "2022-11-24T10:41:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 24, 2022, 10:58am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849/2 "2022-11-24T10:58:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [November 24, 2022, 11:00am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849/3 "2022-11-24T11:00:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![processinglearner](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@processinglearner](https://discourse.processing.org/u/processinglearner)\
**Post date:** [November 24, 2022, 11:17am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849/4 "2022-11-24T11:17:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 24, 2022, 11:26am UTC](https://discourse.processing.org/t/can-you-help-me-making-this-game-with-codes/39849/5 "2022-11-24T11:26:26Z")

</div>

Hi @processinglearner,

take a look here and compare it to your approach …

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/circle-rect.php)**
>
> An online book about collision detection using Processing.

Cheers  
— mnse
