# Need help with processing ball game

**URL:** <https://discourse.processing.org/t/need-help-with-processing-ball-game/20561>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 6, 2020, 9:20pm UTC](https://discourse.processing.org/t/need-help-with-processing-ball-game/20561 "2020-05-06T21:20:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kchabs](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@kchabs](https://discourse.processing.org/u/kchabs)\
**Post date:** [May 6, 2020, 9:20pm UTC](https://discourse.processing.org/t/need-help-with-processing-ball-game/20561/1 "2020-05-06T21:20:48Z")

</div>

Create a program that displays a window, 300 by 400, randomly placing a red ball  
(circle) of diameter 20 randomly somewhere in that space. When any key is pressed,  
the ball will bounce back and forth horizontally on the screen (moving in increments  
of 5), never disappearing or leaving a trail. Another key press will freeze the ball in  
place, another will resume the horizontal movement, and so on. (Meaning any key  
“toggles” movement on and off.)

-The ball moves (and bounces) vertically as well as horizontally. Ensure it is always  
completely visible (not half off the screen if you stop it).  
-If the mouse is moved to the middle of the circle while it is frozen, this also starts  
the circle moving (instead of a key press). Note that pressing a key should still toggle  
movement on/off (not have no effect).

-The ball slows down somewhat with every bounce off a wall (so no longer always  
uses increments of 5 after hitting), but it never completely stops.  
-If the mouse is used to start the circle movement (ie- user did not hit a key), the  
circle turns green, and resumes maximum movement (by 5s). Hitting a key will both  
turn the ball back to red, and toggle movement on/off as above.

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [May 7, 2020, 7:59am UTC](https://discourse.processing.org/t/need-help-with-processing-ball-game/20561/2 "2020-05-07T07:59:03Z")

</div>

Hello and welcome to the forum.

What kind of help you need? Do you have code that you have problems with? Or is there a part you find difficult and we could help you with?

Processing reference [https://processing.org/reference/](https://processing.org/reference/) is a good source to check available functions and how they work. Examples in references give an idea how they can be used and even give a bit of code you can use in your own programs.

One of the benefits of processing is that you can build your programs in small steps. Ball game is described so that you can follow it and add features one by one.
