How to Make a Simple iOS and Android Game with Corona Tutorial

This is a post by Tutorial Team Member Greg Pugh, author of the Colin Turtle children’s eBook app series. You can also find him on Google+. You have probably seen some stories on the news and on the web about kids that are developing mobile apps at an early age. Often they use the Corona […] By .

Leave a rating/review
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

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:

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!


This is a post by Tutorial Team Member Greg Pugh, author of the Colin Turtle children’s eBook app series. You can also find him on .