Corona SDK: Create a Whack-a-Mole Game – Adding Interactivity

This is the second installment in our Corona SDK Whack A Mole 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: Load Sounds

Sound effects used in the game will be loaded at start. This will make them ready for play immediately.


Step 2: Variables

These are the variables we'll use. Read the comments in the code to know more about them. Some of their names are self explanatory, so there will be no further comment there.


Step 3: Declare Functions

Declare all functions as local at the start.


Step 4: Constructor

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


Step 5: Add the Title View

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


Step 6: Start Button Listeners

This function adds the necesary listeners to the TitleView buttons.


Step 7: Show Credits

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


Step 8: Hide the Credits

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


Step 9: Show Game View

When the Play button is tapped, the title view is tweened and removed revealing the game view. The score text is added in this step too.


Step 10: Prepare Worms

The following function creates and places the worms in the stage. We hide them later and add a tap listener to each one.


Step 11: Code Review

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


Next Time...

In the next and final part of the series, we'll handle the worms animation, tap events to 'hit' the worm, and the final steps to take prior to app 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