Corona SDK: Create a Whack-a-Mole Game - Application Setup

In this tutorial series, you'll learn how to create your own version of the classic Whack-a-Mole game. However, instead of using moles, our unfortunate creatures of choice will be worms. 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 worms on screen and get points.

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: 1024x768px, 132 ppi

iPhone/iPod Touch: 320x480px, 163 ppi

iPhone 4: 960x640px, 326 ppi

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

Google Nexus One: 480x800px, 254 ppi

Motorola Droid X: 854x480px, 228 ppi

HTC Evo: 480x800px, 217 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 worm graphic used in this tutorial was downloaded from here under a Creative Commons License.

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: Sound

We'll use Sound Effects to enhance the feeling of the game, you can find the sound used in this example on Soungle.com using the keyword hit.

Step 6: 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 9: 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 10: MovieClip Library

local movieclip = require('movieclip')

Animated graphics will be used in this game, the Corona movieclip library will make this a lot easier.

Step 11: Background

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

-- Graphics
-- [Background]
local bg = display.newImage('gameBg.png')

Step 12: Title View

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

local title
local playBtn
local creditsBtn
local titleView

Step 13: Credits

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

local creditsView

Step 14: Score

The score value will be handled by the next variable.

local score

Step 15: Worms

The following variables are used to store the worms graphics and the last worm that has been visible.

local w1
local w2
local w3
local w4
local w5
local w6
local w7
local w8
local worms
local lastWorm = {}

Step 16: Code Review

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

-- Whack A Worm Game
-- Developed by Carlos Yanez
-- Hide Status Bar
display.setStatusBar(display.HiddenStatusBar)
-- Import MovieClip
local movieclip = require('movieclip')
-- Graphics
-- [Background]
local bg = display.newImage('gameBg.png')
-- [Title View]
local titleBg
local playBtn
local creditsBtn
local titleView
-- [Credits]
local creditsView
-- [Score]
local score
-- [Worms]
local w1
local w2
local w3
local w4
local w5
local w6
local w7
local w8
local worms
local lastWorm = {}

Next Time...

In this part of the series you've learned the interface and the basic setup of the application. Stay tuned for part two where we will handle the logic of the application, buttons behavior and more. See you next time!