Power Up Speed

power up higher speed

How to implement this Pattern in MakeCode

Requirements

This tutorial assumes you have a timer on your platformer.

Create our power up sprite

To create a power up we will replicate the for element loop used to display the Food elements on our game. So the first step is to duplicate that and to make changes to the values. You can find more detailed instructions on how to do this is the create static enemeies pattern. To start change your level Tilemap design to add a new colour tile to act as our power up and change the value of your timer to be one the player would not be able beat if they travelled at normal speed.

power up speed

In the example above you can see that the layout of the level is longer than the starting one. This is due to this pattern working well will longer levels.

Follow the code pattern shown in the screenshot below to make the power up appear in our game. power up speed

Create a new Variable

To be able to change the speed of our player we will need to create a new variable for our game. This will then be used when the player presses left and right buttons. To do this create a new variable called playerSpeedVelocity and and set it to the vx value you have in your move sprite with buttons block.

You can now replace the original velocity x (vx) value with this new variable. power up speed

Create the new Variable Value

Then we will add a condition listener to see when the player is overlapping this power up. When they do we can make the power up dissappear and increase the velocity of the players speed. By increasing the value of the variable that we have just created. power up speed

Move Input Controls into a forever block

We need to do one last thing to make it possible for our player speed settings to be updated as we are playing the game. We need to move the block setting the player speed out of the on start block into a loop that is constantly being updated. If not that setting is set at the start but never updated.

power up speed

Test your Changes and Next Steps

Test your game to check that your changes have the desired behaviour and that there are no side effects. To check that you are making the most of this pattern you can ask yourself the following questions:

This Game Pattern is one of many allowing you to make improvements to your platform game and to learn coding and wider computing concepts. Find more on the Game Pattern page.

As a follow up to this maybe you can make changes to the timer for different levels.