Godot 3 Tutorial - Mobile RPG - P8: Room Transition and Adding New Enemies

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning afternoon or evening wherever and whenever you are my name is Benjamin and welcome to part well geez but what part are we on now part seven of our mobile RPG series this series is sponsored by my Kickstarter so check that out there will be a card in the video and a link in the description let's get started in this video we're going to be adding we're gonna kind of do the same thing we did with our action buttons but with enemies so that we can add more enemies to the game and add different enemy types so there will be a link in the description to a new slime enemy I have imported a new slime dot PNG and so we'll be using that to create new enemies so let's look at our current let's let's look at our current enemy and you can see the enemy has some different properties a sprite and animation for animating the enemy and we've got an attack that the enemy does right here and dealing damage and the enemy has some properties up here so a couple things we're gonna change here we need to change the weight enemies do help a little bit so that we can modify this variable with each new enemy and do it quite easily so we're going to we're going to do export int var HP and what that allows us to do is if you look at our enemy now you can see our HP variables right here and we can easily modify it as we wish right there and we're also going to add a new variable oh we can remove target as well we don't need that we can add a new variable export int far attack will set this equal to three for the rat and we'll save that and then you can see we've got a new variable over here because we exported this that allows us to modify the enemy's attack perfect now our deal damage should use our attack variable well I mean we could call this damage instead of attack set up to four because that's what we were at before and change this to damage so when the enemy deals damage it will deal whatever the damage amount that the enemy is set to so you can easily create new enemies by altering their health value and their damage value and you could also extend the enemy so that its attack does something completely different other than running the attack animation and dealing damage you could have it do whatever you wanted here but we won't worry about that for this one so we have a problem though and the problem is our enemy well this might not be that much of a problem it might be okay for this game actually let's just let's just pretend like it's not a problem and see how things go and if it is a problem we'll fix it so now that we've got our enemy set up we actually need to create a new inherited scene you inherited scene going to inherit from enemy and we're going to call this rat and we can literally just leave it the way it is we'll save this scene and save as rat okay and we'll create a new inherited scene again will inherit from enemy open will call this slime and then we'll need to alter the image here so we'll drag this line image over so now we've got our slime wondering how that compares with the rap pretty good position wise and stuff so we've got our slime and then if we click here we can change the values here so let's give the slime let's give the slime a lower attack like three but higher HP like thirty five and we can update the helpful able to to be thirty five here I don't remember if our code would update it and we'll save this slime but you could have the code update it I'm not sure so now we come back into battle and we've got our enemy it looks like we may have moved let's click on enemy let's do dot TSC in here again open up enemy that I move the animation I did we want the animation to start here there we go and we might have to note that one's already there and that one's oh that's the enemy at that one's there as well okay okay now we're now we're looking good so we're going to what is this enemy connected to here it's on enemy died is connected to battle which just hides the battle action buttons so we've still got some coupling here our enemy is connected to our battle scene still and we're gonna need to fix that so first let's remove this disconnect this signal from enemy and then we'll come into battle and we'll remove this we'll save and then our battle has access to battle units so we could technically make that connection ourselves which is what we might end up doing and I'll show you how to do that we'll see we'll see how we end up doing that but then we can remove enemy here delete nodes okay and we'll add the slime enemy instead so slime drag it drop it right here right here I want to move it up so what's up above right there turn on our mock up so we can see position wise about where we are I mean remember we could drag out the rat that's probably fine well what we probably want is an actual position that they're attached to I think we can do that so let's add a new node position to D and we'll drag this node and drop it somewhere around here we'll drag it over here call this enemy position position and then we can just delete this and drop our slime right on enemy position and it'll be positioned right there and we'll just see how how well that works although I forgot I forgot we need to hide this the mock up and then we're getting an error message that's okay invalid set text on base nil with value of type string HP label so it's having a hard time getting our HP label variable and this is because this is because we're setting our HP to something different before the label so remember how we exported this variable and then we change the slimes HP well that means it's actually setting that that variable this the slimes HP variable this HP variable before the HP label has actually been created and I think you can actually do on ready for the HP var there and that will fix it I'm not sure let's give it a try no no that doesn't seem to fix it so let's remove that and the one way to fix this is just to say if HP label is not equal null and I think this will work but I think that this means we'll have to always be sure to update the enemy's label ourselves and there is a way around this because I have figured it out I just don't remember what it is but now the slime has 35 health but should do do less damage to us and you can see it's using the same animations that our other enemy had and that's what we wanted and it deals quite a bit less damage we should heal though because mana is in short supply so the minute the minute we have enough the minute were damaged and we have enough mana we should always use it and there you go we've killed the enemy are our buttons here don't work we can't heal or use a sword although heal would actually work right now but what we're but they're not gone anymore because of our enemy situation so I'm thinking we'll have a maybe a button up here that's like enter next room or go to next room and we can hide these down here when the enemy dies so how are we going to do that because we're going to be creating a new enemy each time we enter a new room right and that new enemy will have to be able to tell battle when it has died so that battle can then properly create that show that button and so let's add it the button for entering a new room come the 2d here and we'll we'll hide our enemy enemy position and we will come to UI let's create let's create a new Center container and we'll just stretch this across here and stats panel okay well so Center containers whatever control node is inside of them will be centered so put a new button you can see it's perfectly centered now and we'll call this enter next room maybe we'll do a return here enter next we can't do a return on this kind of button apparently [Music] but that should be okay let's do our let's set our min sighs let's try 70 for our width and 13 for the height which is just a really wide but the same height as these and this button will be called next room button and we'll want to connect it to battle and this will be static it won't change we'll just hide it and show it depending on if the enemy is dead so we'll connect this one to will connect its press to battle on next room button pressed and inside of here we'll have some code like battle action buttons - oh well you could do like a transition we should probably do some sort of a transition huh and I have an idea of how we could do one pretty easily so yeah let's do that this is kind of I'm winging it here I'm winging it so who knows how this is gonna go I mean I I always wing it a little bit sometimes but this is this is major we in it so inside of our battle we'll add an animation player and inside of our UI will also add a color rect color rect and we'll make this color rect take up the entire screen so do actually don't put it inside of you I put it outside of UI but below it and then make this black this why doesn't that look black okay it is make it take up the full screen so on layout do full rect so it's taken up the entire room but then set its modulate property set that alpha value let's see yeah set the Alpha value to zero we'll call this fade and then we'll save then our animation player will create a new animation will call this fade to new room and this will take like 0.3 second 3/10 of a second maybe that seems like it would be good and in this animation we'll start off by King Wilkie the modulite property right here okay because we already set it to transparent let's do our snap at 0.05 so we can go we'll zoom in a little too so that we can go half way in between here and at this point we will set our alpha value all the way back up and we'll key and then we'll count move that's fancy never seen that and we'll come all the way to the end set our module 8 all the way back down to zero alpha and key that there you go and I'm gonna choose to set this to cubic right here I should make it a little bit smoother that's actually pretty fast we actually might want to do this longer like 0.5 and then you should be able to grab your keys and just move them do we want it to like have different speeds like maybe fade out slowly fade in quick like that I don't know it doesn't really matter you can kind of you can kind of mess around with the timing and stuff to get it however you want I think I like it to fade out a little bit slower and then fade in quick like that so I've got [Music] 0.35 and then five okay we'll set this all the way back to here save and then inside of battle we then need to get access to our animation player so on ready var animation player get access to it and then here when the next room button is pressed what we're going to do is immediately hide that button so we'll need access to it on ready of our next room button okay then we'll say next room buttoned up hide so we'll hide it and we'll say animation player dot play fade - new room and then we'll say yield animation player animation finished I think is what the signals called so then it will wait until the animation has been finished and then it will show the new battle actions sure we'll just do that and it will create a new enemy create new enemy and now creating a new enemy is going to be a function that will write and we can have it do whatever we want for now let's just print something print created enemy yay okay looking good so we still need a way to know whether our enemy has died and I think what we'll do is we'll still use the signal from the enemy we will just well we could hmm that's it that's kind of a tricky thing to do here I'm trying to come up with a good way of doing this so we'll want to show this or show the slime and we'll want to hide the next room button for now so our slime we could we could connect we could have the slime connect itself to the battle when it enters the room but we're gonna have to be careful about it so that the slime knows not to do it if the battle isn't if it's not in the actual game so if we just run the scene on its own then it doesn't break or we could have the battle try and connect to the slime but each time we create a new enemy we're gonna have to reconnect it but that seems like that should work fine so let's start with that one so on ready we're gonna say if let's see we'll do var enemy equals battle units enemy if enemy does not equal null enemy dot connect so this is how you can manually connect signals so first we're going to tell it what signal to connect which has died we're going to tell it who to connect to which is self or our example is the battle unit and then we'll tell it what function that it's going to run when that signal fires and we'll call this on enemy died ok now we have to we have to create that function so we come down here let's create a new function function underscore on enemy died and then right here we're going to we're going to do next room button dot show battle action buttons stop hide and that's it now why is this different from connecting it why is this different from connecting the the signal this way because this way is easier right this is easier it's an easier way to connect it well the reason it's different is because this way is dynamic meaning we can do it while the game is running versus doing it before the game is running and we're actually going to have to do this again when we create a new enemy so create new enemy is going to create an enemy and then we're also going to connect that enemy as well it won't look exactly like this though so we'll probably won't have anything there yet but that'll be the idea will create a new enemy and then we'll connect this signal the dyed signal again okay let's try this so sword okay so this is this is a really important thing to learn our sword why are buttons working anymore well the reason they're not working is because in Godot the way that input is handled is that it captures input on the top or the bottom most if you're looking at the scene tree over here on the bottom most control node in the scene so our fade control node takes up the entire screen right here and so it's actually capturing that click event and not letting it propagate down to everything under it and that's sometimes what you want right if you have a window with a button and that's on top of another button that the game is hiding you don't want to be able to click the button that's underneath it right but in this case it's confusing because this is invisible and so but it's still capturing the input so to fix that we can click on our fade here come to Mouse come to filter and do ignore that way this control node will ignore Mouse inputs and so then the but it won't actually capture them and the buttons will be able to work and now you can see they're working again but that's important thing to learn because it happens a lot to be honest okay boom enemy died okay it didn't work and we got an error message so what's our air calling method from signal died method not found so that means inside of battle I didn't let see on enemy died on enemy oops I did lower case here enemy died I want it to be I try to follow the same conventions that Godot uses you can see it does underscore on and the next room button is capitalized because it's actually a node and then the signal is lowercase so I did the same thing on enemy as a node died okay there we go Clara debugger we've got some we've got some warnings that we'll probably want to clean up as well okay inter next room and click on that boom fades in we enter the next room our buttons appear and it says creating enemy yeh but we didn't actually create an enemy yet so let's do that mmm how do we want to do this we want it we can let's have a list of enemies that we're gonna choose from and it can be an array and we'll export it maybe that could that could be cool let's do that so our battle node right here we're going to export and we'll do an array and we can tell it what kind of thing that we're going to export we're gonna do PAC scenes scene because that's what our tea SCN those are all PAC scenes of our enemies so the enemies equals and then we'll just do an empty array now what does that do if we click on battle we've got an enemies array over here and if we click on this we've got a size set well we only have two enemies so we'll set the size to two and then you can see that adds two values over here that we can then bring in so we'll say dragged the rat enemy in drop it there drag the slime enemy in drop it there so these are the two enemies the nice thing about this is if you add more enemies that you want it to choose from you can then add to this size and drag and drop more enemies into here and then it will automatically use those new enemies so our battle has a list of enemies now when we create a new enemy we're going to pick one of them and so we'll say let's see we'll say enemies dot shuffle so this will shuffle our enemies array during the game so that we never get the same enemy and then we'll say var enemy enemies there dot front so that will get the very first enemy in our list of the enemies and we can say oops except this is going to be uppercase enemy because it's the scene it's not the instance of the scene yet so then we'll save our enemy equals enemy dot instance and we need access to our enemy start position so let's get that up here on ready of our enemy start position equals enemy well let's just call it enemy position start position is actually a better name but and then we can say enemy has positioned dot add child enemy and we don't have to we don't have to set its position because it'll be a child of the start position so that will automatically set it into position it'll be position zero zero but it'll be zero zero relative to this enemy position so it'll be created right where we want it let me explain that better if you look at the transform of our slime it's zero zero that's because this position is relative to the enemy's position which is 46:29 so but the actual node is still zero zero and when we create it it'll automatically put it at zero zero so we don't have to move it now we need to remember to connect our signal so enemy dot connect what signal died to who self which is the battle what's the function underscore on underscore enemy underscore died and there we go save and I think we show the battle actions right so we should be good to go let's run this got our enemy let's kill him okay inter next room oh we got the rat this time it doesn't reset our action points we might want to reset the action points what do you guys think I think it makes sense to reset the action points so let's let's do that we'll say our player stats equals battle units dot player stats player stats dot action points equals player stats dot max action points and the other thing you'll notice is that it's actually it will actually always choose the same order of enemies and so if you want to fix that you'll in your ready function you want to call randomize which will randomize your seed so that it doesn't choose the same order of enemies every time sword sword sword so oops dang it heal that was you should always heal if you can heal sword sword inter next room okay we got Anna at sword sword mmm it didn't seem to reset our action points did it did you guys I wasn't paying attention it didn't seem to work though let's try this one more time okay action points are it to enter next room it's not resetting our action points did I not save it must be an order thing let's actually move this here to be under right here when we show our new battle actions so we'll move the we'll move the part where we set the action points and we'll do it right before we show the new battle actions and create the new enemy sword heel sword sword sword inter next room there we go action points are reset properly sword heal sword gotta use sword everytime that time we can heal in turn ex room there we go and we've got the basics for our RPG dungeon there's one more video I want to make though I realized I want to make a video that allows you to hover over certain elements and have the information about them displayed down here do you guys see in this glitch we can just continue using it even with zero action points and we've got a bug here let's see resumed after yield but class instance is gone so that is probably what is that caused by resumed after yield but class instances gone well great this is what happens when you wing it what this what this error message means is that one of our one of our yields like this yield for example although it's likely not this one is resuming but then the enemy is no longer there and so my guess is that it's actually it actually has to do with one of the enemy animations which isn't completing maybe the hour shake one doesn't get used if the enemies dead right but it's possible that the enemy that the shake animation is already playing when we attack again so we're attacking so quickly like that but on the right when we kill it so let me show you what I mean oh I messed up it won't work this time now let me let me fix it okay one two okay so this should be perfect okay so if I attack it and it starts the animation and then I immediately attack it again it will die before the animation completes and it will break the game see watch now we can just an attack oh well maybe I'm wrong I thought that was the problem uh-huh but this time it is broken so I'll have to figure out exactly what's going on there and well I wanted to do one more video anyways so now we're for sure gonna do one more video so I'll do a video that fixes this air this bug in the code which has to do with our yield I'm 100% certain it has to do with yield I thought it was with the shake but maybe it's with the attack maybe something's going wrong with attack I don't know well either way I'll figure it out we'll make a video to clean that up and then add a method for hovering over stuff to get information about it like what the sword does what he'll does what enemies do and that way we're actually using this UI down here that we've set up so thank you guys so much for watching this video hopefully you enjoyed it and learn something if you did give it a thumbs up and I will see you all in the next video
Info
Channel: HeartBeast
Views: 10,423
Rating: undefined out of 5
Keywords: Godot Engine, Godot 3, Godot Tutorial, Godot Game Engine, Godot 3 Engine, Godot Engine 3, Tutorial, Make Games, gdscript, Open Source, godot, game development, game engine, godot tutorial, godot 3, open source, godot engine 3, pixelart, pixel-art, lets pixel, pixel art, Pixelart
Id: KSi35Gh6SL0
Channel Id: undefined
Length: 38min 22sec (2302 seconds)
Published: Fri Aug 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.