This video teaches you how to get started making games using the Godot Game Engine. We create the basic building blocks used in autoscroller games such as Geometry Dash.
About this video
Chapters:
In this video
Transcript
Intro ▶ 0:00
Have have you been laying Sleepless at night wondering how the heck are video games made then you have come to the right place today we're making our first game and since imitation is the sincerest form of flattery we'll be imitating Geometry Dash so let's take a
Geometry Dash ▶ 0:10
Look at the game we have a square that moves to the right at a constant speed and the player is able to press a button to make the jump we then have spikes that kill the player and we have different types of platforms that the player can jump on and there you have it let's get started we'll be using the
Install Godot ▶ 0:22
Gdau game engine to make our game I'm using version 4.3 so if you have any other version some small changes can be expected but it shouldn't affect things too much when you've downloaded the engine just start it up and create a new project we're now in the gdau editor if
Main Scene ▶ 0:35
We try to press play to run the project we get this error message saying that no main scene has been defined select one we haven't created one yet so that's what we'll have to do now everything in G do is made up of these things called scenes so your player will be a scene your level will be a scene and so on and the cool thing about this is that scenes can contain other scenes which is how we will be able to connect everything in the game together we'll create a scene of type node which will be the main entry of our game program the main scene is basically the root of our game everything else we want in our game will have to be created as a child of this scene we now have a scene with a single node which we will rename to main if we now try to run the game we get the same error message but now the button to select current is available let's press the button it first wants us to save the main scene that we created so let's do that after
That it runs the game and as you can see it's empty let's start let's change A View to a 2d View and let's create a new scene that will contain our level this new scene can inherit from node 2D that basically gives it a position in 2D space let's rename this node to level in the level we know that we want to have a player some spikes platforms and so on let's start by adding a player
Create Player ▶ 1:50
We can either press on this plus sign up here or we can rightclick our node and select ADD child node for our player we want to create a character body 2D we get this warning message here it says that the node has no shape so it can't Collide or interact with other objects consider adding a collision shape to D so let's do that and now we get another warning saying that a shape must be provided for this Collis shape our character will be a square so let's select a rectangle shape 2D now we have a collision shape if we run our program now it's still empty and that is because we don't have any graphics connected to the character yet so let's do that add the child note to the character body 2D select the Sprite 2D the Sprite needs a texture before we can add the texture we need to add the assets into our game Let's create a new folder here and call it assets I'm going to use assets created by K NL and it is the abstract platformer pack there's
A link in the description I will extract the blue player from the abstract platformer pack and paste that in there so as you can see we have a folder called Blue player and in that one we have a a bunch of images we have a Sprite for when the player duck dies Falls and so on let's add one of these to our player Sprite if we run our game now we can see up in the corner we have one quarter of the player showing and this is because you can see goo renders the game can see this faint blue line that is the game view so if we move our player down here and replay now he's more in the middle so you can see that our Sprite is showing let's reset that movement now we want to add some geometry that our player will walk on so let's go to our level add a child node
Create Level Using TileMapLayer ▶ 3:32
Add a tile map layer create a tile set configure a source for our tile set I've added this tile sheet as well which is basically a bigger texture containing a bunch of small squares that we can draw out using a TI map player add a source for the tile set click Atlas and select our tile sheet goddo asks if it wants us to automatically create tiles in the atlas let's press no now we can manually select which tiles we want from the tile sheet so let's select these three switch back to the tile map now we see that they are enabled if we select any one of these we will be able to draw them on this grid that is highlighted here so let's select the middle one as you can see we can start drawing our level as I said previously the the center of the game is still inside this Square so we need to move our whole level to center it in the screen so let's mark the level let's go to transform if we play our game now we can see we have our player and we
Have a small platform but now we want him to fall on the platform and we want the platform to catch him so let's add Logic for that highlight our character body 2D
Player Movement ▶ 4:32
Attach a new script let's name the script player let's delete this code we will write this ourselves so let's start adding some code for our player let's name our player script using class name this is so that we can use this script in other places of our code and that code will then know which functions we have defined here let's create a variable for our walk speed adding export makes it possible to change that value in the editor let's add a variable for our gravity let's hook up to the physics process add gravity to our y velocity time Delta to make it frame independent add walk speed to our x velocity and then finally call move and slide this will make the character body 2D actually move let's run our game and see what happens so the character falls through
TileSet Physics Layer Collisions ▶ 5:15
The level we need to add Collision to our tile map go back to the ti map layer let's add a physics layer if we now go to our tile set press the select tab let's select this tile expand physics physics layer zero let's start drawing the whole tile so now we've added a physics layer to our tile let's do that with the other two tiles if we try playing our game now we see that the character walks on the level but the Collision seems a bit off let's check our Collision shape let's fit it to our player let's run again and there we go we have a player moving now let's add a spike go to our
Create Spike ▶ 6:04
Level add a child node add an area to the node let's add a collider and let's add the shape we'll keep it simple with add a rectangle shape we need to add a Sprite we can see that we have spikes in our tile sheet so we'll add a atlas texture expand that load in our tile sheet and we obviously don't want the whole tile sheet as a Sprite so we need to press this edit region button navigate to the spikes you want to use and then just draw a rectangular around them like so and close that and now we have spikes let's fit the Collision shape to the spikes there we go now we need to add some code that kills the player when we collide with the spikes let's add a script to our Spike let's Nam the script Spike what we want to do now is use something called signals so if we press our area 2D we press the node tab we can see that we have a few signals that will fire when specific events occur we have a signal that's called body entered and this will
Be called when the player collides with the spike area 2D so let's double click this and now we need to select the method that will be called select our area 2D and press connect this will create a function for us and this green icon here shows that it's connected to the area 2D when the
Load Levels Through Code ▶ 7:32
Player collides with the spike we want to reload the level so let's add a script to the main node let's call it Main and let's define a function that reloads a level let's also add a class name to this script let's go back to the Spike let's check if the body that's entered is the player and if it is we'll drag this main into the script and let's cast it as Main and now we'll be able to use the function defined in our main script reload the level so now let's jump into our main script and let's write this reload level function to be able to reload this level we'll first need to save it as a packed scene the way we can do that is by dragging it down to our assets and naming it level.
TSN now you can see that the level is defined somewhere else we just have a reference to it here in our main node let's delete it for now and try reloading it from script we'll want the reference to the current level so let's add that we'll also have to load the packed scene that we saved of the level so let's create a VAR name it level scene and assign it to preload and now let's try to find our level TSN asset there it is and this complains because we don't have anything called the level we haven't created a script for the level yet so let's remove this let's add in the the function ready this is run as soon as the node is created so when main loads we want to load the level scene and we want to assign it to current level and we do that by calling instantiate on the level scene and assign that to current level now whenever we want to reload the level we want to destroy the current level and reload it as we did in our ready function there
We go let's see if this works then nothing happens and the reason nothing happens is because we forgot to add the current level to our main node as a child and we'll need to do this as well when we reload let's run
Make The Player Jump ▶ 9:33
The game and there you go the player hits the spikes and the level reloads and now we need to add a jump for the player so that he isn't stuck in this endless loop of death what we have to do first is go into our project settings go into our input map add a new action call it jump close it go back to the player add a variable for jump velocity make it negative because the gravity is positive let's connect our player to the input function this function is fired every time we get an input event let's check if the player is on the floor and then we'll check if the event that is pressed is the jump action that we created earlier and if it is then set up the Y velocity to jump velocity let's go back to the input settings we need to add an event so this is the actual button that will fire the jump event I will use space press okay and close it and now let's see if this works if we run our game we die and then I will try to jump
Conclusion And Finished Game ▶ 10:30
And then we fall to our death and there you have it your first endless Runner I'll show you how it can look if you spend a bit more time adding levels adding animations sound menus let's jump forward in time so let's see how the game has evolved we fleshed out the levels added animations and the goal and the menu with the button and then a few levels and that's it thanks for watching let me know if you have any questions or if you would like to dive deeper into any other subject concerning Gau or game development as I said previously I'll put the code on my GitHub and you can find the link in the video description thanks for watching