Lesson 1: Breaking Down Snake
Summary
In this lesson, we break down the classic Snake game to understand what makes it tick. Learn the key elements that define the game and get ready to create a unique version of it yourself.
Lesson 1 Transcript
So what we’re going to do in this module is take the classic game of Snake and make our own version of it.
We are going to look at what makes the game Snake, how you would dissect it as a game designer, and what important parts of it are required to do a clone-like game of your own.
So onscreen. I’m going to throw up just a little bit of gameplay of a snake that I found. It’s a pretty old game. Goes back to, I don’t even know when, but if you had a cellphone in the two thousand, it probably had a snake running on it and you probably played it, but that’s what it is.
It’s a very simple game in terms of aesthetics, but there are hundreds of variations on it. If you search for a snake game, you will find tons and tons of different types of art styles and variations on it.
(00:55)
But if they are trying to keep the essence of what made snake snake, then there are certain things that it has to have.
Now, here is the first challenge that I will give you as a game designer. How do you break this game down and what makes it snake?
If you had to describe it to a friend or a colleague, or if this was your game idea that you wanted to pitch to someone, what is it that you say to sell them on it? How do you describe it in a way that is clearly talking about this game, not any other one, but this game?
(01:34)
How would you do it? Here’s what I would say.
It is a game that has increasing difficulty. Every version that you play, the snake gets longer and longer and you can kill yourself by running into yourself. That’s the way it works. So as you play, the game gets harder progressively, and eventually, you will lose.
This is not an endless game because even if you are a perfect snake player, because you are in an enclosed area, you will eventually run out of space and you will die. That’s just how it is.
The game is designed that way, so it increases in difficulty. It eventually ends probably not too long. I would say like 10 to 15 minutes is the most you could get out of it if you’re very skilled at once and you collect things.
But how important is that aspect of it? Do you have to collect things?
It’s probably pretty important. It shows you when it’s going to get more difficult because every time you collect something, that increases the difficulty.
But probably the bigger part is the score. You have a high score that you are trying to beat, whether it be from someone somewhere else in the world or just your own score that you’ve seen
(02:59)
Past attempts. It keeps track of how well you’ve done. It’s a challenge to yourself and it’s a challenge to others if you pass the game on to them. Those are the core concepts of what makes this game snake.
So how do we come up with a game like this but is also kind of our own thing?
Well, here’s what I’ve got for you. This is what we’re going to be doing in our course. It’s going to be a game that looks a little bit like a snake but is not exactly the same thing, partially because of coding limitations.
Snake isn’t exactly a complicated game, but we’re going to keep things fairly simple, and creating boxes that follow each other is actually harder than it looks.
So instead we’re going to do this; it is going to be a game that increases in difficulty. It is going to be a game in which you collect things and it has a score that you are going to compete with against yourself as you go along.
So it’s going to be fun. We’re going to learn a lot of stuff as we go along and as we make this, and we’ll dissect a lot of design topics as we go along to help you become the best game designer that you can be.
Up next, what we’re going to look at is getting our snake into the game.
Lesson 2: Creating Our Snake
Summary
In this lesson, we start building the Snake game from scratch, beginning with setting up a new project and creating a sprite for our snake.
Learn the basics of pixel art and how to resize your sprite, both in terms of the canvas and the image. By the end of the session, you will have a playable snake object that responds to arrow key controls.
Lesson 2 Transcript
Alright, I’ve got an empty project here that I have named Snake Game. I’ve just increased the resource size over here by double clicking and that’s all I’ve done and that’s where we’re going to get started.
So the first thing we need to do is create a Sprite. I’m going to right-click on Sprites up here and create Sprite. I’m going to name it s p r Snake.
So again, naming conventions are important. If you don’t do exactly what I do, that is okay. Just make sure that whatever you do is consistent so that it’s always the same.
Alright, our snake, we need to actually change the size of it because we’re going to have a fairly small room as you saw. So over here we have the width and the height. That’s what this w and H stands for, and it’s in pixels as you can see.
(00:52)
Now if you don’t know what a pixel is, it is the smallest unit of measurement on a screen. Every electronic is just made up of lots and lots of pixels.
So when we talk about resolutions such as 1920 by 10, 80, that’s 1920 pixels across and 1080 pixels down. That’s what it’s talking about. It’s the pixels in there.
So when we create something for 2D art, it’s normally made from pixels. So if the size is one, that right there is one pixel.
So currently our snake is 64 by 64 pixels. We’re going to click on this little arrow and we can resize it. We’ve got two options.
We can resize the image or the canvas. So when we resize the image, it takes everything inside of it and squishes it down. If we resize the canvas, it actually just takes the overall width and height, brings it down, or brings it up and it doesn’t care what’s inside of it.
(02:05)
So most of the time you’re going to want to scale an image, but let me show you the difference between the two.
So if we come in here and I make a circle like this, come back out, let’s resize it two ways. I’m going to resize it to 32 by 32, and if you want it to have a different width and height, a different ratio, you have to uncheck this box right here.
Otherwise, they’ll both change in accordance with what they were before. So I’ll click apply and now you can see it kind of changed, but it’s still the same spot inside of the image and it looks roughly the same. And now it is 32 by 32 pixels.
So I’m going to double click on this and I’m going to press Ctrl Z and now it is back to 64 by 64. Okay, the other way to resize things, I’m going to go into our Sprite and show you another way. If you click on an image up here,
(02:59)
All of the image options appear and resized frames are the same thing we were clicking on out there. So voila.
Now if we come in and resize the canvas to 32 by 32, you can already see the preview right here. It has changed dramatically because we’ve actually cut out the excess area around the circle and we haven’t cared about the circle itself.
So let’s come back in control Z and control Z one more time to get rid of the circle. And those are the two ways to resize. Most of the time you’ll want to resize the image itself.
What I’m going to do is come up to image resize all frames 32 by 32, and then I can press F for the fill tool over here. It’s a big bucket. I’m going to click on this green. I’m going to paste it right there, and the whole thing becomes green.
(03:53)
So there is our snake. Here’s a center fit. So you can see the whole thing. And it has a lot of properties that we’re going to touch on as we go, but for now, that’s all we need to do. You can now create and modify your sprites.
Awesome! Let’s go ahead and make an object called O B J snake. Let’s assign it to Sprite, which is done right here.
And now what I want to do is get this object moving around in our world, just like we’re going to do in our game. So the first thing that I often forget is you open up the room, and you bring in the snake. If the object is not in the room, it’s not going to show up in your game.
There you go. Okay. That’s all we need to do on the room front. Now let’s add some events.
(04:43)
What I want to do is use the events for our movement. There are a lot of different ways that we can do movement, but the way we are going to do it is by using the key pressed and then we can choose left, right, up, and down.
So we’re going to use the arrow keys here. So I’m going to choose this one first, and then I’m going to add the other events as well. So do the key pressed for right, the key pressed for up, and the key pressed for down.
Okay?
Now we have all of these events. So if any of the arrow keys get pressed, we want to make it go in the direction that the arrow key is facing. That makes sense. But how do we do that really simply?
Well, we use the built-in properties of every object. We’ve talked about the built-in variables, X and Y already, but there are a few more. One of them is direction. And this is the direction that it is going.
Not necessarily how fast it’s going, that’s controlled by something else, but this is just the direction it is moving. And GameMaker Studio
(05:56)
Uses a 360-degree direction system. So let me just show you what that looks like. I’ve taken a screenshot of the room and this is how the direction works.
In the GameMaker studio, it’s 360 degrees. So it’s all the way around the object, whatever one you’re looking at. And it starts on the right. So this is zero, this is 90, left is 180 and down, as I’m sure you’ve already guessed is 270. And you’ve got all the numbers in between. So you can go from zero to 359.9.
Once you hit 360, it just goes right back to zero. So it knows that. So we want to set the direction based on the key that we press. So let’s go ahead and do that On key press down, we’re going to set direction to 270.
Let’s go to the right and say direction equals zero because the right is the first one.
(07:07)
And GameMaker starts by looking at the right. If we go up direction equals 90 and the left direction equals 180.
So with these events, we have now set the direction that our snake should go. The only thing left to do is to set its speed. And right now we don’t have that, but fortunately, there is also a built-in variable for speed.
It’s right here. It’s just called speed, which is great, but we don’t want to set that inside of here. We actually want the snake to always be moving.
That’s one of the things about the game, that’s pretty much in every single game the snake moves on its own. So we want to set our speed, but we only want to set it one time. The way we do that is to add an event, then create event.
So the first time the snake gets created, we set our speed equal to one, and then from there it will just always be one unless we change it.
(08:13)
So now let’s press F5 and test out our snake. So now it is moving to the right because that’s what it defaults to.
But if we press up, we go up left down, right? Perfect.
We have our snake, we have some controls, and that is awesome. So that’s our first object in the world being controlled by us. It is a playable object.
Good job.
And now before we move on to creating the food we’re going to consume as the snake, I want to take a quick break and discuss comments and how to use them and why you should use them. And we’re going to talk about that in the next video.
GameMaker Studio 2 – Module 3: Attack of the Snake
- Lesson 1 – Breaking Down Snake
- Lesson 2 – Creating Our Snake
- Lesson 3 – Comments
- Lesson 4 – Snake Food
- Lesson 5 – What Are Functions
- Lesson 6 – Creating New Food
- Lesson 7 – Randomness
- Lesson 8 – What Is A Game
- Lesson 9 – Losing The Game
- Lesson 10 – Adding Difficulty
- Lesson 11 – Game Difficulty
- Lesson 12 – Game Expectations
- Lesson 13 – Adding A Score
- Lesson 14 – Sharing Your Game
Leave a Reply