Build a Game
Put everything together and build a simple catching game from scratch, step by step!
Every game needs a player! Let's start with a paddle at the bottom of the screen that follows the mouse. We'll use constrain() to keep it inside the canvas.
Now let's add something to catch! We'll create a ball that falls from the top. When it goes off the bottom, we'll reset it to the top at a random position.
The core of any game: checking if things are touching! We use dist() to measure the distance between the ball and the paddle center. If the ball is close enough, it's a catch!
Let's add consequences! The player starts with 3 lives. Missing a ball loses a life. When lives hit zero, the game is over and a message shows up. Press Space to restart!
Let's make it feel like a real game! We'll increase the speed as the score goes up, add some background stars for atmosphere, and show the level. This is the finished game!
What to try next
- Add multiple falling balls at once using an array
- Add power-ups that make the paddle wider or give extra lives
- Make some balls dangerous (red) — catching them loses a life
- Add a high score that persists between game overs
- Add sound effects — try playSound("coin") when you catch something!