Game Template

How to Make a Game

The three functions below the draw() function represent three game states. The start screen and game over screen need some styling work, but the majority of our effort will go into the update function, where we'll organize game play. We use the mouseClicked() interrupt function to toggle through the functions. However, we'll later want to change the way gameState changes from 1 to 2.

Now let's make something happen during game play (the update function).

Solution

The following example shows a game where the objective is to dodge the cursor from the Spots. First let's get the Spots moving while gameState == 1.

Now, we just need to add a conditional to each Spot to see if it overlaps with (mouseX, mouseY). We could do that either as a part of move() or as its own function.