Games [XUI2D] Flappy Bird Example

Discussion in 'Game Development' started by Erel, Jul 19, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User



    Example of a "flappy bird" game. The images and sounds are based on Clumsy Bird open source project: https://github.com/ellisonleao/clumsy-bird (GPL license)

    Interesting points:

    - The moving ground required some work to correctly adjust its position. It moves a bit backwards and then jump forward.
    - The pipes are all drawn from the same two images, one for the top pipes and one for the bottom pipes. The default behavior of the built-in graphic cache is to draw the full image. A delegate class was added and it creates the drawing task with the specific part.
    - I've added another ImageView named ivMessages. It is used for the "get ready" and "game over" messages.
    - The bird is rotated based on its velocity vector direction:
    Code:
    bw.Body.SetTransform(bw.Body.Position, ATan2(bw.Body.LinearVelocity.y, bw.Body.LinearVelocity.X))
    The three projects are attached. All the classes are the same. Only Main module and the layout files are different.
     

    Attached Files:

  2. ivan.tellez

    ivan.tellez Active Member Licensed User

    @Erel, CompressedBC Is from a New BitmapCreator? Last version in Updates to internal libraries for B4A is 3.50?

    Edit: Found ver 4.0 in the XUI2D thread
     
    Last edited: Jul 19, 2018
  3. ivan.tellez

    ivan.tellez Active Member Licensed User

    Really FUN to play with the code. A little frustraiting the collition in the game

    It feel betther with a circle Fixture instead of a rectangle in the Create_Bird sub:

    Code:
    'Dim rect As B2PolygonShape
        'rect.Initialize
        Dim size As B2Vec2 = X2.GraphicCache.GetGraphicSizeMeters(wrapper.GraphicName, 0)
        
    'rect.SetAsBox(size.X / 2, size.Y / 2)
        'wrapper.Body.CreateFixture2(rect, 0.2)
      
        
    Dim bShape As B2CircleShape
        bShape.Initialize(size.Y / 
    2)
      
        
    Dim fix As B2FixtureDef
        fix.Shape = bShape
        fix.Density = 
    0.2
      
        wrapper.Body.CreateFixture(fix)
     
    Last edited: Jul 21, 2018
    Erel likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    I've uploaded a new version. The GameOver sub is a resumable sub with several steps and sleep periods. This update fixes a bug that happened when the game was paused and resumed during these steps.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Another bug: by default bodies are deleted once they are not visible. This can be disabled by setting BodyWrapper.DestroyIfInvisible to False.

    However if we use a custom delegate class for the body then we need to take care of it ourselves. The Pipe class is missing this code from the Tick:
    Code:
    If bw.IsVisible = False Then
           bw.Delete(GS)
           
    Return
       
    End If
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Examples were updated based on XUI2D v0.92.

    The bird shape is now a circle. It is closer to the bird graphic.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Projects were updated with the latest version of X2 framework.
     
    Jaames likes this.
  8. Peter Simpson

    Peter Simpson Expert Licensed User

    Nice, runs smoothly @Erel.

    So when are you going to release games under Anywhere Games ;)
     
  9. LucaMs

    LucaMs Expert Licensed User

    Never. Selling development tools is more profitable :D
     
    Toky Olivier likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice