Corona SDK: Develop a Frenzic-like Game - Adding Interactivity

Welcome to the second post in our Corona SDK Frenzic-like game series. In today's tutorial, we'll be adding interactivity to our interface and coding the start of the game.

Where We Left Off. . .

Please be sure to check part 1 of the series to fully understand 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 background and titleView in the stage.

Step 4: Button Listeners

In this function we add the tap listeners to the buttons in the title view, this will take us to the game screen or the credits screen.

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 will be tweened out of the stage and removed.

Step 7: Add Game View

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

Step 8: Remove the Title View

The title view is removed from memory and the game graphics are added to the stage.

Step 9: Game Listeners

This function will add a Tap Listener to the square containers so you can tap them and place the current block in the center (holder) container.

Step 10: Container Variables

These variables are created inside the square containers, they are used to register the blocks, colors, and positions inside every square.

The letters represent the following positions:

  • a: top-left
  • b: top-right
  • c: bottom-left
  • d: bottom-right

Step 11: Generate Random Block

This code picks a random block color from the Table, this will be used to instantiate the actual block. A parameter is used to determine if the timer needs to be started.

Step 12: Add a New Block

After selecting the block color, the position where it will be placed its calculated using the positions table and then added to the blocks table and the stage.

Step 13: Check Available Space

Before continuing with the game, we must check that the newly created block can actually be placed in a square container. The following code checks every container array to make sure that there is a position available to place the block. If not, the block is destroyed and the function is called again to generate another one.

Step 14: Start Timer

The timer starts counting when the function is called for the first time.

Step 15: Lives

Three seconds are given to place a block in a square container, if that time passes and the block is still in the center square, a life will be removed.

Step 16: Unused Blocks

After removing the life, the block in the center square will be destroyed and a new block will be generated.

Step 17: Check for Game Over

This code checks if the player is out of lives and calls a function that will handle that.

Step 18: 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 behavior, scores, and the final steps to take prior to releasing the app -like app testing, creating a start screen, adding an icon, and building the app. Stay tuned for the final part!

Tags:

Comments

Related Articles