Corona SDK: Create a Rapid Roll-like Game - Interaction

This is the second installment in our Corona SDK Rapid Roll 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 credits 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: Remove Title View

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


Step 8: Score & Lives Text

This code creates the Score and Lives text and places them in the stage.


Step 9: Add Initial Blocks

The following function adds the blocks specified in the parameter at a random position, it will also call the function to add the player to the stage.


Step 10: Add Player

The player will be added when the initial blocks are in stage. It will appear in the center X of the stage.


Step 11: Move Player

The Accelerometer is used to move the player across the screen, the value is calculated using the xGravity property.


Step 12: Screen Borders

This code prevents the player from going offscreen on the sides.


Step 13: Add Regular Block

This function is called by a Timer. It will calculate a random number between 1 and 4 and when the result equals 1, a bad block will be added. If the result is different than 1, a normal block will be instantiated. The blocks are added to a Table, this way we are able to access them outside this function.


Step 14: Add Live Graphic

Another timed function, a live graphic will be added when the timer is complete. The live position will be the last block in the table - 1.


Step 15: Game Listeners

This function adds and removes the necessary listeners to start the game.


Step 16: 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 blocks and player movement, collisions, 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