Advertisement
  1. Code
  2. Corona SDK
Code

Corona SDK: Create a Teeter-like Game - Physics and Interaction

by
Difficulty:IntermediateLength:ShortLanguages:

In this tutorial series, you'll learn how to create a Teeter inspired game. The objective of the game is to balance a ball and avoid the obstacles to get to the goal. Read on!


Where We Left Off

In the first tutorial in this series, the Teeter-like Game concept was explained and the interface created. In this tutorial, a basic physics implementation will be created, the game interaction will be coded, and the project will be exported for release.


Step 29: Add Physics

Set the physics properties for each graphic. The static elements can't be moved. Check also that we use the radius property in the player and holes, this declares the physics shape as a circle and not a square, improving the collisions.


Step 30: Set Holes as Sensors

Since we don't need an actual physics response when the collision occurs, we set the holes as sensors.


Step 31: Code Review

Here is the full code written in this tutorial alongside with comments to help you identify each part:


Step 32: Game Listeners

This code adds the Accelerometer and Collision listeners. It passes a parameter to remove them too.


Step 33: Move the Player

The Accelerometer values are captured by this function and then passed to the X and Y property of the ball.


Step 34: Collisions

When the ball collides with an object, its name is compared to the ones given to the holes and goal. Then the corresponding alert is called.


Step 35: Alert

The alert will remove the game listeners, play a sound, and display the correct message.


Step 36: Simulator Movement

I've optionally added this code to move the ball by dragging it in the simulator.


Step 37: Call Main Function

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


Step 38: 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 compiler.


Step 39: Icon

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

Also, the icons It don't need to have the rounded corners or the transparent glare, iTunes and the iPhone will do that for you.


Step 40: Testing in the Simulator

It's time to do 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 final step!


Step 41: 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 will be ready for device testing and/or submission for distribution!


Conclusion

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

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

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.