[3] GameMaker Studio 2: XCOM 03 Game Tutorial Series - Paint the Map

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so at the end of the last episode we had a basic map and a camera at the moment though uh the camera doesn't center anymore because we changed the the size of the view uh the ratio between the viewport the camera and the viewport so i have come up with with a calculation so regardless of the size of the map uh we're always going to start in the center just because i like to do that kind of thing so in the create event of obj map editor i also added v cells and h cells um set it to 10 and updated our floor grid equals ds grid create line with h cells and v cells and the very bottom in our camera region i have updated cx and cy so cx is now minus the width of the camera view divided by two plus half the width of a tile and cy is half the height of the camera view plus half the height of all of the cells times the tile height that gives us our central x and central y um i also noticed or figured out i have not told you the origin point for the sprites yet which i should have really done on the first episode so the origin point for farm deco farm floor farm west wall farm north wall is is going to be 0 and 33 so when you look at your tile the central point should always be on the middle left that's where all the tiles are going to be drawn from and sbr cursor is 0 32 although if you set it at 33 i don't think it will make much of a difference it doesn't matter what you have the origin as for tea grass although i have it zero seven uh because we i don't think we're ever going to be drawing this uh just by itself we're always going to be using the uh farm deco farm floor those kind of the tile sets okay so um let's run the game and you can see we have uh a nice centered map if we update h cells and v cells to and we run the game again you can see it's still centered okay so change h shell to these v cells back to 10 if you changed it and we're going to add two new variables these ones here because we're now going to code it so we can change the tiles on the map uh we have tile to place which is going to be an image index so for example if we are drawing the floor and the image index we want is 2 0 1 2 we're going to be drawing dirt and then tile part to place we're not going to change it just just yet but we're going to set it for future as e tile part stock round so we're going to be changing the floor for now okay so if we now go into the step event we have a brand new region called change tile to place and we need to know how many images each sprite has that we're trying to use uh the sprite we're trying to use we're gonna grab it from global.biomes tile part to place current biome let me just update this actually make it a bit easier to read there we go so sbr stands for sprite we're going to get it from this 2d array that we set up the tile part to place is going to equal ground and current biome is the farm outside images in sprite is going to tell us how many images that particular sprite has just increase it or decrease a little bit and then if we press right we're just checking to see if if if we increase towel to place by one is it gonna take us past the value of images in sprite if not then just increase it otherwise set tile to place to zero we're also going to have a show debug message just to show you that it's working and for pressing left as long as tile to place takeaway 1 is greater than equal to zero then we can take one away from tile to place otherwise tile to place is going to equal images in sprites minus one so if there's ten images then this is going to equal 9 because we start from zero and again we're going to have another show debug message just to show us uh what the value equals to make sure it's working properly uh is that everything yeah let's just run the game we're not actually going to change the map but if we if you have this output tab open and you press left or right oh sorry try that again there we go so i'm pressing right it's gone up to seven one more time and it goes to zero still pressing right and it goes to three now i'm pressing left and it goes to seven so it's working fine i'm going to minimize this region now and if we go to the draw event oh sorry draw gui event this is going to be a new event we're just going to do ourselves a favor and we're going to draw we're going to display what tile we're using so we can see it in the bottom middle of the screen so again sbr is going to give us the sprite that we're trying to draw uh scale because it's going to be small if we don't increase the scale get the middle of this display for the gui layer and minus the the scale for half the tile width divided by two sorry half guitar width and then d y is going to give us the the bottom of the screen take away the height of the sprite and then we're just going to draw our sprite here like that all we're doing we're just drawing a tile uh to scale so let's run the game again and now we'll have a visual indication you can see on the bottom middle if i press right it's going to change the tile if you press left it goes the other way like that and that just lets us know uh what tile we're using okay so now we're going to just put some code so we can actually change the tile and we're actually going to have the option to change the whole map at the same time just to one tile just to make it easier because there's going to be times you want to do that so we have this new region uh change current tile to tile to place and if we just get this structure down first of all so if we are holding down check button mb left if we're not pressing shift then we're just going to set the cell of floor grid that the cursor is over to tile to place so tile to place equals 2 this cell is gonna get set to two otherwise if we are holding shift we're gonna make all tiles equal the current tile so we're gonna use a double for loop the same as the one where we draw it and all we're doing is setting every cell inside floor floor grid xxyy to tile to place we could actually just do uh ds grid clear uh floor grid uh and then tile to place but um we're going to be changing this soon and we can't just use ds grid clear because we're going to be using lists inside the cells so we can hold more data so this would work but we're just going to use this so we can use it later on as well and if we run the game we can now paint the map a little bit so let's change it to dirt you can do this if i hold down shift and click it changes the whole thing do the same for grass for wheat and if i go back to dirt and paint this like that you should you should have the same effect as me okay so i'm going to minimize these regions now and the last thing we're going to do today is to make it a bit more visual to you what's happening uh we're going to add something in the drawer event we're going to have this uh debug region region to show numbers uh we're going to be drawing text over every tile and it's just going to give us the string of whatever ind equals and ind is the value for that cell in floor grid so once you've got this down let's run the game and you can see every tile is a one because grass is one change to dirt changes to two shift click they're all two wheat they're all four although you can't really see it because uh the wheat is drawing over some of the fours and so on and so on so all we're doing basically storing a number and and that's what we will be doing in the game a lot of so as long as you understand we're just storing numbers for different things like it's going to be like this but a little bit more complex because we're going to have a list in every cell because we want to know more than just the floor we want to know does it have a wall is there an axis there you know stuff like that and we're going to have multiple levels as well so we can have lots of different floor grids holding that information so just remember it it's just as simple as storing numbers and that's that's how we know that's how the game knows what to draw for us so thank you for watching i will catch you next time bye for now
Info
Channel: GameMaker Rob
Views: 233
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, three, paint, the, map
Id: wq3gz2A58E4
Channel Id: undefined
Length: 10min 58sec (658 seconds)
Published: Mon Apr 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.