GameMaker: Studio - Power Ups tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] alright guys welcome back today we're going to be looking at temporary power-ups in game maker studio now I'm going to be following on from the tutorial I did on platformers but this method I'm using is going to be pretty Universal and the concepts that I'm going to be teaching you should be helpful no matter what genre of game you're working with in terms of applying a temporary effect to a player or something else in your game so I've added a few new elements since we left off with our tutorial last time as always this project will be available for download from the description but let's just take a look at what's new so as you'll see there's this little blue square sitting over here this is object underscore obj underscore powerup that's going to be our object that we're going to collide with and it's going to give us a powerup we're going to increase our jump speed for roughly about five seconds so all I've done is I've added a new sprite for the powerup a new object for the powerup and also a second sprite for our player which I've called SPR underscore player underscore B where the player is blue so whenever the player is affected by this power we're going to turn the play of blue just so that you know that the power of is active so the first thing we're going to do is we're going to go into our player object obj underscore player and in the create event where we established our variables and previous episode on platformers you'll see at the moment we have jump speed set to seven at the start of the game now what we're gonna do is simply change the structure of this a little bit to allow us to add a powerup into the game that will change that jump speed without as having to mess about too much in the step event or change anything else that's going on this is why it's important to use variables to refer to numbers and not simply use hard numbers in the code where we mechanically apply our jump and the step refer to them as variables because it gives us the freedom to do systems like this which should become clear in a moment so I'm gonna go ahead and get rid of this gem speed line here now obviously we still meet that but first I'm gonna establish two new variables and establish jump speed underscore normal equals seven which is what we had before and jump speed underscore powder up which we're set equal to something bigger we'll go with ten so then I'm gonna type a jump speed which is our original variable I'm gonna just set it to be jump speed underscore normal now as you can see I mean you might think it's redundant me doing that why not just set that to seven why do I need that to be referring to that well it just makes it easier at this point so now if I ever want to change our normal drum speed all I have to do is go into the create event on one player and change this one number and it will ricochet throughout the rest of the code because that drum speed picks up that normal and then that normal that variable and then that variable is picked up later in our step event where we're handling all of our actual movement code you see here was - gem speed is taking whatever that number is so means we don't have to mess with the nitty-gritty that we've already sold in all the rest of our mechanical code I mean just in our initialize variables we can just play around with the settings in here it makes it much easier when you're trying to tweak sayings and things like that variables totally underrated and now what you'll see is that we now that we have this gem speed underscore power up you can imagine all we need to do is whenever we pick up a powerup or do anything all we need to do is set jump speed to be equal to that for a while and then we only have to change that one number to affect what that is so that's for exactly what we're going to do now so you can go ahead and close this and close this because now the next thing we're going to do is sort of our actual power of object so if we edit our powerup object obj underscore powerup and I'm going to add an event we're going to add the event when we have a collision with the player see this is when we actually want to use the collision event when we actually want to have a real collision when we want to be overlapping with something so when we collide with the player go ahead and drag in and code object what we're gonna do is we're going to apply an effect to the player so what we want to do is say with Open bracket obj underscore player again I Center and then just open and close pair of curly braces now inside these braces here what's going to happen is whatever code we put into here is going to run as if it were running from the player object and not this object so allows us to affect other objects from the events of other objects so when you know the player collides with this powerup with object player we're just gonna say jump speed not jump speed jump speed equals and you'll notice an important thing to remember inside well with statement as well is there anything that you do in here because it's running as if it were running from this object it has access to all of that objects variables and importantly it doesn't have accessed any variables you've declared like here or above it and you know outside of that inside the powerup object it only has access inside of here to the variables that this object knows about just something to be aware of so we want to set jump speed to be equal to jump speed underscore powerup and then we want to set alarm open square bracket 0 close right bracket to equal about 300 now the alarm is going to be what turns our jumps be back to normal so this is the temporary part of our temporary power up we're going to set up an alarm and then when it goes off we're gonna sell jump speed to be normal again and we're sending it to 300 so 300 frames from now alarm zero will be triggered and that's an event that will go off inside object player which will self in a moment 300 frames at 60 frames a second is about 5 seconds so the only other thing we needed to do was to set our player sprite to be our new a new player sprite the one that's affected by the power of so I'm gonna say sprite underscore index equals SPR underscore player underscore B semicolon so at the moment we've applied pretty much a permanent change we've set jump speed equals gym speed power up and sprite index equals this and we've set an alarm but that alarm doesn't do anything yet so we've made all the changes and we've given that power of 1 player it'll increase his jump speed to whatever jumps B power was which I think we set to 10 so it'll go from 7 to 10 and then because we don't want to like you can do in doing this continuously and we don't want to keep setting this alarm continuously otherwise it'll never go off while we're collided with the power up we want to actually get rid of this object after we've done that collision so in that type of instance destroy outside of this with bracket so that will destroy the power of object object after we've collided with it go ahead and close that now if we open up the player object again in the event section we want to add event alarm alarm zero because that's the alarm we referenced you can have up to 11 alarm events per object but we only need alarms zero for this one again dragon a dragon a code action so now when our time is up all we need to do is basically set our code to be normally our jump speed to be normal again so we type jump speed equals jump speed underscore normal which was the variable we set up in the first place and then sprite underscore index equals SPR underscore player and then that'll set everything back to how it was before and that's really all there is to it so now hopefully nothing goes wrong you should be able to demonstrate I come up here and I jump onto this powerup you can see we've turned blue and we can jump way higher than we jumped before and then that runs off after about five seconds and now we're jumping the same height we used to jump and the powerup is gone as well so yeah that's that that's how to create a temporary power up effect in either a platformer or pretty much any game so yeah I hope that was useful and I'll catch you next time see you guys
Info
Channel: Shaun Spalding
Views: 192,806
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Game Development, Indie Games, Indie, Games, Tutorial, Information, Learning, Tutorial Series, Game Maker Studio, Steam, iOS, Android, HTML5, Windows, Making Games, How to make games, Basics
Id: Dmh4yvKzE34
Channel Id: undefined
Length: 9min 9sec (549 seconds)
Published: Sun Mar 23 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.