Corona SDK: Create a Balloon Game - Interaction

This is the second installment in our Corona SDK Bloons inspired Game tutorial. In today's tutorial, we'll add to our interface and start coding the game interaction. Read on!


Where We Left Off. . .

Please be sure to check part 1 of the series to fully understand and prepare for this tutorial.


Step 1: Declare Functions

Declare all functions as local at the start.


Step 2: Constructor

Next, we'll create the function that will initialize all the game logic:


Step 3: Add Title View

Now we place the TitleView in the stage and call a function that will add the tap listeners to the buttons.


Step 4: Start Button Listeners

This function adds the necesary listeners to the TitleView buttons.


Step 5: Show Credits

The credits screen is shown when the user taps the about button. A tap listener is added to the credits view to remove it.


Step 6: Hide Credits

When the credits screen is tapped, it'll be tweened out of the stage and removed.


Step 7: Show Game View

When the Start button is tapped the title view is tweened and removed, revealing the game view.


Step 8: Game Listeners

This code adds tap listeners to the game background. These will be used to shoot the acorns to the balloons. A tap listener is also added to the restart button.


Step 9: Start Game

Here we start the game by hiding the direction indicator, adding the game listeners and calling the function that generates the balloons.


Step 10: Create Balloons

A double for loop is used to create and place the balloons on the stage. The balloon is then added to a table. This will grant us access to the balloons outside this function.


Step 11: Collisions

This function handles the acorn-balloon collisions.

When this occur, the balloon is removed from the stage and a sound is played. We also update the score and target textfields.


Step 12: Start Charge

This code will reveal the direction indicator, reset the acorn's impulse variable, and add a frame listener that will handle the aim and impulse value.


Step 13: Charge

The aim rotates accordingly to the direction that will take the acorn, which is set by the impulse variable.


Step 14: Code Review

Here is the full code written in this tutorial, alongside with the comments to help you identify each part:


Next Time...

In the next and final part of the series, we'll handle the acorn shooting, level restart, and the final steps to take prior to release like app testing, creating a start screen, adding an icon and, finally, building the app. Stay tuned for the final part!

Tags:

Comments

Related Articles