Corona SDK: Create an Alphabet Soup Game – Final Steps

Corona SDK: Create an Alphabet Soup Game – Final Steps

Tutorial Details
  • Technology: Corona SDK
  • Difficulty: Intermediate
  • Completion Time: 30 - 45 Minutes
This entry is part 3 of 3 in the series Create an Alphabet Soup Game

Welcome to the final tutorial in our Alphabet Soup game series! In this tutorial, we’ll handle word selection and the steps necessary to build the final app.


Step 1: Hit Test Objects Function

We’ll use an excellent and useful function for collision detection without physics. You can find the original example and source at the Ansca Code Exchange website.

-- by jhocking
function hitTestObjects(obj1, obj2)
        local left = obj1.contentBounds.xMin <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= obj2.contentBounds.xMin
        local right = obj1.contentBounds.xMin >= obj2.contentBounds.xMin and obj1.contentBounds.xMin <= obj2.contentBounds.xMax
        local up = obj1.contentBounds.yMin <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= obj2.contentBounds.yMin
        local down = obj1.contentBounds.yMin >= obj2.contentBounds.yMin and obj1.contentBounds.yMin <= obj2.contentBounds.yMax
        return (left or right) and (up or down)
end

Step 2: Detect Letters

The next function will run when the user lifts the finger used to select the word. It will calculate the selected letters using the function created in the previous step.

function detectLetters:touch(e)
	-- Code...
end

Step 3: Get Selected Letters

A string variable is created to store the letters highlighted by the line.

	-- Get selected letters
		local selectedWord = ''
		for i = 1, tfs.numChildren do
			if(hitTestObjects(lines[lines.numChildren], tfs[i])) then
				selectedWord = selectedWord .. tfs[i].text
			end
		end

Step 4: Check If Word is On List

This code checks the generated string and compares it to the elements in the words table. If the word is found a sound is played and the counter rises.

-- Check if word is on list
		for j = 0, 5 do
			if(selectedWord == L1[j]) then
				audio.play(bell)
				currentWords.text = currentWords.text .. ' ' .. selectedWord
				currentWords:setReferencePoint(display.TopLeftReferencePoint)
				currentWords.x = 5
				correct = correct + 1
			end
		end
	end

Step 5: Check for Game Over

When the counter reaches the same amount of words in the table an alert is called.

	if(correct == #L1) then
		alert()
	end

Step 6: Alert

The alert function stops the game, removes the listeners, and displays a game status message.

function alert()
	gameListeners('rm')
	alert = display.newImage('alert.png')
end

Step 7: Call Main Function

In order to initially start the game, the Main function needs to be called. With the above code in place, we’ll do that here:

Main()

Step 8: Loading Screen

The Default.png file is an image that will be displayed right when you start the application while iOS loads the basic data to show the Main Screen. Add this image to your project source folder, it will be automatically added by the Corona compiler.


Step 9: Icon

Using the graphics you created before you can now create a nice and good looking icon. The icon size for the non-retina iPhone icon is 57x57px, but the retina version is 114x114px and the iTunes store requires a 512x512px version. I suggest creating the 512×512 version first and then scaling down for the other sizes.

It doesn’t need to have the rounded corners or the transparent glare, iTunes and the iPhone will do that for you.


Step 10: Testing in Simulator

It’s time to do the final test. Open the Corona Simulator, browse to your project folder, and then click open. If everything works as expected, you are ready for the final step!


Step 11: Build

In the Corona Simulator go to File > Build and select your target device. Fill the required data and click build. Wait a few seconds and your app will be ready for device testing and/or submission for distribution!


Conclusion

Experiment with the final result and try to make your custom version of the game!

I hope you liked this tutorial series and find it helpful. Thank you for reading!

Series Navigation«Corona SDK: Create an Alphabet Soup Game – Interaction

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Fotis

    The project does not work well.
    After selecting start, the letters appearing scaled-stretched and cannot be readable.
    Pls fix.

  • Mohamed

    Thanks Carlos. I have a question:

    Which version of Corona are you using? I opened the main.lua file in Corona simulator and it does not seem to work.

    I have build 2011.704.

    Once it is launched, I can see the screen page, but once clicked on Start, I see a gray screen. Is this normal? I do not see any alphabet. Any idea?

  • Mohamed

    It seems that there is a gray layer above the orange one. Can you please check Carlos? It does not display properly in the simulator. I can send you a screen shot if you send me a message.

    • Ben

      I have the same problem, a gray screen when trying to start the game. Did you get this fixed?

  • Le

    For the text problem, it must be a difference in how Corona handles the device fonts nowadays, this is the second tutorial I have come across where the font is screwed up, this one is a very easy fix.

    Comment out the two lines tf.width and tf.height in buildSoup()

    If anyones interested, I also made a small change so that when the user drags around after touching it updated a line real-time. I found it weird that you cant see the line until after you let go. If you want to do the same then make these changes.

    Add a line at the top of main.lua where you are instantiating the groups

    – [Feedback Line]
    local feedBackLine = display.newGroup()

    then in the startDraw function add:

    if (e.phase == ‘moved’) then
    for i = 1, feedBackLines.numChildren do

    feedBackLines:remove(i)
    end
    tempLine = display.newLine(initX, initY, e.x, e.y)
    tempLine.width = 16
    tempLine:setColor(255, 0, 0, 25)
    feedBackLines:insert(tempLine)
    end

    BTW, if you notice that the line looks darker until you draw another line, thats because I didnt remove the line after the touch has ended, if you want to do that, copy the feedBackLines:remove loop into the e.phase == ‘ended’ condition

    • Le.

      Also, great tutorial man.

    • Joe

      think you have a typo … local feedBackLine = display.newGroup() should be local feedBackLines = display.newGroup() right?