Godot Game Engine Tutorial

Breakout Tutorial

Part 1

So this is what we're going to build. A simple breakout clone to demonstrate some of Godot's features.

If you haven't already done so, hop on over to godotengine.org and download the Godot engine. I'm currently using version 2.1.4. If you're using Godot 3.0, I can't promise that everything will be the same.

Open the Godot Engine and make a new project. I'm going to call mine 'breakout'. Save the project to somewhere on your computer.

We land on a new, blank project. Click the '2D' button at the top of the screen to change to 2D view. Right now our scene is empty. Lets put in a node so that we can start building our game.

On the right hand side of the screen is the Scene manager. Click the plus sign to add a new node. Search for a Node2D in the pop-up window and add it to the scene. You'll see that it appears in the scene manager. Double click on the node and rename it to world.

Next I'm goign to add my image files to the project. I'll do this in the explorer but just copying the ball.png, paddle.png, and brick.png files in the project directory on my computer.

Right click and save these images to your project directory.

Ball Brick Paddle

Right click the world node and add a new child. Search for Rigidbody2D. Rename the RigidBody2D to 'ball' and then right click it to add a new child node. This time search for Sprite and make sure it is a child of the ball. If you get the hierarchy wrong, dont panic. You can either drag and drop to reparent the node, or right click it, select 'reparent' and then find the correct parent node. In this case its our ball.

With the Sprite node selected, look at the Inspector. You'll find it below the Scene manager. Here we can edit the properties of our nodes. We need to set a texture. Click the field next to the texture label and load the ball image. Find the small arrow to the right of the texture field. Click it and you'll find more details. Under the flags field, turn off filter and mipmaps. This will keep our image nice and crisp.

Right click on the ball node and add a CollisionShape2D. In the inspector, Click the shape drop-down and add a new RectangleShape2D. Then click the little arrow beside this field and set the Extends to 10 x 10.

We need to change some properites on the ball to get it moving.

Set the Mass to 0.01 and the Weight to 0.1, the Friction to 0, and the Bounce to 1. Lastly, scroll down to Velocity and set the Linear Velocity to something like 200, 200.

Now is a good time to save our progress. Go to Scene at the top left of the editor and then Save Scene. I'm going to create a new folder called Scenes. I saved my file as 'world.tscn' which is the file format I like to use for my scenes.

At the top of the scene editor you'll find a series of tools: the select tool, the move tool, and the rotation tool. Click the move tool (it looks like a cross) and then drag the ball into the middle of the screen.

Now click on the Scenes button in the top left and go to project settings. In the projects settings panel, with the application tap selected, set the Main Scene field using the folder icon. Find 'world.tscn' in your project and select it.

Hit play and watch the ball fly off the screen. I think we need some walls to keep the ball from flying off the map.

Right click on the world node and add a new StaticBody2D. In the inspector, set the Friction of the StaticBody2D to 0 and the Bounce to 1. Give a it a CollisionBody2Das a child node and. Use either the inspector tab or the selector tool to drag out the shape,You can use the arrow by the input field to set the dimensions to seomtihng like 20x320. Name this shape wall_left. Snug the right edge of the wall against the vertical line of the camera's left edge.

Right click and select duplicate and drag the wall to the other side of the screen. Rename it wall_right. Duplicate another wall and this time rotate it 90 degrees using the inspector tab under the Transform section. Rename this to wall_top. Duplicate (Ctrl+d or Cmd+d) and drag it down to create wall_bottom. You should have four walls arranged into a box.

Now if you hit play, the ball will bounce around the screen. Not bad. And we haven't had to write any code yet. That's all about to change, next up is the paddle.

Part Two >