Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Our goal now is make the game get more difficult as it progresses. And to do that we want to increase the number of moles allowed on the screen at once. We will start in the Game::tick method. At the very bottom, we will check to see if increasedElapsed is greater than or equal to increaseMolesAtTime, and here we will control the number of moles that can be on the screen at once and the amount of time between the moles, so the game will get progressively more difficult. So the first thing we will do is create an integer maxMolesAtOnce and set that equal to 18 and then we will check to see if molesAtOnce is less than maxMolesAtOnce.
If so we will increase molesAtOnce. Then we will create a float called minMoleTime, this is going to be minimum time between moles. Set that equal to .1f, so a tenth of a second is the minimum time between moles. On the next line, we will subtract from time between moles. timeBetweenMoles -=, in parentheses will do a condensed if statement on this line, so timeBetweenMoles > minMoleTime, and if that's the case we are going to subtract .05 from timeBetweenMoles, if not we will subtract nothing.
Go to the next line, we are going to add on to increaseMolesAtTime by ten seconds. So += 10.0f. So it will gradually get harder and each time there are more moles on the screen, it will take ten more seconds to add an additional mole. Outside of that inner if statement, we are going to set increaseElapsed = 0. Now we will save and test this in the emulator, and what you should see is that overtime the game becomes more and more difficult. So there are more and more moles on the screen at once.
So now I will click Play and I will play the game for over 10 seconds and after that time we should start seeing four moles on the screen at once. There are our four moles. So as you play longer and longer, the game should get more and more difficult and now it feels more challenging. So it's more game like. I just remember that if the game is too easy or too hard for you then you can adjust that simply by controlling the values of these variables.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 100129 Viewers
56 Video lessons · 113153 Viewers
71 Video lessons · 82024 Viewers
131 Video lessons · 39354 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.