Games [BANanoPhaser 0.2+] Exploring tweening with a coin catcher

Discussion in 'Game Development' started by Mashiane, Nov 15, 2019.

  1. Mashiane

    Mashiane Expert Licensed User



    Welcome to game 4. The purpose of this game is to explore more game tricks. For example.


    1. Instead of adding a collision detector, we return the result of physics.overlap, a boolean.
    2. We have removed gravity on the game configuration. This enables us to have the elements not falling off the screen.
    3. We set a background color for the game.
    4. We use BANano.CallSub to call another method within the game when something happens. This is using the CallBack but we havent used any callbacks on this example.

    We keep on improving on the code readability to ensure that transitioning from javascript to BANanoPhaser is simple enough.

  2. Mashiane

    Mashiane Expert Licensed User

    1. We use a preload-scene to load our resources, when this is complete it starts the game.

    Sub onPreload
    Dim value As Double
    Dim onloadCB As BANanoObject = BANano.CallBack(Me, "onProgress"Array(value))
    "progress", onloadCB)
        Dim onCompleteCB As BANanoObject = BANano.CallBack(Me, "onComplete"Null)
    "complete", onCompleteCB)
        'start loading the assets
    End Sub
    2. When the game starts, it fires onCreate, here we place our player and other objects on the arcade. As the player and the coin will collide, onUpdate, we need to trap the cursor movements, we then run .createCursorKeys.

    Sub onCreate
    'get random x and y values
        player = Scene.physics.add.sprite(100100"player")
        coin = Scene.physics.add.sprite(
    'ensure these dont fall outside the scene
    'initialie the scoreboard
        score = 0
    Dim style As Map = CreateMap("font""20px Arial""fill""#fff")
        scoreText = Scene.add.text(
    2020"Score: " & score, style)
    'trap keypress
        arrow = Scene.input.keyboard.createCursorKeys
    End Sub
    3. When the game is played, when the player is moved via the arrow keys, detect an overlap between the coin and the player. If there is a collision, fire the hit sub. The movement of the player is ensured that when the keys are pressed down, the x and y positions are incremented and decremented.

    Sub onUpdate
    If Scene.physics.overlap(player, coin) Then
    End If

    If arrow.right.isDown Then
    'increment x of plater
    else if arrow.left.isDown Then
    'decrement x of player
    End If

    If arrow.down.isDown Then
    'increment y of player
    else if arrow.up.isDown Then
    'decrement y of player
    End If
    End Sub
    4. Looking at the hit Sub..

    The hit subs generates an x and y random value and moves the player to the new location. Also the score is incremented.

    Sub hit
    'set x and y values with random numbers
        coin.X = Scene.MathBetween(100600)
        coin.y = Scene.MathBetween(
    'increment the score board
        score = score + 10
    "Score: " & score)
    'add a tween: i.e A Tween allows you to alter one or more properties of a target object over a defined period of time.
        Scene.tweens.add(player, 2001.21.2True)
    End Sub
    As noted, this game also just deals withe the barebones of game development. You can explore the other examples for more functionality especially the Approximately game that has more logic also.

  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