Part 5
There are 3 errors in this section.
Since the only input in to the game is a mouse click, we just set playerClicked to be true, the rest of the game logic will be added later.
Check your errors here.
Part 6
There are 3 errors.
This is what the game loop looks like. The game loop has 3 other functions: handleUserInput is in charge of any player inputs, like mouse or keyboard;
handleGameLogic updates player movements, etc;
handleDraw doesn’t do much except let the player know what’s happening in the game by updating the UI. For example, when the score goes up, the player can see the number increase on the score textfield.
When those functions are done, the gotoWin and gotoLose variables are checked to see if they are true, if they are, the functions will be called and the game will end.
Check your mistakes here.
Part 7
There are 4 mistakes in this section.
playerClicked is going to be set to true when the player clicks their mouse anywhere on the game stage. When that happens speed will be set to -16. The negative value means that the bird will move up. Check out these two pictures to see why that is so.
See, y increases as it goes down. So a negative y value means something going up.
Maybe this because you always scroll down on a web page when it loads.
Try switching the 16 to another number and seeing what happens when the game is done.
We also have to set playerClicked to false after we acted on it.
Check the mistakes here.
Part 8
This section has 3 errors.
The beginning of the function updates the position of the bird (“mcPlayer”) by adding the speed to the y position. If the speed is negative, the y position decreases, therefore going up. After that we put in the gravity to make the speed go in the positive (downwards) direction, you can make a different value for gravity and see how the game changes.
In our version, if the bird goes up to the top of the screen it will die, just like it will when it hits the bottom of the screen. The code will then check the players position as either less than 0, or higher than 600 (the bottom most pixel) and if one of those is true, setting gotoLose to be true.
Check your code here.
Part 9
There is only one error in this section.
We will loop through the pipes array that has all the names of the pipes (see startgame), currPipeName will store the name, and we do var currPipe = this[currPipeName], we get the actual reference to the respective pipe movieclip.
Next, we will move each of the pipes to the left. We are using a speed of -8 here; feel free to experiment with it but just make sure it is negative so it will move to the left.
Then we check the collision of the pipe with the bird by using hitTestPoint. This has the effect of making the game a little bit easier, because if the edges of the bird touches the pipes, the bird will still live. If there is a hit, gotoLose will be true and the game will be set to end.
If the bird misses the pipe then currPipe passes by the bird, we set it to invisible (visible = false) and adds 0.5 score to the game. There will always be two pipes so .5+.5 = 1 point per set of pipes.
Click on this to see the error.
The last three sections are so small, I am not going to put any errors in them, (at least not on purpose).
Part 10
Our game only has 8 sets of pipe obstacles, so one that part is cleared, the player has won. Feel free to add extra sets of pipe obstacles if you want.
Part 11
Usually we use the handleDraw function to update the UI displays, but here update the text field that shows the score (txtScore).
Part 12
The two functions triggerGoToLose and triggerGoToWin are called when the lose or win states happen. We then remove the game loop so the game doesn’t keep running, then we can jump to the correct frame to show a won or loss.
Note: This tutorial was originally made by Joseph Tan and was adapted for you wonderful people under a creative commons licence.
You must be logged in to post a comment.