Gamemaker DND Platformer Tutorial - #9 Damaging Enemies

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you're interested in making a detailed platformer just like this one with in game maker using drag-and-drop then keep watching good a gamers if you've been following along your game is coming along really well we have an enemy but we have no way for the player to interact with the enemy yet so let's give the player the ability to jump on the enemy's head and deal damage to them but when you have two objects that you need an interaction with you can create a collision event between them but let's go to the player and let's create a collision event between the player and the enemy so the first thing I want to do is drag in an if statement and I want to make sure that the enemy is not already dead because we don't want any interaction if the enemy is already dead so we need to check the state of the enemy and make sure it's not in a dead state so if I write the state here this variable that is checking is the state variable of the object that is running it which is the player but I want to check the state of the enemy and when you're in a collision event to check the other instances variables you can use the word other but I'm going to say other state and that refers to the enemy's state variable so if we look at the state variable the enemy and if it is not equal to the dead state and we haven't created this as yet and it's going to be enemy state so es dot dead so if the enemy is not dead then we want to have some sort of interaction with the player so let's have another check here let's go and have a look quickly at the enemy here's the current mask for the enemy now we want to be able to jump on the enemy's head to deal damage so we need to look at say this section above and say if the player has interacted with this section up here well then the player has jumped on the enemy's head so the limits of the mask all the way around the outside are called the B box values so this is B box top B box right B box bottom and B box left and we can refer to these to know if the players landed up the top up here let's go back to the player and let's look at the variable of the player the B box bottom and if the play is B box bottom if that is greater then the enemy's B box top so over dot B box top let's say plus 10 so other B box top plus 10 so we go back to the enemy this is the B box top and we're doing plus 10 and when we plus we actually go down in game maker so plus 10 is about down here somewhere so if the players B box bottom is anywhere above this line well then we interacted with the enemy's head so back again the player so if that's true that means the player did interact with the enemy's head but we also want to make sure that the player is moving down but they're actually falling on the enemy's head and not just going upwards so how do we know if we're going down well our vsp is going to be greater than zero now that's the case we're actually hitting the enemy in the head let's set our vsp and close this down we'll set our vspeed to be minus jump speed so I'll actually get a jump and bounce off the enemy but that's the player sorted now what do we need to do to the enemy if this happens let's go up a little bit well first we need to change them into the dead State and when they're in the dead state they're going to play this animation which is of them dying but one of the first things we do is we need to put them back to their first image index so that they can play the animation correctly because when you change States it doesn't reset the image index you've got to do that ourselves but let's assign an instance variable and we want to change the image index and we'll put it back to zero and we also want to make sure they're not walking anymore because we want them to stop and then fall over but let's also assign the HSP to be zero as well the last thing we need to do is we need to change their state we need to put them into that dead state so let's change their state variable to enemy state dead but these three changes are all related to the enemy they're not related to the player and as I've got them there now they will all change the players variables because we're not using other I didn't use other and the reason I didn't use other is I wanted to show you something else you can use so if we go here there's a apply to code block we're going to drag it over and just put it below the VSP assign and what you can do with this is apply multiple changes to what another instance but if we change it here and say it applies to other and then we drag all these under those changes now will happen for the uber which is the enemy but it's really handy so you don't have to use multiple others you can just do and apply to and it applies to the other for everything here all right so let's go and create this dead state for the enemy so let's go to the enemy and let's go to their step event at the moment we only have one case for our state and that's enemy state dot walk but let's create another case and this one's going to be enemy state dot dead want to do in this state well what's going to happen is we're changing to this and when we press play the enemies falling down but what happens is they will fall down and then they will get back up and they'll fall down and the animation will continue to play so we need a way to make sure that the animation stops after it plays once but let's have a look firstly at the image index so we need to monitor the image index value and when it is equal to the final image index for that sprite then we need to stop our image speed so that it stops animating now let's look at our image index and we need to know when it's greater than the final image index value now another variable you can use is image underscore number and that is the number of images in the sprite now image number will always be one more than how many sub images you have in your sprite so if your sprite has three sub images or frames the image index values are 0 1 & 2 but we have 3 images in total and image number will be equal to 3 so because it's one more if our image index is greater than image number minus one then we are on the last frame we are on the final frame of that animation and if that's the case what we want to do is set our image speed to be zero an image speed is the speed our animation is playing so setting it to 0 means it stops playing now we still need to have our collision check and our animation check because we're moving into the dead state and we need to know which sprite to use so I'm gonna take this one and this one which is the collision and the animation I'm gonna copy those and I'm gonna paste them down below the F so they don't have to happen if the if happens they happen all the time now the last thing to do is for our animation for the enemy we actually don't have a state for dead so let's go to our scripts let's go to our animation enemy let's add a case for the s dead enemy state start dead do is assign the instance variable for sprite and we want to assign it to our SPR underscore dead which is just our dead sprite now we're also checking facing which we still want to keep doing is I'm going to copy and paste that as well we want to make sure we're checking the facing direction so that we can die on the correct orientation I'm gonna test the game now so first we want to make sure when we interact with them nothing happens great it's only when we jump on their head so what about if we jump underneath them that doesn't happen either because those VSP is not greater than zero so let's jump on their head and they get affected then so the same for this guy when we are not interacting with them from the top Kathy actually happens so we don't take any damage or anything at the moment but when we hit them from the top they fall down and their animation stops that's looking great now if there are other things you want to see in drag and drop please leave a comment down below make sure you like and subscribe because it helps me to make content like this now over in my game maker course on udemy I add a sword and a shield and the player has a lot more interaction with the enemies the course is currently the highest rated game maker to course on udemy if that's something you're interested in check out the coupon code down in the description you get over 90% off from the course thanks for joining me I'll talk to you next time [Music]
Info
Channel: Slyddar
Views: 7,364
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, parallax background, parallax, enemy, damage, kill, hurt, mario, jump
Id: HUZGYJ8LRlA
Channel Id: undefined
Length: 9min 48sec (588 seconds)
Published: Tue May 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.