The process of doing this is relatively simple.
1. Create your variables
You will need 6 total for this example. You will need:
- One that contains the normal movement speed
- One that contains the normal movement speed as a negative
- One that contains the boosted movement speed
- One that contains the boosted movement speed as a negative
- One that is empty that can contain either of the positive speeds
- One that is empty that can contain either of the negative speeds
- A boolean variable (true or false switch) that we can use to trigger the power up
2. Create a block of code similar to these in your main characters behavior. Note that you will have to recreate this for every movement direction.
3. Add another block to your character that looks like this.
What this block does is determine if the boolean variable $speedboost has been switched to true. If the variable becomes true, it changes the $speed variable for normal to godspeed. In this block I kept the normal movement speed at 10, and the boosted speed at 20. So when you run over the power up it doubles your movement speed. The "do after" block at the end makes it so that after ten seconds all of the movement speeds revert back to normal speed. Pretty clever!
4. Create a character that will be your power up item.
Edit it's behavior to include a block like this:
(Note: Ignore the red flags in this block. Stencyl threw those up because I didn't add animations to this actor before creating the behaviors.)
You may also want to add something to that block that kills the actor and removes it from the screen. I had planned to do that for this example but it slipped my mind. If anyone is unsure how to do that, just let me know in the comments and I'll cover it in another post.
That's all you need to do to change your movement speed without first calculating directions. Play around with those blocks and see what other kinds of cool things you can achieve with this principle.
If this blog helps you out, or you just enjoy reading it, consider subscribing to my feed burner so you get immediate updates when this blog is updated. I am always looking for suggestions on what to post next that will everyone will get the most value from, so if there is anything in particular that you would like to me to explain, please let me know in the comments and I'll cover it. Thanks for reading!
How can I do it so that the speed boost works more like a x2, x3 or x5 icon when pressed?
ReplyDelete