Difficulty Scaling

4 minutes
Share the link to this page
Copied
  Completed

Transcript

Haider, in this lecture, we are going to add difficulty scaling in our game. Basically, our game is an infinite scroller, so you can keep playing indefinitely until you lose. So after some time the game will become boring, the enemies will keep coming at the same speed and you will keep shooting at them. So we want to make a challenging, we want to make the game harder as it progresses. So for that, we'll add a variable called difficulty. When the game starts, that variable will be at one and its value will keep going up but slowly, now the speed of the background and the enemies will be dependent on this difficulty variable.

So when the difficulty variable retail say true, the enemies will be going at twice the speed. So this way, the game will just keep becoming harder. So let's begin. First of all, I'll open our manager. I'll open this create event. Now here I'll add the variable action.

I'll create the variable difficulty with a value of one Now I'll add the step event, he will increase the value of the difficulty variable. So I'll add the variable action. In the name, I'll enter difficulty in the value I'll enter 0.0003 and declarative. So as you can see, the difficulty variable will go up by this very small value so that it takes some time to get harder. Now we need to change the background speed based on the difficulty. So first, I'll open the game room to check the background speed.

Also remember the name of the background layer, which is simply background. Now I'll go here and you can see that the backgrounds vertical speed is four, so we'll simply multiply this speed with the difficulty variable. So I'll go back to the object now. Now there's no action for changing the speed over layer, so we'll need to use a function. A function is like an action. It takes some input values and performs an action and usage is like a script where you have to specify arguments functions are actually used in coding, but you can also use functions in drag and draw using an action.

So in the actions our search function and add the function call action. Now you need to write the name of the function which is layer underscore v speed, this function changes the vertical speed of a layer. Now in the first argument of the function, we need to specify the name of the layer that we are modifying. So I'll type background as a string, so make sure you don't forget the quotation marks. Now I'll click on the plus sign here to add another argument. The second argument needs to be the vertical speed.

So here I'll enter four multiplied by the difficulty value. So now the vertical speed of the background layer will change based on the difficulty variable. And now I'll open the drawers UI event, you will draw the difficulty variable but only for testing. Now this is where the score is wrong. So after this, I'll add the draw value action. First, I'll set the caption to Dave Then in the value Atlanta difficulty, the exposition for this will be the same as above and the y will be 60.

So there should draw the difficulty value but this is not something that the player needs to see so make sure you remove it later. Now we need to apply the difficulty to these three objects the islands the enemies and the power ups. So an open Oh Island and go to is creative and you can see that it's vertical speed is for now I'll add the step events. Here I'll add the set speed action. First I'll change the tire to vertical and then in the speed island to four multiplied by Oh manager dot difficulty. So the island speed will be based on the difficulty variable as well.

And I typed all manager dots before the variables name since the variable belongs to all manager. Now I'll open Oh enemy and do the same here. I'll open the creative and and you can see there the verticals Here is to show I'll open the step event and add the set speed action. Just like before, I'll make a dependent on the difficulty variable. And now I'll do it in power parent as well. I'll open the creative and and its vertical speed is true as well.

So in the step event, I'll do the same. So I'll run the game and play it. You can see the difficulty value here is going up slowly. I'll skip ahead and now everything is faster. You can see it in this comparison. And now let's move on to the next lecture.

We will make the enemies move horizontally.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.