64x64 icon dark hosting
Get a Tuts+ subscription for just $45! Deploy New Relic now to claim.
Advertisement

Create a Sound Based Memory Game - Game Logic

by

This is the second installment in our Corona SDK Sound Memory tutorial. In today's tutorial, we'll add to our interface and the game interaction. Read on!


Also available in this series:

  1. Create a Sound Based Memory Game - Interface Creation
  2. Create a Sound Based Memory Game - Game Logic

Where We Left Off. . .

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


1. Start Button Listeners

This function adds the necessary listeners to the Title View buttons.


2. 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.


3. Hide Credits

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

4. Show Game View

When the Play button is tapped, the title view is tweened and removed revealing the game view. There are many parts involved in this view so we'll split them up in the next steps.


5. Add Square Buttons

This code places the game button images in the stage.


6. Instructions Message

The following lines will add the instructions message, show it for two seconds and then fade it out.


7. Check Button

This button is used to test the user input and make sure it equals the level sounds. It is invisible by default.


8. Game Listeners

This function adds the necessary listeners to start the game logic.


9. Play Level Function

This function reads the currentLevel variable to determine which level to play. It also uses a transition to visually point to the button associated to the sound. When the level sequence is done the check button becomes visible.


10. Record User Input

Pressing the buttons in the center will call this function. It will play a sound and record its value in the userInput table. This table will be used in the next function to compare the sounds.


11. Check Input

This function compares the names of the buttons pressed to the level table, and calls an alert with the corresponding message.


12. Alert

The Alert function creates an alert view, animates it, and ends the game.


13. Call Main Function

In order to start the game, the Main function needs to be called. We'll do that here with the above code in place.


14. Loading Screen

The Default.png file is an image that will be displayed right when you start the application while the iOS loads the basic data to show the main screen. Add this image to your project source folder; it will be automatically added by the Corona compliler.


15. Icon

Using the graphics you created before, you can now create a nice icon. The icon size for an iPhone without retina display is 57x57px, but the retina version is 114x114px and the iTunes store requires a 512x512px version. I recommend creating the 512x512 version first and scaling down for the other sizes.

iTunes and the iPhone will create the rounded corners and transparent glare.


16. Testing in Simulator

It's time to do the final test. Open the Corona Simulator, browse to your project folder, and click open. If everything works as expected, you are ready for the final step!


17. Build

In the Corona Simulator go to File and Build and select your target device. Fill in the required data and click build. Wait a few seconds, and your app will be ready for device testing and/or submission for distribution!


Conclusion

In this series, we've learned about sound loading, playing, and table comparison. These are skills that can be very useful in a wide number of games.

You can experiment with the final result, and try to make your custom version of the game!

I hope you liked this tutorial series and found it helpful. Thank you for reading!

Advertisement