Advertisement
  1. Code
  2. Corona SDK
Code

Corona SDK: Build a Shell Game - Interaction

by
Difficulty:IntermediateLength:ShortLanguages:

This is the second installment in our Corona SDK Three Shell 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: 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 comment there.


Step 2: Declare Functions

Declare all functions as local at the start.


Step 3: Constructor

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


Step 4: 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 5: Start Button Listeners

This function adds the necesary listeners to the TitleView buttons:


Step 6: 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 7: Hide Credits

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


Step 8: Remove Title View

When the Play button is tapped, the title view is tweened and removed, revealing the game view. All the game graphics are added by this function, check each component in the following functions.


Step 9: Bank Credits

This code adds the bank credits text as well as the bank image.


Step 10: Ball

The ball is instantiated by the next line, a center position is given to it:


Step 11: Shells

Next are the Shells wich are positioned in the left, center and right parts of the stage, we use also a group to index them and use them later.


Step 12: Button Bar

Lastly, the button bar is added, this is the dark background, message text, and bet button.


Step 13: 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 shells animation, tap events to select the shells, 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!

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.