First, what are we trying to do. That's simple: make a FlappyBird clone.
Ok, so what is FlappyBird? It's a simple game of the infinite level type. In this case, you control a bird: pressing a button makes it flap its wings which increases its height. Gravity is also acting on the bird, causing it to fall over time. To complicate things, an unending series of random obstacles enter from the left side of the screen, which must be avoided by flying over, under, or through holes in them. If the bird hits an obstacle, it's "game over".
A simple game: one input (press any button or shake), one character to move up and down, and a series of obstacles that enter from the right and move across the screen and leave on the left.
Some complications can be thrown in: the obstacles are random in size and structure, and the speed at which they move can increase over time.
Let's write this as an object-oriented system. So, the first question is: "What are the things?"
Let's start by having a
Game class that implements the rules of play, initial state, win conditions (or in this case, loose conditions).
Next we have a class to implement the player character: the
Bird class. That's the player character in the game. It's what the player has (some) control over.
Finally we need a class to implement the obstacles, which is the
Post class, because they look sort of like posts.
Game object is the central thing, it has a single
Bird instance and zero or more
Post objects that are on the screen.
Game has a run function that loops until the gamer is over, i.e. until the bird collides with a post.
Each time though the run function's loop, it will look at input and make adjustments to the bird's altitude based on gravity and user activity. Occasionally the scene will be advanced, moving posts to the right. It's at this point that a collision between the bird and a post is checked for and dealt with. Even more infrequently, a new post will be added to the right side of the screen.
When the system starts, it presents the user with a choice of using the accelerometer (shake) to flap, or pressing buttons. Choice is shown by filling the left half of the Trellis with yellow, and the right half with blue.
Pressing a yellow button selects the accelerometer while blue selects using buttons.
The game then starts. The bird (yellow pixel) will gradually fall under the effects of the game's gravity. Flapping (by shaking or pressing any button) will cause the bird to move up. Over time green posts will entry from the right and move across the display, disappearing off the left side. The player's job is to maneuver the bird to avoid hitting the posts. As the game progresses, the speed of the posts increases. Initially posts extend from the bottom of the screen. In time they can extend from the top as well. Eventually there will be posts that extend from both top and bottom and the player has to guide the bird between the two pieces of the post.