# Trying to create a billiard game

**URL:** <https://discourse.processing.org/t/trying-to-create-a-billiard-game/30318>\
**Category:** Coding Questions\
**Created:** [May 26, 2021, 4:31pm UTC](https://discourse.processing.org/t/trying-to-create-a-billiard-game/30318 "2021-05-26T16:31:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 26, 2021, 5:09pm UTC](https://discourse.processing.org/t/trying-to-create-a-billiard-game/30318/4 "2021-05-26T17:09:24Z")

</div>

ok thanks so have you heard of [object oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming)? Basically Java (which Processing is built on) is a language made for that.

You can check the basic tutorial on the Processing website about it :

> **[Objects](https://processing.org/tutorials/objects/)**
>
> The basics of object-oriented programming.

The idea is to represent data in your code as logical objects.

Let’s take the example of a billiard ball : it has a location (x and y coordinated), a velocity (can be represented as a vector), a color… Those are **attributes** , it’s what define a billiard ball.

And you may want to create multiple balls in a billiard game, those are called **objects**. And those objects are variations of the same kind of entity : the `Ball` **class** for example.

You can also make actions on your ball objects : apply a force, display them on the screen, change their color, position them… these are called **methods**

You can check a post I did on this subject (with balls also 😉 ) :

> [@Problems with my mini game](https://discourse.processing.org/t/problems-with-my-mini-game/21949/2):
>
> Hi, Welcome to the community! slight_smile Before trying to solve your problem, you are facing a well known problem where the structure of your code is actually describing [object oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming) : So object oriented programming is a way to structure your code by using objects to model the data that your are manipulating. In this special case, your are creating Balls, and a Ball is described as : a position (x and y coordinates on the screen) a speed (described as a vector, xDir and y…

You will see that your code will be very structured and clear (because for now it’s hard to read) and it will be easier to add features (as the future trajectory or throw on click…)

---

_[View the full topic](https://discourse.processing.org/t/trying-to-create-a-billiard-game/30318)._
