In this tutorial series, you will learn how to create a minimalistic Alphabet Soup game. The goal of this game is to allow the player to pick words out from a jumbled set of letters. Read on!
Step 1: Application Overview
Using pre-created graphics, we will code an entertaining game using Lua and the Corona SDK API's.
The player will be able to draw a line across the stage in order to highlight a word. 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: 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 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.
application = { content = { width = 320, height = 480, scale = "letterbox" }, }
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.
Necesary Classes Variables and Constants Declare Functions contructor (Main function) class methods (other functions) call Main function
Step 8: Hide Status Bar
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: Game Background
A simple graphic is used as the background for the application interface, the next line of code stores it.
-- Graphics -- [Background] -- [Game Background] local gameBg = display.newImage('bg.png')
Step 10: Title View
This is the Title View, it will be the first interactive screen to appear in our game. These variables store its components:
-- [Title View] local titleBg local title local startBtn local aboutBtn -- [TitleView Group] local titleView
Step 11: About View
This view will show the credits, version, and copyright of the game. This variable will be used to store it:
-- [CreditsView] local about
Step 12: Words List
The list of words to find and the already found will be stored by the next lines.
-- [Words List Textfield] local wordsList local currentWords
Step 13: Game View
The game view is composed by the TextFields that store the single letters, the line used to highlight words and the alert used when the game is complete. Add the following lines to your code to handle these elements.
-- [Letter Texfields Container] local tfs = display.newGroup() -- [Selection Line] local line local lines = display.newGroup() -- [Alert] local alert
Step 14: 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.
-- List of words to find local L1 = {'IPHONE', 'ANDROID', 'CORONA', 'MOBILE', 'GAMES'} -- Multi-dimensional table, this is used as a 'map' to display the words in the stage local L1Map = {{0, 0, 'I', 0, 0, 0, 'G', 0, 0, 0}, {0, 0, 'P', 0, 0, 0, 'A', 0, 0, 0}, {0, 0, 'H', 0, 0, 0, 'M', 0, 0, 0}, {0, 'M', 'O', 'B', 'I', 'L', 'E', 0, 0, 0}, {0, 0, 'N', 0, 0, 0, 'S', 0, 0, 0}, {0, 0, 'E', 0, 0, 0, 0, 0, 0, 0}, {'C', 'O', 'R', 'O', 'N', 'A', 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 'A', 'N', 'D', 'R', 'O', 'I', 'D', 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} local alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} local correct = 0 -- Number of found words
Step 15: Code Review
Here is the full code written in this tutorial alongside with comments to help you identify each part:
-- Alphabet Soup Game -- Developed by Carlos Yanez -- Hide Status Bar display.setStatusBar(display.HiddenStatusBar) -- Graphics -- [Background] -- [Game Background] local gameBg = display.newImage('bg.png') -- [Title View] local titleBg local title local startBtn local aboutBtn -- [TitleView Group] local titleView -- [CreditsView] local about -- [Words List Textfield] local wordsList local currentWords -- [Letter Texfields Container] local tfs = display.newGroup() -- [Selection Line] local line local lines = display.newGroup() -- [Alert] local alert -- Variables local L1 = {'IPHONE', 'ANDROID', 'CORONA', 'MOBILE', 'GAMES'} local L1Map = {{0, 0, 'I', 0, 0, 0, 'G', 0, 0, 0}, {0, 0, 'P', 0, 0, 0, 'A', 0, 0, 0}, {0, 0, 'H', 0, 0, 0, 'M', 0, 0, 0}, {0, 'M', 'O', 'B', 'I', 'L', 'E', 0, 0, 0}, {0, 0, 'N', 0, 0, 0, 'S', 0, 0, 0}, {0, 0, 'E', 0, 0, 0, 0, 0, 0, 0}, {'C', 'O', 'R', 'O', 'N', 'A', 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 'A', 'N', 'D', 'R', 'O', 'I', 'D', 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} local alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} local correct = 0
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!
Comments