Flappy Beard [Day 2] – Gameplay basics and adding the splash screen

Today I’ve decided to do the core functionalities of the game and the actual gameplay.

I’ve started with the infinite background scroll which gives the player the effect that the main character is moving, although it’s always drawn at the same X position on the screen. The simplest way to do this is to have a background that is the same width as the screen width. This way we will draw the background maximum 2 times per frame. Every frame we are decreasing the x position of the background by a specific number of pixels, if the background position is exactly 0, we draw the background only once at the position 0; else we draw the background twice in a row: at position x (which is always a negative number) and at position x + width of the backround. It doesn’t matter if we are drawing off screen, Android supports clipping very well. Another popular effect in 2D games is parallax scrolling to achieve scene depth. It can be done by drawing multiple infinite backgrounds which are moving at different speeds.

I’ve done also the basic main character controls. The bird is pulled down every frame by the gravity and it’s speed is increasing. When the player taps the screen, a specific amount of speed is added to birds speed, so the bird is flying upwards. I’ve set also birds maximum speed in both directions to smooth the gameplay a little bit.

The next thing is generating, drawing and animating the tubes. For this part I’ve created a tube class which holds the x position, the y position of the gap and two flags if the player passed the tube. The tubes are generated at a constant distance (which is configurable), with a random gap position (the gap height is also configurable). On every frame I update the x position for moving and the flags if the player passed the tube; flags are crucial later on for performance, since I don’t want to process tubes which are already passed or outside of the screen.

Since the player can already pass the tubes it’s time to implement scoring. For every passed tube, the score is increasing by one. I’ve also finished persisting the high score on the device.

Some basic gameplay stuff is finished and I’ve started with the splash screen. It should show only the logo with some fade in/out effects; very easy and straight forward.

Last but not least, I’ve spent some time drawing the actual font for scoring. The font will contain only numbers for now.

       

* * * * *