Game Maker Studio 2: Tower Defense Game 1/3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on my game maker enthusiasts it's real touch GML here and today I'm presenting a new game that we're creating which is a tower defense game so I've went ahead and made this game beforehand and you're seeing it right here on the left hand side this is gonna be a three part series and basically what we're gonna go through is creating the basic core foundation of the game so the simple rules of tower defense right so you have a path you have enemies that come down this path and the towers shoot them and you don't want the enemies to get to the end all right very very simple rules so I'm gonna actually do something a little bit different here I'm gonna go into notepad on my right hand side while I let the game play out on the left hand side and we're gonna design the game from a developer's perspective so we all know the basic rules of tower defense you know you have the path you have the towers you shoot them and that's it right but what are what separates our game from the others right so let's figure out okay what happens when you go to a next wave what kind of different towers do we want in the game we're gonna design that out right now just so you can kind of see that process so one thing that we're gonna want to figure out is okay enemy progression right so how do we want the enemies to progress wave to wave so we can do a number of different things right but one of the main things would probably be more health all right so we're gonna want to give the enemies more health each term because each turn your wave you're creating new towers and the enemies need to get harder what's another set of progression that we can use with this enemies so we can say maybe a faster spawn rate so they'll be more clumped together right we also maybe want to add one enemy per wave so we get to wave twenty you say you start out with five enemies you're now 25 enemies alright another thing we can do is maybe there have a faster speed so each wave the enemies have faster and faster speeds these are all things that we can add into the game let's look at our towers now so what are our towers gonna do you know we can have all these different cool lightning towers bazooka towers if anyone's ever played keep our defense you know you have the super-monkey but we're gonna we're gonna build out a couple basic towers here and they're gonna have basic attributes to them so for example let's have our first tower which will be our our gray tower that cost the least amount of money let's just make it an average tower right so it has medium range and a medium fire rate the way this game is designed out is the there is no damage for the bullets so now you can easily and I'll show you how to do it implement different bolts into the games where towers can shoot different bolts to give bigger damage rates I'm simply just working with the attributes of range and fire rate with these towers all right so our second tower can be let's say short range and with a faster fire rate right or a quick fire right all right so that's gonna be a short range with quick fire rate and then to invert that we're gonna give one with long range and a slow fire rate all right so they cover more of the map but it's not shooting as much okay so these are gonna be the basic towers and progression rules that we're gonna follow when developing this game alright so here we are in game maker studio 2 now the first thing I'm going to do is go to my rooms here let's go to room 0 and what I'm gonna do is change the width and height so I'm gonna make it 640 by 480 now this is just my preference this is the game size that I want to have if you don't want to have the size you definitely don't need to what we're doing here can be equipped with any sort of room size so I'm gonna go over to options main and I'm also gonna change my games frames per second to 60 this gives for smoother gameplay usually games play at 60 frames per second I recommend 60 for smoother gameplay alright so there we go so we've got our room we've got our frame set now let's go ahead and start building the actual level now typically in game development you don't build the level first you want to build all of the logic in the game we want to start off with a very basic room where we can then add into it so the towers all of that sort of stuff right so I'm gonna go ahead and create a sprite actually I'm gonna create a group I'm gonna name it textures and I'm gonna create a quick sprite and I'm gonna make it 96 oops by 32 and basically what I'm doing here is this is gonna be the texture group for our tile set that we're gonna put in the game so how you're seeing the path and grass actually laid out is just a tile set so I'm just gonna build the parts for that tile set so in the image editor here I'm just gonna create a square that's 32 by 32 all right and then let's I'm gonna create another one here I shouldn't use a different color there we go and then another color here so these are gonna be this is essentially three 32 by 32 sprites so in title sets with the game maker the first one needs to be blank the second and third slot are going to be the grass and dirt path pictures or textures alright so let's go ahead and do that now I'm gonna go ahead and fill this in and select it like a green I'm gonna bring down the darkness just a little bit you pop a couple little grass dots in here alright I'm gonna select this we're gonna create the dirt so I'm gonna bring it down and darkness and then just to keep it congruent we're gonna go ahead and place a couple of these down as well all right so that's a very basic texture sheet for our landscape so I'm just gonna name this as tiles all right and then I'm gonna go down on the right hand side here and create a new tile set and I'm going to select the sprite that we just created on the right hand side I'm gonna set the tile width and tile height to 32 by 32 this is essentially making it so that it separates each piece is each piece into 32 by 32 so we can use it that way all right and I'll name this tea tiles so now let's go ahead and go into our room here and what we're gonna do is we are gonna add a new tile layer all right and here we're gonna select the tiles and now we can simply take this and drag it and fill it everywhere so I'm gonna fill it with grass well and it looks like actually making the tiles is wrong let's see here let's edit this real quick yeah we were one pixel off all right so then I'm going to take my drawing tool here and I'm just gonna draw in and we did the same thing for for our dirt let's go ahead and take that perfect all right so now let's go ahead and just draw in a path that we want our enemies to go around all right so let's see here very basic path kind of make it look the same and this should be lined up actually so they go there's our path this is going to be the path that the enemies follow all right so how do they actually follow the path and we're actually going to be used something called paths and game maker so what I'm gonna do on the left hand side here is I'm gonna go ahead and create a new path layer all right and here we're gonna select the path and we're gonna create a new path and you can keep everything here the same and what we're gonna do is we're just gonna basically click right up here right before our path actually starts this is where the enemy is gonna be created now you can see it's a little off centered so if you click down here in our grid X you can actually select that to be 8 and you can get it right in the center there all right so let's actually let's make the Y 8 as well so now we can drag down to the center of that's sprite there we go and whoops mess something up there and now we're just gonna click all around the path we just created to create a very simple path system okay so now this what we can do is we can assign any object to follow this path and it's gonna do it pretty much it's gonna look great all right so let's go ahead and in our sprites create an enemy so I'm going to add another group and we're gonna name an enemies and here I'm going to create s enemy I'm gonna edit it make it a 32 by 32 sprite here we go and we'll just make it look like that alright so now I'm gonna go ahead and create an object and I'm gonna create our enemy so Oh enemy select sprite and then I'm gonna create another object and this is gonna be called a spawn and essentially what a spawn is gonna do is it's gonna control all of the attributes for our enemy so it's gonna have one main controller for the health points in the game the speed and the level progress as well as it's gonna actually spawn our enemies okay so if we go into the code and then the create event what we're gonna do is we're gonna set up a couple variables and this is gonna be spawn amount and this is gonna be how many enemies were actually spawning for each wave so we'll say five to begin with that's gonna be our starting amount our spawn underscore count is gonna be zero what this variable does is going it's going to track how many we've actually spawned in the wave and then once it hits the number five it's gonna stop spawning so it's just a tracker and then our spawn or rate this can equal 1 multiplied by room speed which is essentially one second okay and what this is gonna do is it's it's again just pretty much once at once every second there's gonna be an enemy that spawns alright so here what we can do is set alarm 0 to equal 1 and if we go into alarm 0 here we can go ahead and start writing some code so why did we call alarm 0 alarm 0 is basically like a timer so the event gets called every time this timer reaches zero or whatever it may be right so if we set it to one that's one millisecond so in the create event in one millisecond we're actually going to call this event and any code inside of it what we can normally do is set alarm zero 2 equal spawn rate which is what we are going to end up doing but we want to start spawning them right away we don't want to wait a second for your enemies to start spawning so in alarm zero we're gonna say if spawn underscore count is less than our spawn amount we're going to instance create depth at X Y depth is negative one with our Oh enemy we're going to increase our spawn count variable and then we're going to set alarm zero to equal spawn rate so it can keep going through this code every second okay so what we're doing here is we're creating a basic if statement so we're checking hey is our spawn count variable less than our spawn amount variable this is at zero and this is at five so yes it is less than that so we're going to create our enemy then we're going to add to this spawn count hit alarm zero back to spawn rate which is one second that's what we made the variable so once it comes back here it's gonna say now if one is less than five then we're gonna create another enemy and in spawn counts could increase again and it's gonna go through this process five times or however much our spouts amount our spawn amount is okay so if we go into our room here we go to our resources and we put our spawn well let's make sure we're on the instances layer we put our spawn into the game now actually let's go ahead and we want to make sure it's completely centered I want to make sure it's completely centered with our path so let's put this to eight as well there we go I'll change this back to 30 to 32 so now it's gonna create those enemies right on top of that layer so in our enemy we're going to go into the create event and now we're going to just initialize a couple things now like I said before our Oh spawn object actually controls the health points and the speed of our enemies so we're gonna go ahead and into the create event of our spawn we're gonna set up those values so we're gonna set global dot HP to equal 100 we're gonna set global dot speed equal 1 and we'll set global that level equal 1 as well while we're here all right so HP is gonna be the health points for our enemy the SPD is gonna be our speed now I don't do speed because that's a built-in variable and game maker and we can't actually use that but speed is going to be in control of how fast we're moving on the path so why do we make this global because every enemy that gets spawned with that wave is gonna have these same attributes here okay it just just make any global makes it easier so we can just access it and it doesn't mess with any of the other code that we're using all right so if we go up to the enemies create event we can go ahead and start everything out so we're gonna say path start and it's gonna be path 0 that we created the speed is going to be global that speed the end action is going to be 0 we don't want it to do anything and absolute it's gonna be true all right so that's gonna start us out on that path with the actual speed itself we're then gonna create a variable called HP and it's gonna equal global HP so since this is in the create event of the enemy its initial values are coming from the wherever the values are when it's created here so wherever these values are when this is created that's gonna be the value so even though this is gonna change with our enemy progression that we built if it's already spawned it's not gonna change so we could spawn an enemy with our goal what HP equal 100 and then right after it's spawned set global at hbd whole 110 and this would not change because this value has already been set all right so let's go ahead and run the game and actually you know what it's a little bit off because we need to center the origin on our enemy here so just go up here middle center and we're good to go so now you can see the enemies coming out on the path and there's five of them and they're just gonna be going on through so that's gonna be it for today go leave a like go and subscribe visit Cody made simple calm to learn more about programming and I'll see you guys next episode peace
Info
Channel: RealTutsGML
Views: 47,957
Rating: undefined out of 5
Keywords: Game, Maker, tutorial, beginner, gaming, studio, java, programming, lets, build, game, tutorials, game maker studio 2, game maker studio tower defense game, game maker tds, game maker tower defense tutorial, game maker tower defense game tutorial, game maker studio 2 tsd, tower, defense, tower defense game, game maker tutorial, game maker tower defense tutorial game
Id: pU26LtyzM8k
Channel Id: undefined
Length: 17min 17sec (1037 seconds)
Published: Wed Sep 13 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.