Advertisement
  1. Code
  2. Corona SDK
Code

Create a Hundreds-Like Game - Interface Creation

by
Difficulty:IntermediateLength:ShortLanguages:

In this tutorial series, you’ll learn how to create a game like the popular Hundreds. The objective of the game is to reach 100 points without the circles touching while you raise the score. Read on!


Step 1: Application Overview

Using pre made graphics we will code an entertaining game using Lua and the Corona SDK API's.

The player will be able to tap on the circles on the screen in order to increase the score. You can modify the parameters in the code to customize the game.


Step 2: Target Device

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

The iOS platform has these 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. A few of the more 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 be focusing on the iOS platform with the graphic design, specifically developing for distribution to an iPhone/iPod touch, but the code presented here should apply to Android development with the Corona SDK as well.


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


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


Step 5: App Configuration

An external file will be used to make the application go fullscreen 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 is run in a different screen resolution.


Step 6: Main.lua

Let's write the application!

Open your prefered Lua editor (any Text Editor will work, but may not have syntax highlighting) and prepare to write your awesome app. Remember to save the file as main.lua in your project folder.


Step 7: Code Structure

We'll structure our code as if it were a Class. If you know ActionScript or Java, you should find the structure familiar.


Step 8: Hide Status Bar

This code hides the status bar. The status bar is the bar on top of the device screen that shows the time, signal, and other indicators.


Step 9: Import Physics

We'll use the Physics library to handle collisions. Use this code to import it:


Step 10: Background

A simple graphic is used as the background for the application interface, the next line of code stores it.


Step 11: Title View

This is the Title View, it will be the first interactive screen to appear in our game, these variables store its components.


Step 12: Credits View

This view will show the credits and copyright of the game, this variable will be used to store it.


Step 13: Game Background

This image will replace our previous background. This will be the game background.


Step 14: Circles

The circles group will store the five circles that will be created dynamically later in the game. We'll be using the Corona SDK drawing API.


Step 15: Walls

Physics walls are created to make the circles bounce on the screen.


Step 16: Score

The score value is handled by this variable.


Step 17: Alert

This is the alert that will be displayed when you win the game. It will complete the level and end the game. There is also a 'You Lost' alert that will behave in a similar way.


Step 18: Variables

This are the variables we'll use, read the comments in the code to know more about them.


Step 19: Declare Functions

Declare all functions as local at the start.


Step 20: Constructor

Next we'll create the function that will initialize all the game logic:


Step 21: Add Title View

Now we place the TitleView in the stage and call a function that will add the tap listeners to the buttons.


Next Time...

In this part of the series, you've learned the interface and the basic setup of the game. In the next and final part of the series, we'll handle the level creation, collision detection, 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!

Part 2 of This Series - Adding Interaction

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.