Create/Recreate The Flappy Bird Game

Project #1

Create/recreate the Flappy Bird game in Python3.

For this project, use graphics.py. It is a simple graphics library. Click HERE for more information. (download, install, documentation, ...)

The code in the video is incomplete (not shown). The developer must interpret the design from the available code, Expand it, and then code the project in Python3.

The code in the video is not Python. It is VBA.

Note: VBA stands for Visual Basic for Applications.

Steps to Solve the Problem?

  1. Study and understand graphics.py. What capabilities does it have for animation? Do you need a different graphics/animation module?
  2. Read and understand the code in the links below.
  3. Understand the structure of the program/code in the links below.
  4. Translate the structure into Python.
  5. Code and Test.

(Some, Not All) Code From The Video

Code From I Made Flappy Bird in EXCEL?! (YouTube).

'==================================================================== Options Explicit '-------------------------------------------------------------------- ' Main '-------------------------------------------------------------------- 'Bird Variables Private BirdCell As Range Private BirdPreviousCell as Range Private BirdBirdVerticalMovement As Long Private Const Gravity as Byte = 1 Dim FloorRange as Range '--------------------------------------------------------------------- 'Initialize Bird Parameters Public Sub InitializeBird() Set BirdCell = shTest.Range("R5") Set FloorRange = Range("A40:Z40") BirdVerticalMovement = 0 FloorRangeInterior.Color = rgbBlack End Sub '-------------------------------------------------------------------- 'Update Bird Public Sub UpdateBird() ''Bird Gravity BirdVerticalMovement = BirdVerticalMovement + Gravity ''Sets Previous Cell Set BirdPreviousCell = BirdCell ''Set New Target Cell Set BirdCell = BirdCell.Offset(BirdVerticalMovement,0) ''Detect If Bird Is About To Go Through Floor + Move Bird Up If So If BirdCell.Row >= FloorRange.Row Then Set BirdCell = Cells(FloorRange.Row - 1,BirdCell.Column) BirdCellVerticalMovement = -8 End If End Sub '-------------------------------------------------------------------- 'Draw Bird Public Sub DrawBird() BirdPreviousCell.Clear BirdCell.InteriorColor = RGB(255,241,38) End Sub '==================================================================== Option Explicit '-------------------------------------------------------------------- 'Timer Functions '-------------------------------------------------------------------- Private GameTimerID As LongLong Public Sub InitializeTimer() 'Sest Up Timer Dim GameTimerIntervial As Double 'Sets Up Tick GameTimerInterval = 50 Sleep (500) ''Create The Timer Using Given Interval And Applies ''It To Update Method GameTimerID = SetTimer(0,0,GameTimerInterval,AddressOf Update) End Sub '--------------------------------------------------------------------- Public Sub EndTimer() If GameTimerID <> 0 Then KillTimer 0,GameTimerID GameTimerID = 0 End If End Sub '==================================================================== Option Explicit '-------------------------------------------------------------------- 'Declarations '-------------------------------------------------------------------- 'Declaration For Sleep Function Public Declare PtrSafe Sub Sleep Lib "kernel32" ( _ ByVal dwMilliseconds As Long) '-------------------------------------------------------------------- 'Declaration Of Timer Function Public Declare PtrSafe Function SetTimer lib "User32" ( _ ByVal HWnd As LongLong, _ ByVal nIDEvent As LongLong, _ ByVal uElapse As LongLong, _ ByVal lpTimerFunc As LongLong) As LongLong '-------------------------------------------------------------------- 'Declaration For Kill Timer Function Public Declare PtrSafe Function KillTimer Lib "user32" (_ ByVal HWnd as LongPtr, _ ByVal NIDEvent as LongPtr) As Long '==================================================================== 'Test Game ' ------------------------------------------------------------------- Sub TestGameCode() 'set up game Dim BirdCsll as Range Div FloorRange as Range shTest.Select Range("A1").Select Cells.Clear Set BirdCall = Range("H10") Set FloorRange = Range("A40:Z40") BirdCell.Interior.Color = RGB(255,241,38) FloorRange.InteriorColor = rgbBlack 'Gravity + Refresh Bird Do Until BirdCell.Offset(1,0).row >= FloorRange.Row BirdCell.Clear Set BirdCell = BirdCell.Offset(1,0) BirdCell.Interior.Color = RGB(155,241,38) Sleep (50) Loop End Sub

Code From A Different Video

Code from I made Flappy Bird in EXCEL?! (YouTube)

'-------------------------------------------------------------------- 'Test If It is On The floor If TargetRow >= FloorRange.Row Then TargetRow = FloorRange.Row - 1 BirdVerticalMovement = 0 ElseIf TargetRow <= 1 Then TargetRow = 1 BirdVerticalMovement = 0 End If 'Store Destination Cell Set BirdCell = shTest.Cellss(Target.Row) End Sub --------------------------------------------------------------------- 'Draw Bird Public Sub DrawBird() BirdPreviousCell.clear BirdCell.Interior.Color = RGB(255,241,38) End Sub 'Jumping Variables Private Const JumpHeight As Integer = -8 Private Const JumpHeight As Integer = -8 'Key Checking Private PreviousUpKeyState as Integer --------------------------------------------------------------------- 'Check Up Arrow Key Primary Sub CheckKeys() If GetAsyncKeyState(vbKeyUp) <> 0 And ....

Links

Flappy Bird in Excel VBA - Introduction