[6] GameMaker Studio 2: XCOM 06 Game Tutorial Series - Changing the height/width of the maps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so in today's video i will show you how to do this which is adding or taking away so let's just make it a very thin map from the map and if we add a new floor then it still has the same map dimensions um let's get started okay so if we go into the create event of obj map editor so we have a macro called base tiles per piece and we have two variables horizontal pieces and vertical pieces i just wanted to run the game so i can use a visual aid to explain things so right now we have our map and it's just a 10 by 10 so it goes 10 tiles across 10 tiles down um this is following on from our macro which is base tiles per piece is 10. what do i mean what do i mean by per piece well if we divide the width by 10 it gives us one which means we have one horizontal piece if we divide the height by 10 we get one again which is one vertical piece if i increase the width by three it's now 30 across divided by 10 is three so we have three horizontal pieces we still only have one vertical piece though but if i increase it you know by one two three it's a 40 by 30 so we have three horizontal four vertical pieces that's literally all it's for and it's just to be used so we know how big grids should be because for example if i make a new floor now and then you know oops paste this we want the size to be the same okay so now we go into the step events of the map editor let's just make this a bit bigger for now so um we have some code which i've adjusted uh originally it's just gonna be for moving the camera around it used to be called just map but uh it makes more sense did we call it camera because it's actually the camera we're moving not the map anyway uh right now if we hold wazder we're only going to allow our old region to run if we are not holding shift otherwise if we are holding shift we're going to have a brand new region which you're going to be to change the width and height of our maps just make sure you have these three lines down first of all make a brand new region and let's open it uh i can make this a bit so sorry it's not going to be zoomed in um i don't really really want to split the lines because it's probably going to be more confusing well as long as you know that this is the same line let's just uh split it actually uh make it a bit a bit easier for you you can zoom in there we go so um all we're doing is we're checking for if we press left or right on this one here if we press press a or d uh we're going to increase horizontal pieces by right take away left so this is going to be either plus one or minus one so we're either going to be adding or removing from horizontal pieces and then we just want to make sure that we never go below one for horizontal pieces and we never go above five five is just like an arbitrary limit i set for myself um you can set this to whatever you like you know five for now is what i have otherwise uh if we press w or s up or down same kind of thing adding or removing from vertical pieces uh clamping it to either one or five so basically the minimum is a 10 by 10 tile map the maximum is a 50 by 50 tail map um i realize i haven't kind of explained what we're going to be using these maps for we're going to have battle maps which are the maps we're making stitched together so even though you might have a max of 50 tiles for a single map the actual battle map could be 500 tiles with 10 or more of these other maps stitched together randomly so or even not randomly you can kind of decide how it gets placed but anyway um that's why i've set the limit and then we have a new script called scr change floor size we're passing it the current map list which holds our floor grids and the horizontal and vertical pieces so i'm just going to minimize it now so once you've got this this stuff down we'll go into the script okie doke so if we now go into well if you create the script and call it scr change floor size i'm going to go into the script now and um so at the very top let me try and zoom in as much as i can we have the name of the script we're passing it to the current map list horizontal pieces and vertical pieces the description for the script is we are changing the dimensions of a floor but it should be all flaws actually um the first argument is current map list which is the list that holds all of our floor grids and then we have horizontal pieces and vertical pieces should be self-explanatory let's just move this there we go this is just like another description it just says if the width of the grids are less than or greater than horizontal pieces either resize the grid and add cells or delete cells and then resize the grids why delete cells first because if we don't do that we will get a memory leak because those lists will not be recoverable they'll just be existing in memory so um this isn't entirely true uh you'll find out why in a minute so uh the first thing we want to do is get the width and height of the floor grids and also the wanted width height that we want to change the four grid to based on the horizontal or vertical pieces so we're gonna grab uh the very first floor grid there should always be one in every map so grabbing it from this entry is a safe bet and then get the width and height of this grid and also the width and height that we want to change that grid to um this stuff here is explained here so basically these two lines we're checking where their horizontal pieces is not equal to the width of the grid or that vertical pieces is not equal to the height of the grid because um we're going to be clamping before the script runs we clamp these two variables to make sure they never go below one because on a 10 by 10 map we never want to decrease it which is just what this says and that was the exception to this so yes we want to change the width or height of the grid but only if um it's not already at 10 by 10. okay so this bit here we're going to be adding cells to the floor or to the grid let's say floor grid makes more sense so if the horizontal pieces is greater than the width of the map all the vertical pieces is greater than the height of the map then and by height and width i mean you know um how many 10 by 10 pieces does it have so we need to sort out where to start the x x and y y from for our loop that's what this does um we also need to set the end x x and end x and end y y for the loop which is what this does i know i'm not explaining this it's going to make sense when we come to the for loop which we're going to come to next so we have a triple for loop so here's the first one here's second here's the third and what it does is uh for as many flaws this one's for as many flaws as there are in the map we're gonna resize the floor grid so we're grabbing the floor grids for the level resizing it to our new width and height and then um this just here is setting is making sure we set the very bottom most level ground to a grass tile so it's not just empty anyway so for as many levels as there are get the grid resize it then we have a double full loop just to go through that grid and we need to make a new list for every new cell and give it default data which is what that does and then uh yy start xx start is where we're starting from because we don't want to start from zero zero we want to start from the old edge of the grid and go from there that's all it's for so here's the matching bracket for levels and then we're ending the region from there and then um so we have an else statement here so basically if this isn't true then it means horizontal pieces or vertical pieces is less than that corresponding value for the grid so we're decreasing or removing cells from the floor grid so like i said in this situation we want to delete lists from the cells first to prevent memory leaks and then resize the grid so again we get the start xx and start by y where we want to start from uh the end x x and y y is just the existing width or height of the grid we don't need to uh calculate that again for as many levels as there are are in the grid get the grid from our map list for the level use a double for loop to just destroy that list that's all we need to do and then after the full loop has been done for that grids we just resize the grid to the new width new height and then that's the end of the region and that's it for that script okay and the last thing we need to do is just update add new floor script so um previously we had these two lines where we just we're setting h cells and v cells to 10 but now we're going to use the existing code i have which is uh setting h cells to horizontal pieces times base tiles per piece and the same for free cells all this is going to do is whenever we add a new floor it's going to make that new floor the same size as every other floor in that map and that's the only change in the script but if we we run the game now we should be able to see this happening so here's the map uh pressing holding down shift pressing s has given me all of this that's the max i can go should be five if i press shift and d two more times that's the max i can go because five is the max if i then press shift and w i'm reducing the height that's the minimum i can go and hold down shift and a that's the minimum width if i just make the map bigger and then make a new level shift and up is it yeah and then if i uh do shift and click oops if i do shift and click then i have a new level and it's the same size as the old one and if i now delete um some of these pieces like i'll press shift and w the whole map size changes both levels and that's exactly what we want to be um normally well my original plan for this series was to finish the map editor first and then show you um how to use it in the uh to make a battlescape like you know uh randomly stitch maps together to make it a bigger map but um it's that's going to be quite a few episodes away so i think next episode what i'm going to do is i'm going to show you um what we're aiming towards which is i'll just show you um a quick way to randomly add maps together to create like one big map um so you get an idea for what we're going for um but until then thank you very much for watching i will catch you next time bye for now
Info
Channel: GameMaker Rob
Views: 144
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, change, add, floors, levels, six, width, height, How to make a 2.5d game
Id: tfIMQyyIJiE
Channel Id: undefined
Length: 14min 10sec (850 seconds)
Published: Fri Jun 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.