Gamemaker DND Platformer Tutorial - #6 Enemies

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good a gamer's if you're interested in making a detailed platformer just like this one with in game maker using drag and drop then keep watching [Music] g'day gamers now we've already done quite a bit of setup with our character but set up the movement we've added collisions we've added the sprites and we've changed our character to use States now that setup is actually going to start paying dividends for us because we want to add an enemy and adding an enemy now is actually a lot simpler because we have that setup or gun but let's bring in the sprites for our enemy firstly I want to duplicate the player idle sprite and we're going to call this s underscore enemy underscore Idol now the sprites are in the description what we're looking for is the idol strip let us drag that over top the mask for the enemy we're gonna leave the left at 13 I'm gonna put the top at 18 and the right at 34 and the bottom at 62 so it's down at his feet there I'm sure your origin is set to middle Center and let's duplicate that two more times and we want to call this one s underscore enemy underscore walk and then we need an s underscore enemy underscore dead so let's just group those together down here so let's just bring the sprites in now for those there's a dead sprite let's drag that in for the walk let's bring that one in as well now I'm just going to set the speed of the walk to be 10 and for the dead set that to be 10 as well and we'll just change the origin here to be 20 and 26 and that way because this is a line to the left it'll actually be in the center when we swap to that sprite so we can close it down let's go and create an enemy layer but just under player let's make a new layer here and we'll just call this enemy we're just going to make a copy of our player object because we have all the states and everything already set so it's going to make it much easier to put an enemy in the game so let's duplicate the player and we'll call it i underscore enemy want to change the sprite set it to the idle sprite for the enemy and will also change the masks to be the idle sprite of the enemy now I've created a dead sprite so we actually need a state that is for when player is dead or the enemy is dead as well so let's go to our entity and let's make a new variable definition and it's going to be SPR underscore dead and for the sprite I'm just going to put the players idle because that exists we don't have a player dead at the moment so we'll just use the idle let's go back to our enemy and let's look at our variable definitions which we inherit from the entity so the ones here we won't actually want to change actually just go back to entity and we'll just drag this one up quickly so it's we built the others and you know enemy then it'll appear in the right spot so instead of player I'll let's edit that and we want to have enemy idle instead of player walk we want to have enemy walk we don't have an heir at the moment for the enemy but instead of playeridle for the dead we want to have enemy dead so now that we've assigned the sprites to those variables they will appear when we run the antium script we don't have to do anything else for that now once again all that setup that we did previously is now going to pay dividends for us now we also need to change a state I'm going to just put this state as enemy state so es dot walk and for the walk speed I'm going to set it at 1.2 now we need to create the enums for the enemy state now you could use the same state as the player but I like to keep them separate so they can have different things even though they will have a lot of similar things I like to actually do it separately but let's go to our game a copy of this paste it down here and is it going to be out enemy States I'm gonna call it es enemy States and the moment we just have an idle walk and a dead back to enemy okay so in the step event where we are running those states let's have a look at this the we just want to change our case here instead of PS Idol we're going to say yes dot Idol so standing for enemy states we have to air stop walk and actually don't have an air state so we can delete this one the moment we just have a walk and I'm probably not even going to use the idol for now actually so we're just going to focus on the walk so for the enemy we're actually not getting input because that we're not receiving any keyboard commands but let's just make it simple and we'll set a variable instead let's set the HSP of the enemy directly and we'll just set it to walk speed x facing but if the facing is one then we're going to have a HSP of 1.2 if the facing is negative one then it's going to be minus 1.2 metal move us to the left or the right we don't need our get input will still do calc movement because that will calculate the slowdown as well as gravity now we don't need to check around because we're not jumping I'm not going to change states for now so I'm just going to take the check state out we're not jumping so we can take out a check jump and we're left with our collision and our animation so this will now enable the enemy to walk left or right but there's no way for the enemy to turn around at the moment they'll just hit a wall and I'll just keep walking into it so when the enemy runs into a wall the collision script will set the HSP to be zero but what we want to do is have the enemy change direction when they hit a wall so we need to add a test that tests the see if our HSP is zero and if it is we need to change direction so let's drag across a check and we'll say if our HSP is equal to zero well then we must have hit a wall so now let's change our direction and we can do that by assigning the facing value to be a value of facing x minus one and that means that if facing is one where timesing it by minus one so facing will become minus 1 if facing is minus 1 it'll then become 1 so essentially we're changing the direction of the enemy I have got an idol case here but I'm actually not going to use that so I'm going to delete it and we're just going to leave one walk case for the enemy now because we're using es as our enum we need to go into the annum script and in here we're referring to the enum PS so we need an animus crypted actually works for our enemy and it's a really good idea to separate the adding script from the enemy and the player because it gives you more freedom if you need to make changes to their particular animation state so let's duplicate the antium script and I'll just call this a name underscore enemy and all we need to do here is we don't have an idle state so we can remove that and we don't have an air state so remove that and the constant we're checking this time is es dot walk but now that we have the new enemy enemy we can just go back to our enemy and make sure that we are using that particular script but here instead of an IAM we just want to have a name enemy great so now let's go and add the enemy to the room Oh drag in the enemy we can place them anyway here let's put it down here so they turn left and right and if you want to click on the player because I'm on a different layer at the moment I can't click on the player but you can hold down P or you can press the little button up here which lets you select from any layer then you can select an object from another layer but to push around on that now and see what happens great so we have an enemy that moves and they turn when they hit the wall now I'm sure you agree there wasn't a lot of setup to get an enemy to do that because we had already done all the setup before and it's also really functional because we can add different enemy States now we don't have a way for the enemy to die yet and move into their dead state but that is something that we can look at adding in a later tutorial now one thing you might notice is that the enemy will start walking the opposite direction to which way they are facing and that's because H SP is equal to zero when the enemy is created so we're instantly swapping they're facing direction but I had more control over which way they're moving what you could do is if I go back to our enemy and if you double-click on it and go to the creation code now in here this code will run when that particular enemy gets created so we can just set a variable here and we can set which way we want facing to be when this character is created now it's going to be the opposite to which way you want them to move so if I put a facing value of 1 it'll start moving to the left if I put a facing those minus 1 it'll move to the right and that's because if you go back to look at our enemies code we are changing it when HSP is 0 so this one's being set to minus 1 it means it's going to move to the right so if I place this one here and then I make a copy of it copy paste and put another one and I make this one equal with their creation code to 1 and close that so now this one will move to the left and this one will move to the right when we run the game and there we go so we have no way for them to stop they just fall off but that gives you greater control over how they start the game at least so that's all we're doing for this tutorial but before I go I want to enter in my game maker course it's currently the highest rated course on udemy for game maker there's a discount coupon code in the description I suggest you go give it a try it's a really cool course you can use the trial version of game maker as well I make adjustments in the course to allow the trial version to work so the course is getting some great reviews if you're interested in looking at game maker a little deeper and start to explore GML then I suggest you take a look but thanks for joining me I'll talk to you next time [Music]
Info
Channel: Slyddar
Views: 13,823
Rating: undefined out of 5
Keywords: gamemaker, drag and drop, dnd, collision, platformer, platform, make game, jump on head, enemy ai, gms2, drag n drop, drag, drop, dragndrop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms, advanced, learn, vertical
Id: _HSn4sySzYU
Channel Id: undefined
Length: 11min 39sec (699 seconds)
Published: Mon May 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.