How to Make a Simple iOS and Android Game with Corona Tutorial
- Getting Started
- Choosing a Text Editor
- Being Resourceful
- Building Our Settings
- Configuring Your Config File
- Onto the Main Event
- Care to Comment?
- Status Bar? We Don’t Need No Steenkin’ Status Bar!
- Let’s Get Down with Physics
- Constantly Writing Variables
- Giving the Player Feedback
- Bring Balloons to the Party
- Two Walls and a Ceiling
- Let’s Play Ball(oon)!
- It’s the Final Countdown
- Why Won’t These Balloons Pop?!
- Where to Go From Here?
Why Won’t These Balloons Pop?!
So you’ve added the ability to pop the balloons, but what gives? The balloons still won’t pop!
Take a look back at the code for clues. You added the functionality to myBalloon that listens for a user touch. If the balloon is touched, it plays a pop sound and removes the balloon from the app. If there’s time on the clock, the game is allowed to start, and the code tracks each balloon by adding 1 to each generated balloon.
Hey, wait a minute! You never told the game to actually start — d’oh! :]
Add the following code to the end of startGame (just after the spot where the event listener is added to the balloon):
-- If all balloons are present, start timer for totalTime (10 sec) if (balloons == numBalloons) then gameTimer = timer.performWithDelay(1000, countDown, totalTime); else -- Make sure timer won't start until all balloons are loaded playerReady = false; end
The above code checks if all of the balloons are generated, and if they are, calls the countDown function. Note that the gameTimer variable is re-used here to create a new timer which tracks the time left in the game at 1 second (1000 milliseconds) intervals.
If you run the game now, you will see “…Loading Balloons…” while the balloons are being generated, and then “Hurry!” once the timer starts. You don’t want the player having an unfair advantage and being able to pop balloons before the timer starts. That’s why you have a loading period.
If you want to make the game harder (or easier), altering the game is very easy. You can change the number of balloons or the time by changing the following variables:
-- How many balloons do we start with? numBalloons = 100; -- Game time in seconds that we'll count down startTime = 20; -- Total amount of time totalTime = 20;
And there you have it, a balloon game that will run on any device the Corona SDK supports!
Where to Go From Here?
Here is the completed source code for the tutorial.
There’s a lot more you can do to make this game more exciting:
- Add a counter for the number of balloons popped. This gives the player an idea of their progress in the game; you could even show a total balloons counter which gradually decreases as the player pops more balloons.
- Add a scoring system where each balloon popped adds to the players score. You can get fancy and have different scores for multiple pops at the same time (you’ll need to figure out how to detect multiple touches first!).
- Try adding different colored balloons where each colour has a different value, so that popping certain colors (or the same colour in sequence) gives a higher score.
- Add a reset button so the user can abort the game in progress and start a new one..
In addition, if you want to learn more about Corona, we have two more tutorials about Corona on this site that you might enjoy:
- How To Make a Game Like Doodle Jump with Corona Tutorial
- How To Make a Game Like Jetpack Joyride Using LevelHelper and SpriteHelper [Corona Edition]
I hope to see you create some fun Corona games in the future! And if you have any questions or comments about this tutorial or Corona in general, please join the forum discussion below!