CoronaSDK: Create an Entertaining Bouncing Game

In this tutorial, I'll show you how to create a bouncing game with the Corona SDK. You'll learn more about the Drawing API, touch controls, and random numbers. The objective of this game is to use a paddle to prevent balls from touching the floor. To learn more, read on!

1. Application Overview

We'll use pre-made graphics to code an exciting game using Lua and Corona SDK API's.

Upon completion, the player will use the touch screen on the device to control a paddle. The parameters in the code can be modified to customize the game.

2. Target Device

The first thing we have to do is select the platform we want to run our app in. This way we'll be able to choose the size for the images we will use.

The iOS platform has the following characteristics:

iPad 1/2/Mini: 1024x768px, 132 ppi

iPad Retina: 2048x1536, 264 ppi

iPhone/iPod Touch: 320x480px, 163 ppi

iPhone/iPod Retina: 960x640px, 326 ppi

iPhone 5/iPod Touch: 1136x640, 326 ppi

Because Android is an open platform, there are many different devices and resolutions. Some of the common screen characteristics are:

Asus Nexus 7 Tablet: 800x1280px, 216 ppi

Motorola Droid X: 854x480px, 228 ppi

Samsung Galaxy SIII: 720x1280px, 306 ppi

In this tutorial we'll focus on the iOS platform with the graphic design, specifically to develop for distribution to an iPhone/iPod touch, but the code presented here applies to Android development with the Corona SDK as well.

3. Interface

A simple and friendly interface will be used. This involves multiple shapes, buttons, bitmaps, and more.

The interface graphic resources necessary for this tutorial can be found in the attached download.

4. Export Graphics

Depending on the device you have selected, you may need to export the graphics in the recommended PPI. You can do that in with your favorite image editor.

I used the Adjust Size... function in the Preview app on Mac OS X.

Remember to give the images a descriptive name and save them in your project folder.

5. App Configuration

We'll use an external file to make the application become full-screen across devices (the config.lua file). This file shows the original screen size and the method used to scale that content in case the app runs in a different screen resolution.

27. Score

Here's a score TextField to create at the top-right of the stage:

-- Score
score = display.newText('0', 300, 0, 'Futura', 15)

28. Physics

Next we need to add physics to our objects. Here we'll use the Filter property that prevents certain objects from colliding with each other. This prevents our circles from colliding while keeping collisions between the walls and paddle. You can find a simple explanation of its behavior at the Corona Site.

31. Add a Circle

The circleTimer calls this code. It creates a circle or ball at the top of the screen (which is then moved down by gravity) and gives it a random size and color picked from our colors Table. The color values are then stored to to change the paddle as well. A little push is added in a random direction calculated by the dir and r variables.

34. Call Main Function

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

Main()

35. Loading Screen

The Default.png file is an image that's displayed when the application starts while iOS loads the basic data to show in the Main Screen. Add this image to your project source folder, then it will be automatically added by the Corona compliler.

36. Icon

Using the graphics you created before, you can now create a good looking icon. The icon size for the non-retina iPhone icon is 57x57px, but the retina version is 114x114px. Keep in mind that the iTunes store requires a 512x512px version. I suggest creating the 512x512 version first and then scaling down for the other sizes.

It doesn't need to have the rounded corners or the transparent glare, iTunes and the iPhone does that for you.

37. Testing in Simulator

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

38. Build

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

Conclusion

In this tutorial, we've learned about drawing API, timers, random numbers, and other skills that can be incredibly useful in a wide number of games.

Experiment with the final result and try to make your own custom version of the game!

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