Advertisement
  1. Code
  2. Mobile Development
  3. Corona

Corona SDK: Create a Rapid Roll-like Game - Setup

Scroll to top
Read Time: 5 min

In this tutorial series, you'll learn how to create your own version of the classic Rapid Roll game. Read on!


Step 1: Application Overview

Corona SDK Game Figure 1

Using premade graphics, we will code an entertaining game using Lua and the Corona SDK APIs.

The player will be able to move a character across the stage and the platforms using the Accelerometer and you will be able to modify the parameters in the code to customize the game.

Step 2: Target Device

Corona SDK Game Figure 2Corona SDK Game Figure 2Corona SDK Game Figure 2

The first thing we have to do is select the platform we want to run our app within. By doing so, 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

Corona SDK Game Figure 3Corona SDK Game Figure 3Corona SDK Game Figure 3

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

Corona SDK Game Figure 4Corona SDK Game Figure 4Corona SDK Game Figure 4

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.

1
2
application =
3
{
4
    content =
5
    {
6
        width = 320,
7
        height = 480,
8
        scale = "letterbox"
9
    },
10
}

Step 6: Main.lua

Let's write the application!

Open your prefered Lua editor (any Text Editor will work, but you won't 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.

1
2
Necesary Classes
3
4
Variables and Constants
5
6
Declare Functions
7
8
    contructor (Main function)
9
	
10
    class methods (other functions)
11
12
call Main function

Step 8: Hide Status Bar

1
2
display.setStatusBar(display.HiddenStatusBar)

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: Load Physics Engine

We'll make use of the poweful Box2D engine built into Corona, use this code to include it in your app:

1
2
local physics = require('physics')
3
physics.start()
4
physics.setGravity(0, 0)

Step 10: Background

Corona SDK Game Figure 5

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

1
2
-- Graphics
3
-- [Background]
4
5
local bg

Step 11: Title View

Corona SDK Game Figure 6

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

1
2
-- [Title View]
3
 
4
local title
5
local startB
6
local creditsB
7
8
-- [TitleView Group]
9
10
local titleView

Step 12: Credits

Corona SDK Game Figure 7

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

1
2
-- [CreditsView]
3
4
local credits

Step 13: Score & Lives

Corona SDK Game Figure 8

The Score and Lives are handled by the following variables.

1
2
3
local live
4
local livesTF
5
local lives = 3
6
local scoreText
7
local score = 0
8
local alertScore

Step 14: Blocks & Player

Corona SDK Game Figure 9

The blocks are the platforms where our player will step on, stored in the next lines of code.

1
2
-- [Blocks group, Player]
3
4
local blocks
5
local player

Step 15: Game View

Corona SDK Game Figure 10

The gameView variable is a group that will contain all the game graphics, this will help us handle them all at once.

1
2
--[GameView Group]
3
4
local gameView

Step 16: Variables

These are the variables we'll use, read the comments in the code to know more about them. Some of their names are self explaining so there will be no comment there.

1
2
-- Variables
3
4
local moveSpeed = 2
5
local blockTimer
6
local liveTimer

Step 17: Code Review

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

1
2
-- Blocks 'Rapid Roll' like Game
3
-- Developed by Carlos Yanez
4
5
-- Hide Status Bar
6
7
display.setStatusBar(display.HiddenStatusBar)
8
9
-- Physics
10
11
local physics = require('physics')
12
physics.start()
13
physics.setGravity(0, 0)
14
15
-- Graphics
16
-- [Background]
17
18
local bg
19
20
-- [Title View]
21
 
22
local title
23
local startB
24
local creditsB
25
26
-- [TitleView Group]
27
28
local titleView
29
30
-- [CreditsView]
31
32
local credits
33
34
-- [Score & Lives]
35
36
local live
37
local livesTF
38
local lives = 3
39
local scoreText
40
local score = 0
41
local alertScore
42
43
-- [Blocks group, Player]
44
45
local blocks
46
local player
47
48
--[GameView Group]
49
50
local gameView
51
52
-- Variables
53
54
local moveSpeed = 2
55
local blockTimer
56
local liveTimer

Next Time...

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

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
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.