[5] GameMaker Studio 2: XCOM 05 Game Tutorial Series - Adding and Removing Floors/Levels

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so right now we can change the floor decoration west wall and north wall and also change the biome of a map but we also want to be able to add or remove floor levels so we're gonna do that now there's a couple of things we need to change first though inside obj controller in the create event we have a new variable or a new macro called max levels set to 12 all this means is that we're not going to allow ourselves to make more than well we're not going to make anything higher than 12 levels basically just assuming as well there we go it's better then if we go into the create event of the map editor zoom back out that's okay so um you can see this is this full loop and this line here line 13 and line 11. we'll be using this to create the floor grid before and filling it with lists well i think i mentioned before that we are going to be using a script for this kind of thing and today is when we're going to start using that because every time we add a floor to our map um we might as well just use a script to do it and if we can use a script then we can use it in the create event as well uh we do want to keep vcells we don't need any of this stuff apart from v cells because v cells is used by the camera creation code that's further down we also have a new variable called current level this is going to track which level we are working on um we have a list this list is going to hold all of the floor grids for the current map so um every map's going to have a floor grid for every level and current map list holds those floor grids basically and here is the script that was talking about i'm going to make that in a minute uh we're going to pass it the map list and the current level so what level do we want to make this floor on so these lines are new so we're going to the script uh let me just change that so at the top we have the name the function the script we're passing it the map list and current level to make sure you got these four lines down then we're setting uh h cells and v cells to 10 for now in the future we're going to use this this code which is why i didn't delete it but for now we're going to set it to 10 we're going to try and keep things as similar as possible to what we had before we're then going to create a a grid called floor grid and give it the width and height of the h cells and v cells and then if we are creating uh the very bottom level if we're at the very bottom level uh we want to set index to one otherwise index is zero uh what's index going to be used for well this double full loop does the same thing that we did in the create event apart from uh if we are setting the ground we're gonna set it to one if the current level is zero otherwise ground is going to be zero as well and then we're just going to add data list to floor grid like we did before you can probably copy and paste the code from the create event and just modify it so it looks like this should be very similar and then we just simply add for the floor grid to our map list the current map list um and you can see this that's why we can use this script because this code is going to work for every floor you don't have to put the show debug messages but it's useful for debugging purposes okay so now we're gonna add two more things and we're gonna test it to make sure our code still works so we're gonna go we wanna go into the step events of the map editor at the very top we're going to add a new line this one here so far floor grid equals current map list and inside the list we're going to say current level and then if we go into the draw event same object we have two lines i think so we have this line at the top for var levels equals zero levels is less than ds list size current map list levels plus plus and then we have va floor grid equals chromapolis levels because we're grabbing the grid from the list now as opposed to just having one grid and then don't forget to make sure we have a closing curly bracket at the very bottom and the previous code should just be inside that if statement or sorry inside this new for loop so all this should be inside so if we run the game now we should be able to do the same things we did before except it's working differently like so and shift shift r and c to change the biome cool okay so uh we're actually going to be able to add new floors now so to do that go into the step of the map editor and we have a brand new region at the bottom called change or increase level and inside there we have two blocks we have if pressed up and if pressed down uh let's tackle if pressed up first so we're only going to be allowing ourselves to create a new floor if current level equals the top floor it's worked it out easier to do it that way um so i'll just explain what this code does this block here uh so this whenever we're pressing up this is always going to run as long as current level plus one is less than the size of the list so basically as long as current level is not the top floor then increase it otherwise if we if we're not holding shift and current level is at the top floor and we're pressing up then uh we're just gonna set current level back to zero so we can rotate between levels if we are holding shift and current level is at the top level then we're gonna make a new level so uh one more check though is uh we're only gonna make that new level if the size of the map list is less the max levels i.e we not already have 12 floors in that list so if all these conditions are true and we can make a new level we're going to increase current level by one so that it's now the new top level and create a new floor for that new top level uh which we've already got a script for which is the same script we use in the create event then if we're pressing down this is a bit more straightforward so if we're not holding shift if current level takeaway one is greater than equal to zero then reduce one from it otherwise just send just set to current level to be the size of the list segway one so we're just rotating between the level levels here if we are holding shift and current level is greater than zero reduce one from current level and delete the floor so this is going to be our last thing and last script to do for today and we're passing it current map list so if we go into that script if you make it first and then go into it so uh here's the top of it we're just gonna delete the highest floor so last pause is going to be uh the the size of the list takeaway one floor grid is going to be the highest floor grid we currently have uh what we need to do if you remember the floor grid this this guy here this grid has a list in every cell uh you never want to delete a data structure that holds all the data structures because that's how you get memory leaks so the first thing we need to do is get rid of all the lists that are stored inside this grid which is what this double full loop is going to do then we can destroy the floor grid that we got from the map list but map list is still going to hold the pointer to that floor grid so we have to then delete the grid pointer from that list as well which is what this line does and that's going to delete everything that we need to so if we now run the game we can see this in action so there's one last thing to do uh totally forgot in the draw events of the map editor we're updating our draw y from this to this so we're just to take taking into account levels this time so it's the levels times towel height times two that makes all the difference so just make you have that make sure you have this down i'm gonna zoom in this and when you run game it should all work properly i'm going to switch my biome to uh barn because uh there's actually useful stuff for barnes so i'm just gonna uh stick a wall on the edge then i'm gonna press shift knob to make a new level that's the one that i want and let's give ourselves a floor as well this one will do i'm going to press shift and click so we've got a floor at the top and i'm just going to delete it's going to delete oops that's the wrong one yeah i'm deleting too much anyway uh you should have something like this where you can add floors and delete them i'm gonna i should probably well let me just finish this and then i'm gonna delete a floor there we go so let's add a new floor let's uh spam a different tile so you can see we've got a roof kind of but then uh what happens if i hate my creation i'm just going to delete them all so i'm going to keep pressing shift and down and i can't delete the bottom floor which is as it should be if i keep pressing shift and up how high do i go like this is the highest we can have it's pretty high uh let's make a floor here oops there we go so that's as high as we can go this is this would have to be the roof so let's let's change actually so this would have to be the roof of a very tall building and that's it for this episode thank you for watching i will catch you next time bye for now
Info
Channel: GameMaker Rob
Views: 172
Rating: undefined out of 5
Keywords: gamemaker, game maker, gamemaker 2, game maker 2, gamemaker rob, tutorial, gloomytoadstudio, samspade, spalding, gamedev, indiedev, xcom, isometric, series, change the, walls, wall, biome, deco, decoration, five, change, add, floors, levels
Id: Mx4Jb0GPNiE
Channel Id: undefined
Length: 11min 54sec (714 seconds)
Published: Thu May 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.