Add the speed attribute for all items (see sandwich item).
Create the function moveDynamic with the same parameters and if/else as moveStatic.
in the if section, set the x position to twice the display’s content width
set the y position to some random number between 0 and the display’s content height (Hint: look up corona sdk api. Then look at the math library. Which function do you use to choose a random number?)
set the speed to some random number between 2 and 6
set the amplitude (amp) to a random number between 20 and 100
set the angle to a random number between 1 and 360
in the else section, set the self.x to be the speed subtracted from the x
set the self.angle to be the angle plus 0.1
finally have this line: self.y = self.amp * math.sin(self.angle) + self.initY
Add the amp, angle, and initY attributes to the sandwich, pizza, and both donuts (but not to the hole).
set the initY to be y
set all other values to be the same as was coded in the moveDynamic function
Go to the function scene:show. Change the pizza, sandwich and both donuts to moveDynamic.
At this point, test your app.
Now we are creating the points. in the function scene:create,
set points = 0
In the corona sdk api, look at the timer library. Which function do we use to start the timer?
It is the performWithDelay function. We will want to increment in 100 milliseconds (the first parameter), use the function pointsUpdate as the listener (second parameter), and we want the timer to run forever (third parameter with 0 passed in).
Make the scoreTimer = timer.performWithDelay(100, pointsUpdate, 0)
set the fill color of the score (setFillColor using colon, not period) to (0, 100, 0). Do you know what RGB coloring is? It is red-green-blue coloring. Based on this knowledge what color will the score text be?
insert the score into the screengroup
Above the moveStatic function, create a function called pointsUpdate. It takes no parameters.
In pointsUpdate, set points to be points+1. On the following line add this: score.text = string.format(“%d”, points)
Test your app. The score should appear in the bottom right corner of your screen.
Now we will format the start, instructions and replay pages a little further. Download the pictures I sent and put them in your project folder.
Let’s first set up the start and instructions pages.
In start.lua, change all the “button” variables to be called “startButton”
Create instrButton just like how you created startButton. The image to be used is instrbutton.png. Change the y position of the startButton to be 0.3 of the content height. Change the y positions of the instrButton to be 0.8 of the content height.
Add and remove touch event listeners for the instrButton. The listener function should be “goToInstructions”
Create the function goToInstructions EXACTLY like the beginGame function; however, the composer should go to the scene “instructions”
Open instructions.lua. Create a menuButton with the image “troll.png”, and x and y positions halfway across the page. Add it to the screen group
In the function scene:show in the else if section, add a touch event listener to the menuButton with the listener function as “goToStart”. Remove the event listener in the function scene:hide’s if section.
Create the goToStart function EXACTLY like the beginGame function in the start.lua file, but instead the composer should go to the scene “start”
Test your app. The troll face may not be visible, but still click on the center to make sure that you will go back to the main menu page.
Now we will set up the restart page.
Create restartButton just like how you created instrButton (see start.lua for example).
Add and remove touch event listeners for the restartButton in the proper places (see previous instructions 8.6). The listener function should be goToGame
Create the goToGame function EXACTLY like the beginGame function in the start.lua file.
Test your app so that it still runs. You will not be able to reach the restart page just yet.
There is a known error in the restart.lua file. In the toMenu function, “goToScene” should say “gotoScene”. This was my fault, so if you have a question about it, ask me.