Gamemaker Studio: 5 Bullet Hell Attacks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hi, this video features the 3 attacks from my previous video but now also with 2 new attacks, (homing and lane) plus as another user suggested: Instance Pooling. I would be open to pushing this code into a state machine for users to learn about if that's interesting to anyone. Thanks!

👍︎︎ 3 👤︎︎ u/CorrectBattle 📅︎︎ Dec 08 2021 🗫︎ replies

Great job, thanks for sharing. Have you done any frame tests on the speed comparison when using stacks and not using them to recycle the bullets?

Also as feedback, your mic is a little louder than last one, but still fairly soft imho.

👍︎︎ 2 👤︎︎ u/Slyddar 📅︎︎ Dec 08 2021 🗫︎ replies
Captions
hello game maker dev i'll be showing you how to make a boss that has these bullet hell attacks here today these attacks are all set to the number keys and can be activated manually but if you guys would like tell me about in the comments if you would like me to set up a state machine so that way the boss will act on its own i'll be setting up all this in a brand new project so that way you guys can follow along and we'll also be talking about the instance pulling as you can see up here in the corner so that way you can recycle your bullets instead of continuously creating or destroying them so here in my project i've already got my sprites set up you can use whatever sprites you would like i'm going to start with the boss object and we're just going to initialize the create event so we can get some variables down namely our ds stack which we'll be using to recycle our bullets stacks are like a tower you can put things into them and then you can only take off the top and you'll see more about how that works in a bit we're also going to put down a bullets created variable this variable is not really important it's just there so that way we can see how many we've made and then we're going to have two more variables called spin shooting and lane shooting these will be related to our attacks later on go ahead and set the sprite for the boss and then we're going to set up a few variables for the bullet as well namely just their uh homing variable that's it for that one so we're going to be creating an awful lot of bullets here in this game and we're going to need a script so that way we're not dirtying up our code with a lot of different random functions all over the place so we're going to create a function right off the bat called create bullet and this create bullet function is going to take a few arguments namely the position we want the ball to be at we also want the direction the bullet is going to go the speed the bullet's going to travel out and whether we want that bullet to home end to the target or not so normally whenever you would create bullets in your bullet hell you would just destroy slash create them whenever they would you know go off the screen or just stop being used but here we're going to work with our ds stack so that way we're recycling our bullets instead of destroying them so we're going to first check if our ds stack is empty which means that there are no bullets currently in the pool that we can recycle which means we have to create a new one so we're going to say bullets created plus plus just so we can keep a check and then we're going to save our bullet equals instance create layer we want it to be created the xx and yy that we pass in on the instances layer and the other bullet object so since we have set the id given back by instance create layer into this variable bullet we can now alter that variable bullet by saying with bullet we're going to change its direction to the variable that we passed in as well as its speed and then we're going to tell it whether it's a homing bullet or not so if our ds stack is not empty as in we have bullets in our tower that we can pull out we're going to say else our bullet we're going to pull a bullet from our tower and you'll see in a minute once we get around to our bullet code deactivate our bullets and then put them into the stack so we'll have to pull them out by taking their id here and then we're going to activate them again because whenever we deactivate them later on we don't want them to be using up any of our memory we're doing this to save our memory so we're going to once again say with bullet and this bullet is going to be deactivated whenever they go off the screen or interact with the player so we're going to reset their movement back to the x and y coordinates that we pass in and then we also need to say direction equals der speed equals speed and homing equals homan close out our brackets and this is our bullet script this will allow us to utilize our ds stack so that way we're creating bullets whenever we don't have bullets to recycle and then recycling them if we do have bullets in the pool so we're going to go up here to our bullet script real quick and we're going to set up the interaction with the ds stack so we're going to write image blend equals c white here just because this will be used with some later code and that will prevent us from having a bug i'll explain it a bit later so df stack push global dot bullet id or bullet pool and then we're going to push our id so in tower we're going to have like a bunch of different bullets like we'll have one two three four and maybe these are their ids so if five went into the there first and that's his id we would only be able to pull out one using our script down here by using pop so that will pull off one and then we would have access to two three four and five so we're recycling our bullets by pushing their ids into the stack and then pulling them off we're also going to deactivate it so that way it is not being used by the memory and that is it for our bullet right now which means we can move on to the more interesting bit of setting up the attacks so we're going to first set up a variable here at the top for the player's directions that way we can reuse this variable multiple times we're going to call this peter and then point direction x y o player dot x and notice we don't have our player object yet we're going to go ahead and create that real quick that way our code looks pretty there we go and then we're going to start by setting up the spray attack so if keyboard chuck board or it allows us to get the id of the key that you press on your keyboard here create bullet x y i random 360. i random three or i end up giving you a value between the number that you give it in zero only whole values though so five for the speed and then zero because this won't be a homing bullet if you want to change it to be homing then by all means go ahead but also that homing isn't set up yet so be careful about running this because you'll get an error we're also going to set up the fan attack here we're going to have two variables related to this one is the fan size and one is the fan spread if check we're gonna use pressed here so that way we don't send out a stream of bullets two and now we're going to use a four loop here so four of our i equals the way that you would originally set this up to get this fan effect is you would say negative two and then i less than three i plus plus and the reason for this is i'll show you because when we use create bullet here and create it at our location and we say uh peter plus i times uh 15 5 and 0. so we're going to introduce the fan size and fan spread here but um between negative two and two you would have a difference of five and we're using the negative values in order to get backwards values uh on our angle to where we're shooting at the player but we're going to replace these with our fan size and spreads that way we can easily alter them we're going to do that by using 4 which rounds down your value which will give us fan size divided by 2 which will be 2.5 which gets rounded down to 2. and we're going to use the opposite over here seal which rounds up so fan size divided by 2 gives you 2.5 which rounds up to 3. so we end up with the same thing here we're going to replace our degrees here with fan spread and then we're going to close this out so that's our spray attack and our fan attack both done here oh i'm missing a value here i know if i just have an extra comma next we're going to set up the spin attack and this one will utilize our spin shooting variable so if they press the 3 key to activate the spin shooting we're going to set spin shooting to 1 so that way we can start utilizing that variable and then if spin shooting oops is greater than zero we're going to increment spin shooting because this variable is going to be used as our direction so whereas we start at zero we're going to be adding five to it so that way we go around in a full circle we're going to create bullet x y spin shooting 5 and 0 because we don't want to home and then we're going to at the end of our line where our cursor is we're going to hit control d twice so that way we can make that effect that you saw in the preview and we're going to do that by subtracting 15 and then subtracting 30 so that way the angles are slightly different then we need to catch the spin shooting variable once it finishes its rotation so if it's greater than 360 we're going to set spin shooting back to zero and that's our spin attack there next we're going to set up the homing attack and for this we'll have to write a bit of code in the bullet but first we're just going to go ahead and set this up it's going to be exactly the same as the spray code so we're going to pull the code from up here we're going to make this a 4 and then we're also going to use i random range here instead of i random which will allow us to set the values that we want to be between so between 180 and 360. we're going to set it to 1 because i think the effect that it has when coming out of the low speed is the best and then we're going to set home into one as well so now we need to go to our bullet back and set up the homing effect so here we're going to say if homing does not equal zero and homing is less than 99 we're going to increment homing and i know this looks weird but this is how i've set it up so that way we can also add a colored effect to the bullet to show when it's going to be fired at the player so if homing equals 99 we're going to catch it and say homing plus plus and then we're going to set the direction equal to the point direction of the player so that way after homing fills up so it gives the player time to react to the bullets it'll fire itself at them and we're going to use a speed of 8. and here's where the homing checks come in because we're going to say if homing does not equal zero we're going to use image blends to change the color of the bullet so that way we can make it more apparent when the bullet's going to be launched we're going to do this by writing merge color c white and c red so this will merge two colors um based on the amount that you put in the last bit and we're going to do homing over 100 so that way as homing reaches 100 it will start to be closer to 1 and your value here would be between 0 and 1 based on how close you want to be to white or red and that's it for the homing code it's pretty simple the reason here also for this image blend equals c white like i said earlier is so that whenever the bullet goes off the screen you don't want it to stay red and then come out red when it gets recycled because that would just look weird so lastly we're going to set up the lane attack so that way we can trap the player in an area and force them to move more carefully this one's got a lot going on with it so if you need to pause the video to catch up don't worry about that board five and just like our spin shooting we're gonna set lane shooting to one and then we're gonna introduce a few variables here we're going to say lane size this is how uh much of a degree of radius you want on either side of the player so you can make this smaller or bigger to give them less or more room and i'm going to say lane timer this is how long you want them to do this for and remember if your room is moving at 30 frames per second or your room speed is 30 this would technically be 6 seconds because you divided by it so we're going to say if lane shooting is greater than zero we're going to increment lane shooting and then we're going to say var lane clamp equals clamp 90 minus lane shooting lane size and 90. so we're going to use this clamp here in a second to make it to where it will not go as close to the player as lane size so as lane shooting goes up we're going to have a 90 degree uh area between the player and the bullets but it'll be subtracted by lane shooting as it increments and then we want our minimum to be the lean size but we also want our maximum to be 90. we're going to add that to our direction here in a second so create bullet x y our direction minus the lane clamp and then speed of tin and then not homing and we want a high speed that way it cuts off the player and they can't get past it we're going to create a second one here because it would only have one line if you did it on one side and we're going to add the lane clamp so that way it cuts them off on the other side and then we're going to catch it so if lane is shooting is greater than or equal to lane timer plane shooting equals zero so that way we can reset and that is our lane shooting so now that we have all these set up we're going to go ahead and run this just so that way i can make sure it's working for you guys oh oh that's a beginner's mistake i forgot to put the uh instances in the room there we go so let's see the spray a fan the spin the homing bullets see i like the one speed coming out so they're like this slow attack then they fill up and as they get to their full red they launch at you and then the lane attack and you can combine these as well and if you guys would like i can also show you um how to set up a state machine so that way the boss performs all these actions by itself rather than you having to press the keys so i'm going to make sure we have cleaned everything up here and to do that we need to add one more thing here we're going to say if well clean up and we're going to attach this to a keyboard check as well even though this is something that should be run whenever the character is destroyed so we're going to say nine so that way it's out of the way so the reason for this is in your ds stack that has all your recycled bullets if you were to destroy this boss object as in like you defeated it and you destroy it all the bullets that are stored in the stack are not going to be destroyed so you need to clean the stack out before the boss is destroyed and so you would normally put this code in the destroy event so that way you don't have bullets hanging around that are just not going to be doing anything and to do that we're going to say var stack size equals the stack size of the pool and then we're going to run a for loop so that way we can go through the entire one or the entire stack a less than stack size can't type right now and a plus plus bar destroy equals ds stack pop so we can pull our bullets out we're going to subtract from bullets created and then we're going to destroy the instance that we pulled and that's it that'll empty your ds stack for you and then we just have one final thing that we want to do here and that's in our destroy event we want to also get rid of the ds stack dstack destroy so global dot bullet pool so optimally you would want to run this code here i put it under keyboard effects that way you can do it without destroying the boss but you would run this code so that way you'd clean out your stack and then you would destroy the stack so that way it's no longer taking up your memory and just so you guys um have this as well so that way you can see how many bullets you've created and destroyed we're also going to set up that draw code we're going to need to draw self so that way we can still see the boss and then draw text we're going to set it at 2020 and let's created plus string so that'll show us how many bolts we've made and then we'll do one more at 40. and then what's in pool stack size global.pool there we go oop what am i missing here i'm missing a parenthesis i think right yeah all right and let's run that one more time just that way we can see the finished bit see now we have our bullets created and our bullets and pool appear and as we shoot we'll see that the bullets and pool go up to match the bolts created which means all the bullets on the outside here are now deactivated and thus not taking up memory but whenever we start attacking again it'll use those bullets first recycling them that way we're not creating and destroying bullets hundreds of times a second that'll be it for this video thanks for watching through if you would like to see a state machine based on this boss that way the attacks can come out on their own let me know in the comments or give me a like and i'll see you guys next time
Info
Channel: Critical Battle
Views: 263
Rating: undefined out of 5
Keywords: Gamemaker, GameMaker Studio, Coding, Tutorial, Bullets, Bullet hell, Instance Pooling, gms2, gms, boss, player, homing, bullet hell, gamemaker studio, game maker studio
Id: N7YQVGzMu1k
Channel Id: undefined
Length: 21min 45sec (1305 seconds)
Published: Wed Dec 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.