Let's GameMaker: Turn Based Strategy #2 (Resolution & TBS Movement) Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is lost and welcome back to episode 2 of the turn-based project that we're making so in that in this episode I kind of promised that I would show you how to do some sort of like resolution control so I think we can start with that and then we will make the move squares as we talked about in the previous episode which I will go into further detail about in a moment but let's do this first sir to control the resolution size for a game like this I've come to the conclusion that I think this is probably the best way to do it could be wrong you know I'm sure that there are obviously this a variety of ways you can control the resolution size but for this project I think this is a good idea so create objects and we need to create them with some code in it right and in here we're going to start the the window size and variables oh god that spell today but that's what we want and we also need a global and we're going to call this global window scale and for right now this will equal 1 this will make sense in a moment I mean and again there's many different ways you can actually do this code and layout but I'm just going to do like this because I've already pre done this and it kind of works quite well so display with and I mean this is quite self-explanatory this wanders right this is a variable and this is what it does it's just going to get the width of your comp of your monitor and we also need just real high and this does the exact same thing but obviously the height of your resolution Armani or whatever and now we need 1/2 we need the window width and the window hex and this is this heights are in height and this is going to be obviously the begins with height height got cat speak to the height that we set momentarily so yeah we'll just do this really quick and then we need window height and I realize I've missed the code up here to make this width and again I will probably make a few errors here and there just because I'm constantly glancing over at my previous project which is done like it's not finished but things like this is done you know like that the resolution controls already in there so I'm using that as and as you can see here I'm just using it as a base so that we can do this I've chosen to do it in this format rather than copy and paste my linear just so I can go as I'm writing the code I can explain it a little bit better and I think this could I'm going to show you is going to be perfect for options menu so that this will be transferable to like other projects that you may do in the future and I think it's well worth knowing so what we want to do to start with is we want to find a way to increase the window right so the way that you would go about this is we're going to use just the plus and minus key for this but you can easily adapt this to clicking a button so let's just crack into it so if keyboard check pressed we'll see a virtual keyboard ad it should also work on your numpad I believe as well and the display width is bigger than 640 because that's what size the game is and obviously we don't want the game to be able to go bigger than our monitor screens right and we'll times that so if the display width so your computer if it's bigger than 640 times the global window scale then it will do everything in here and this courier will prevent it from being bigger than your monitor is what I was trying to say so every time you press the Add button we'll add one to the global window scale we'll had we'll add half a point to that if you like and so what will then do is we'll sit window set size and we'll say 640 times the global window scale for the width and we'll say 360 times the global window scale and I believe what this will do for us is every resolution that we have will be a sixteen by nine ratio right because I believe that's the most common and I don't really know anybody that doesn't use a sixteen by nine ratio anymore so that's that's just what we're going with and so now we'll actually set the position so we say and what I mean by set position is this is this will set the position in the center of the screen so it's not you know going all over the place so we'll say if display width is less or equal than 640 times the global window of scale Oh God global window scale um then window set position um I will just say 0zu um now we sit so this basically is saying that if it's the size of your monitor right are there abouts it'll set the window position up here sit at your top left so that it is the fullscreen right I mean Barry man this will only work this will work for full screen mode this will only work for um the windowed mode or borderless windowed mode okay um so now we'll say else if the display width is bigger than 6 foot so if your monitor is bigger the width of your mullet is bigger than 640 then we will add that to the global window scale no that's sorry I don't mean we'll add it to the global scaling army and if your display width is bigger than 640 times the global window skill so for example if this is this stats at 1 the global window scale I do believe right yep stats at 1 so we're saying that if display with 6 Watts times 1 you know then it's just 640 so your monitor will be wider than that and then every time you press it it will add 0.5 ok so imagine this is imagine the window skill is now - so if your monitor is bigger than 640 x - so what's that 2080 sorry 1280 then we'll set the position to the center right and when for that when you through an alarm because this doesn't update instantly for some reason it takes a couple of friends so or a framer so that's what we're doing our source it if set position is false which stats is false then we'll say alarm zero equals one will create that and second and say set position equals true right and now we need to basically do this but for subtraction so to make the window smaller again so set else/if keyboard check pressed and we'll go VK subtract and obviously and the global window scale is bigger or equal to one because we don't want it to go any smaller than that because that would be a little bit ridiculous and then we'll say global dot window scale - equal zero point five will set window set size I mean this is pretty much exactly like the other code but just kind of opposite if you're not I mean global window scale 360 times the global window scale okay good and then we'll say if um display with um 640 on less times the global window scale then again window set position zero zero you probably don't actually need this this particular section here but I'm gonna add it anyway just for consistency sake and then we'll set else else if um display width bigger and 640 homes bigger and 640 times the global window scale then again it's exactly the same if set position is false then alarm zero plus one and set position equals so this is basically the code to scale again to change the resolution and also after it's changed the resolution as I said it will see if if the if the game size is smaller than your monitor it will set it to be in the center and if not then it will set it to be at the top left so that is the full screen so let's just add the alarm quickly and then we can move on with the next step so let's go for alarm zero and in here you this is just going to refresh the window position so window height will be window get width divided to so it it will be at the center of your monitor obviously and we're going to do the same AHA keep putting height first I mean width and we'll do the same for high so when you'll get height divided two and then we'll say window set position display width divided 2 minus the window width and then the display right by 2 minus the window type and then we'll say set position is false so that we can then do it again and that is the resolution size so let's just check that this wax um please work you should do so let's have a look and of course it doesn't because once again I forgot to put the object in the room being the complete genius that I am that will never get old that's kinda that's gonna happen a lot I'm just I'm just saying that will happen every time I see if that works and it does as you can see it will never go bigger than the screen as you can see these black Bowser here because we're in window mode if we go to borderless that won't be an issue um but yes we can now change the resolution in increments of I'm actually not sure half of 640 right so 320 so in increments of like 320 pixels I believe we can change this width wise anywhere so yeah that works quite nicely and now we will move on to actually creating move squares for al character to move on so if we now close this and go into our object Spearman we are going to add a create event and in here we are going to say I guess these will just be the variables for this and what we're going to do is our movement system is going to be based on pixel distance right and you can also turn this into like a point system right so you so will say our first character the Spearman I mean we will have to change this I don't know but for right now we'll see the Spearman as a pixel distance of 100 and in fact I'm going to rename that to pixel dist so yeah it can move 100 points now this is pretty irrelevant at the moment this doesn't mean anything yet because I don't actually know I think that's going to be about three squares roughly it can move but we will we will check this in a moment and we're also going to want the ridge pixel disk which is good stands for original pixel distance which will equal is pixel this just so that we can it was just so that we will be able to reset at the end of the 1000 pixel distance so his movement point this the pixel distance is basically movement points right so at the another 10 we can then use this code you know but obviously the other way around so then reset our movement points now might sound a bit confusing hopefully I've stubbed I've made that and understandable probably haven't if I haven't just let me know now I'll go over it um but now we're going to need to create a script for this to work in fact first we do need to create but first we should create a move square right so let's just go SPR move square I guess and we'll make it they to by fixed to and I'm gonna make mine white but like I guess transparent so see-through and maybe 50 in here would be okay um and why that why the buffer whatever that'll do for mine I think um we'll see how that looks so go ahead and center that and now we will create the objects also I should make you aware that this move system is going to be object based not necessarily the most efficient but that's just how we're going to go about doing this so yeah that will do object move square now we need to create a variable in here and this will make more sense in a moment but in here I'm just he's only gonna be one variable in here so I'll just put em and we're going to use a loop to determine how far we can move as well so we'll just put loop provides for now and we will come back and edit this to be more relevant in the future and all we need in here is a row and the row will equal let me just check so I forgotten one to eight so they're all equal 1 to 8 and this is basically just going to be the Y position book that'll make sense in a moment and also the loop bars whatever we was in here will always be used to check the entire grid okay so we now need to create a script and we'll call the scripts scripts place move squares I guess that'll do whatever we know what that means so um let's see for this we're going to use a for loop now we've covered these in a topic previously in a basic beginner topics I believe I called the series so hopefully if you've watched that you might be a little bit aware of how this how this works but if not just follow on hopefully you'll understand in a moment so we're going to say for I equals 0 and while I is lower than 18 I plus equals 1 okay now I don't want to go to index like I said I made just a series about this and if that's the wrong one I'm in a series about this book we're saying I starts at 0 and while I is lower than 18 I will add 1 so we now need a variable called I X and this is going to be the x position of the grid that we check to see if we can place a move node ok and again this probably isn't the most efficient way of doing this because we've checked we're always checking the entire grid but I don't know I think this is and I just like the way this works and plus I like the idea of adapting an actual loop in here just to demonstrate how they work so this is what we'll use I mean it works just fine everything where it's there's nothing wrong with it I think it could just be done slightly more efficiently but whatever so saying if um I X is bigger or equal to 576 that will that is the very last the very last grid if you think about awkward that's the very last rule if you like the very very last roof so then it needs to move down a row okay so we're going to sit if it's 576 then I it's going to equal zero and the row will plus equal theta to show the row the Y position will move down to the next column a down to the next row however you want to phrase that whatever so I move down one and then it will check the next set right so then what we're going to do is underneath this we need to say if MP grid path so if we can path to a certain point again let's fill out the ID which one is map grid and we know the path is global navigates so um we have to add a few variables you have just realized to our player 12 Spearman but we'll come to that in a moment so we're going to say if if I'll do that now just so you'll understand this next bit in the Spearman yes sorry in the Spearman we need cur nerd X and that will just be his X for right now and we'll say cur node Y so this is just its point on the map this it will always be stored in this value so now we're going to say um so if we can path from the global selected current nerd X and the global selected um current nerd y 2i X and to the row and off your alarm diagonals then we will say if path get length and global navigate so this will calculate that the length of the path that we have to travel so if it is smaller or equal to the global dot selected pixel pixel dist then I'm sure you can see what's going to happen here we're going to create at that position an object move square okay wrong number of arguments somewhere where Y app because I haven't done that right so it will do that and then we'll say say if Rho is bigger than 320 so this is the actual look this is the bottom row now then we're going to say Rho equals 0 and I equals 20 just to stop the loop completely okay hopefully hopefully that made sense and let we'll check if it works really quick by adding it to our player turn script so what we need to say now is when we move obviously this has to be correct but we also have to have if Mouse in fact I'm going to do this up here so we'll say and instance position um mouse X and mouse y is over the object move square so this basically means we can only have a move if the mouse is over a move square so we can only move to the move squares right now let's just see if this works it should in theory work oh no it shouldn't because I haven't called anywhere bye so after we've um I'm point on the screen again like you can see what I'm doing after we've said the global selected is the player this is when we will run that scripts okay so we'll say script open nodes ah no we won't that simile other that's the other project what we'll actually see is play sum of squares like that okay so now let's check that that is working this should be fine in theory um so I'll let me make it a little bit bigger no what's wrong um variable control I X ah that should have a that should have an underscore in the middle of that so let's do that real quick so place open nodes yep that should have an underscore now let's see if it works um no it doesn't okay why doesn't that work I will be back in one moment right so it actually did work all you have to do like stupid I forgot once again is if you go into the move Square and actually actually link the sprite to it you know the sprite move square then it will work and what I did actually is I just made this a little bit darker so I did white again but I could increase the opacity to 80 and then filled it make sure you click replace when you do that now let's have a look how this works um so as you can see the move squares are placed we cannot I'm right-clicking outside of it we cannot move outside kind of move anywhere but if we click there then we can now obviously we no need that to disappear right this has got a girl now so um what we do with that is in the play ten we say down here once we have right clicked we can then say with objects move square um instance destroy and that should do it yep and as you can see still making it here because we're not updating the current nerd X&Y okay so we should do that and the way that I did it in my previous project if you like is I used this code here so we'll say so we'll say if global DUP moving is true now we haven't set this variable up yet but we will in a moment so if it's true if we're moving then with global selected and then we'll say if half index equals minus 1 so that means just if the past done if there isn't a path anymore then current nerd X will equal X and the current nerd Y will equal Y and then will I say global dot moving is false and we will stop there so what we need to do now is we need to go in control remember the global variables in here we need to sit global dot moving equals false and in our navigation scripts are actually I guess you can put it in here yeah all right we'll do it here we in here we will say down yes this is fine what's it global dot moving is false spell now let's check that out so we now should have a system that works quite nicely let's just check it so we're moving there yeah no actually why why why why okay give me one moment so that's why my brain just isn't working today this should actually say and true obviously I don't know how I just made that mistake but whatever this should now work let's just test it one more time my brain is fat and all over the place I don't know if you can tell so yeah now it's working obviously you'll notice now that the path has got shape and slightly smaller because we're on the moving part of the distance right maybe not oh no it's not because we're not taking off the movement points are we right let's make sure that's happening so we will say that um when we move we need to take off the pixel distance right so how far we've traveled so let's just do that now so I've just copied and pasted that in there too feel free to copy that and that should do the trick so let's try that out um in theory this should now work right um yes so now we can't do it anymore so let me just try that again um right so if we move one space then yeah as you can see it's now getting smaller and it is now working just fine so now before we end I will have like a really quick just finished n button just so that we can you know have our movement points back so if we go to object control and I guess that we can just say ah I've already done actually I've already done this so you can just feel free to copy and paste that in there and that should do the trick quite nicely I think we can end that there for today um you know we've we've got ah a proper movement system working now what I will do is I'm not sure what I'm going to do for the next episode yet but I'll have a think if you guys want to see anything in particular then comment below and but yeah I'll have a think what leads on nicely sis I think probably what we need to do is get a situation where we have multiple characters on screen and then build the movement system with objects in mind that we have to maneuver around and stuff like that and but yeah thank you very much for watching guys and I will see you next time
Info
Channel: Talent Lost
Views: 16,556
Rating: undefined out of 5
Keywords: gamemaker, game maker, game, maker, lets, let's, build, lets build a game, let's build a game, part, develop, create a game, how, how to, tutorial, guide, gml, code, lets develop, beginner, rougelike, create, lets create a game, lets create, let's create a game, how to make a game, how to create a game, how to build a game, turn based, turn, based, strategy, turn based strategy, tactical combat, tactical, combat, mp grid, movement, move, resolution
Id: bodc3KF4LL4
Channel Id: undefined
Length: 30min 0sec (1800 seconds)
Published: Mon May 23 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.