Godot 4 Game Development Projects - Chris Bradfield - E-Book

Godot 4 Game Development Projects E-Book

Chris Bradfield

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Godot 4.0 is one of the most sought-after open-source game engines, and if you’re enthusiastic about exploring its features, then this book is for you. Written by an author with over twenty-five years of experience, the Godot 4 Game Development Projects introduces the Godot game engine and its feature-rich 4.0 version. With an array of new capabilities, Godot 4.0 is a strong alternative to expensive commercial game engines. If you’re a beginner, this book will help you learn game development techniques, while experienced developers will understand how to use this powerful and customizable tool to bring their creative visions to life.
This updated edition consists of five projects with an emphasis on the 3D capabilities of the engine that will help you build on your foundation-level skills through small-scale game projects. Along the way, you’ll gain insights into Godot’s inner workings and discover game development techniques that you can apply to your projects.
Using a step-by-step approach and practical examples, this book covers everything from the absolute basics to sophisticated game physics, animations, and much more. By the time you complete the final project, you’ll have a strong foundation for future success with Godot 4.0 and you’ll be well on your way to developing a variety of games.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 316

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Godot 4 Game Development Projects

Second Edition

Build five cross-platform 2D and 3D games using one of the most powerful open source game engines

Chris Bradfield

BIRMINGHAM—MUMBAI

Godot 4 Game Development Projects

Second Edition

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Kaustubh Manglurkar

Senior Content Development Editor: Feza Shaikh

Technical Editor: Simran Ali

Copy Editor: Safis Editing

Project Coordinator: Aishwarya Mohan

Proofreader: Safis Editing

Indexer: Hemangini Bari

Production Designer: Ponraj Dhandapani

Marketing Coordinators: Anamika Singh, Namita Velgekar, and Nivedita Pandey

First published: June 2018

Second edition: August 2023

Production reference: 1110723

Packt Publishing Ltd

Grosvenor House

11 St Paul's Square

Birmingham

B3 1RB UK.

ISBN 978-1-80461-040-4

www.packtpub.com

To Priya, for being a constant source of support and encouragement.

To my students at the Science Academy STEM Magnet for being my guinea pigs, and for teaching me how to be a better teacher.

-Chris Bradfield

Contributors

About the author

Chris Bradfield has worked in the internet technology space for more than 25 years. He has worked in the online gaming space for a number of successful MMOs and social gaming publishers in South Korea and the United States. Throughout his game industry career, he has served as a game designer, developer, product manager, and business development executive.

In 2012, he discovered a love for teaching and founded KidsCanCode to provide programming instruction and curricula to middle- and high-school students. He also produces video- and text-based tutorials and other learning resources for game development students around the world.

I would like to express my gratitude to Kenney Vleugels (@kenneyNL) for the 3D Minigolf tiles, skorpio for the spaceship art, Luis Zuno (@ansimuz), and for Sunny Land art for their work.

About the reviewer

In the land of Indonesia, Isaiah Jamiel stands as a masterful artisan skilled in the realms of .NET and Godot. Leading NTC Studios alongside Izra, Hansen, Sachio, Shannon, Della, and Yesika, he aspires to achieve success in the realm of game development. Jamiel’s artistic talents extend beyond coding, as he breathes new life into traditional Indonesian music with his arrangements. Yet amidst his passion for code and music, his heart finds solace in the unwavering love he holds for his beloved Valerie and his cherished family. Isaiah Jamiel’s unwavering commitment to blending innovation, artistry, and profound connections serves as the driving force behind his remarkable endeavors in both the realm of technology and the world of music.

Table of Contents

Preface

1

Introduction to Godot 4.0

General advice

The secret to learning effectively

What is a game engine?

What is Godot?

Downloading Godot

Alternate installation methods

Overview of the Godot UI

Project Manager

Editor window

Learning about nodes and scenes

Scripting in Godot

About GDScript

Summary

2

Coin Dash – Build Your First 2D Game

Technical requirements

Setting up the project

Vectors and 2D coordinate systems

Part 1 – the player scene

Creating the scene

Sprite animation

Collision shape

Scripting the player

Moving the player

Choosing animations

Starting and ending the player’s movement

Preparing for collisions

Part 2 – the coin scene

The node setup

Coin script

Part 3 – the Main scene

Node setup

Main script

Starting a new game

Part 4 – the user interface

Node setup

Message label

Score and time display

Score and time display

Updating the UI via GDScript

Game over

Adding HUD to Main

Part 5 – finishing up

Visual effects

Sound

Powerups

Coin animation

Obstacles

Summary

3

Space Rocks: Build a 2D Arcade Classic with Physics

Technical requirements

Setting up the project

Rigid body physics

The player’s ship

Body and physics setup

State machines

Adding player controls

Screen wrap

Shooting

Adding the rocks

Scene setup

Variable size rocks

Instantiating rocks

Exploding rocks

Creating the UI

Layout

Scripting the UI

The Main scene’s UI code

Player code

Ending the game

Detecting collisions between rigid bodies

Pausing the game

Enemies

Following a path

Enemy scene

Moving the enemy

Spawning enemies

Shooting and collisions

Player shield

Sound and visual effects

Sound and music

Particles

Enemy trail

Summary

4

Jungle Jump – Running and Jumping in a 2D Platformer

Technical requirements

Setting up the project

Introducing kinematic bodies

Collision response

Creating the player scene

Collision layers and masks

About AnimationPlayer

Animations

Collision shape

Finishing the player scene

Player states

Player script

Player movement

Player health

Collectible items

Scene setup

Collectible script

Designing the level

Using TileMaps

Designing the first level

Adding dangerous objects

Scrolling background

Adding enemies

Scene setup

Scripting the enemy

Damaging the enemy

Player script

Game UI

Scene setup

Scripting the HUD

Attaching the HUD

Title screen

Scene setup

Setting up the main scene

Transitioning between levels

Door scene

Screen settings

Finishing touches

Sound effects

Double jumping

Dust particles

Ladders

Moving platforms

Summary

5

3D Minigolf: Dive into 3D by Building a Minigolf Course

Technical requirements

Introduction to 3D

Orienting in 3D space

Godot’s 3D editor

Adding 3D objects

Global versus local space

Transforms

Meshes

Cameras

Project setup

Creating the course

Understanding GridMaps

Drawing the first hole

Environment and lighting

Adding the hole

Making the ball

Testing the ball

Improving ball collisions

Adding UI

Aiming the arrow

UI display

Scripting the game

UI code

Main script

Ball script

Testing it out

Option 1 for improving aiming

Option 2 for improving aiming

Camera improvements

Designing a full course

Visual effects

Adding materials

Lighting and Environment

Summary

6

Infinite Flyer

Technical requirements

Project setup

Inputs

Airplane scene

Collision shapes

Scripting the plane

Building the world

World objects

Chunks

Main scene

Spawning new chunks

Increasing difficulty

Collisions

Fuel and score

Title screen

Audio

Saving a high score

About file locations

Accessing files

Suggestions for additional features

Summary

7

Next Steps and Additional Resources

Using Godot’s documentation

Reading the API documentation

Version control – using Git with Godot

Using Blender with Godot

Import hints

Using blend files

Exporting projects

Getting the export templates

Export presets

Exporting

Exporting for specific platforms

Introduction to shaders

Creating a 2D shader

3D shaders

Learning more

Using other programming languages in Godot

C#

Other languages – GDExtension

Getting help – community resources

Godot Recipes

Contributing to Godot

Contributing to the engine

Writing documentation

Donations

Summary

Final words

Index

Other Books You May Enjoy

Preface

This book is an introduction to the Godot game engine and its new version, 4. Godot 4 has a large number of new features and capabilities that make it a strong alternative to expensive commercial game engines. For beginners, it offers a friendly way to learn game development techniques. For more experienced developers, Godot is a powerful, customizable tool for bringing visions to life.

This book takes a project-based approach to learning how to use Godot. It consists of five projects, along with additional resources, that will help developers achieve a sound understanding of how to use Godot to build games.

Who this book is for

This book is for anyone who wants to learn how to make games using a modern game engine. New users and experienced developers alike will find it a helpful resource. Some programming experience is recommended.

What this book covers

This book is a project-based introduction to using the Godot game engine. Each of the five game projects builds on the concepts learned in the previous projects.

Chapter 1, Introduction to Godot 4.0 introduces the concept of game engines in general and Godot specifically, including how to download Godot and how to effectively use this book.

Chapter 2, Coin Dash – Build Your First 2D Game, is a small 2D game that demonstrates how to create scenes and work with Godot’s node system. You’ll learn how to navigate the Godot editor and write your first scripts in GDScript.

Chapter 3, Space Rocks: Build a 2D Arcade Classic with Physics, demonstrates working with physics bodies to create an Asteroids-style space game.

Chapter 4, Jungle Jump – Running and Jumping in a 2D Platformer, involves a side-scrolling platform game in the spirit of Super Mario Bros. You’ll learn about kinematic bodies, animation states, and level design using tile maps.

Chapter 5, 3D Minigolf: Dive into 3D by Building a Minigolf Course, extends the previous concepts into three dimensions. You’ll work with meshes, lighting, and camera control.

Chapter 6, Infinite Flyer, continues exploring 3D development, covering dynamic content, procedural generation, and more 3D techniques.

Chapter 7, Next Steps and Additional Resources, covers even more topics to explore once you’ve mastered the material in the five game projects. Look here for links and tips to further expand your game development skills.

To get the most out of this book

To best understand the example code in this book, you should have a general knowledge of programming, preferably with a modern, dynamically-typed language such as Python or JavaScript. If you’re new to programming entirely, you may wish to review a beginner tutorial before diving into the game projects here.

Godot will run on any relatively modern PC running Windows, MacOS, or Linux operating systems.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Godot-4-Game-Development-Projects-Second-Edition. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/lY2hq.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “With Godot 4, you have an additional option: importing .blend files directly into your Godot project.”

A block of code is set as follows:

shader_type canvas_item; void fragment() { // Place fragment code here. }

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “The first property is Shader, where you can choose New Shader. When you do, a Create Shaderpanel appears.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Godot 4 Game Development Projects, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

Scan the QR code or visit the link below

https://packt.link/free-ebook/9781804610404

Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directly

1

Introduction to Godot 4.0

Whether it’s a career goal or a recreational hobby, game development is a fun and rewarding endeavor. There’s never been a better time to get started in game development. Modern programming languages and tools have made it easier than ever to build high-quality games and distribute them to the world. If you’re reading this book, then you’ve set your feet on the path to making the game(s) of your dreams.

This book is an introduction to the Godot Game Engine and its new 4.0 version, which was released in 2023. Godot 4.0 has a large number of new features and capabilities that make it a strong alternative to expensive commercial game engines. For beginners, it offers a friendly way to learn game development fundamentals. For more experienced developers, Godot is a powerful, customizable, and open toolkit for bringing your visions to life.

This book takes a project-based approach that will introduce you to the fundamentals of the engine. It consists of five game projects that are designed to help you achieve a sound understanding of game development concepts and how they’re applied in Godot. Along the way, you will learn how Godot works and absorb important techniques that you can apply to your own projects.

In this chapter, we’ll cover the following topics:

General advice for getting startedWhat is a game engine?What is Godot?Downloading GodotOverview of the Godot UINodes and scenesScripting in Godot

General advice

This section contains some general advice to readers, based on the author’s experience as a teacher and lecturer. Keep these tips in mind as you work through the book, especially if you’re very new to programming.

Try to follow the projects in the book in order. Later chapters may build on topics that were introduced in earlier chapters, where they are explained in more detail. When you encounter something that you don’t remember, go back and review that topic in the earlier chapter. No one is timing you, and there’s no prize for finishing the book quickly.

There is a lot of material to absorb here. Don’t feel discouraged if you don’t get it at first. The goal is not to become an expert in game development overnight – that’s just not possible. Just like with any other skill – carpentry or a musical instrument, for example – it takes years of practice and study to develop proficiency. Repetition is the key to learning complex topics; the more you work with Godot’s features, the more familiar and easier they will start to seem. Try repeating one of the earlier chapters after you reach the end. You’ll be surprised at how much more you’ll understand compared to the first time you read it.

If you’re reading this as an e-book, resist the temptation to copy and paste the code. Typing the code yourself will engage your brain more actively. It’s similar to how taking notes during a lecture helps you learn better than just listening, even if you never look back at the notes. If you’re a slow typist, it will also help you work on your typing speed. In a nutshell: you’re a programmer, so get used to typing code!

One of the biggest mistakes that new game developers make is taking on a bigger project than they can handle. It is very important to keep the scope of your project as small as possible when starting out. You will be much more successful (and learn more) if you finish two or three small games than if you have a large, incomplete project that has grown beyond your ability to manage.

You’ll notice that the five games in the book follow this strategy very strictly. They are all small in scope, both for practical reasons – to fit reasonably into book-sized lessons – but also to remain focused on practicing the basics. As you build the game, you will likely find yourself thinking of additional features and gameplay elements right away. What if the spaceship had upgrades?What if the character could do wall jumps?

Ideas are great, but if you haven’t finished the basic project yet, write them down and save them for later. Don’t let yourself be sidetracked by one “cool idea” after another. Developers call this feature creep, meaning a list of features that never stops growing, and it’s a trap that has led to many an unfinished project. Don’t fall victim to it.

Finally, don’t forget to take a break now and again. You shouldn’t try and power through the whole book, or even one project, in just a few sittings. After each new concept, and especially after each chapter, give yourself time to absorb the new information before you dive into the next one. You’ll find that you not only retain more information, but you’ll probably enjoy the process more.

The secret to learning effectively

Here’s the secret to getting the most out of these projects and increasing your skills in a way that makes them stick: at the end of each chapter, once you’ve finished building the game project, immediately delete it and start over. This time, try and re-create it without looking at the book. If you get stuck, just look at that part in the chapter, and then close the book again. If you really feel confident, try adding your own spin to the game – change some parts of the gameplay or add a new twist.

If you do this multiple times with each of the games, you’ll be amazed at how less often you’ll need to check the book. If you can make the projects in this book on your own without help, then you’re surely ready to branch out and take on your original concepts.

Keep these tips in mind as you read through the following sections. In the next section, you’ll learn what a game engine is and why game developers might want to choose to use one.

What is a game engine?

Game development is complex and involves a wide variety of knowledge and skills. To build a modern game, you need a great deal of underlying technology before you can make the actual game itself. Imagine that you had to build your computer and write your own operating system before you could even start programming. Game development would be a lot like that if you truly had to start from scratch and make everything that you need.

There are also a number of common needs that every game has. For example, no matter what the game is, it’s going to need to draw things on the screen. If the code to do that has already been written, it makes more sense to reuse it than to create it all over again for every game. That’s where game frameworks and engines come in.

A game framework is a set of libraries with helper code that assists in building the foundational parts of a game. It doesn’t necessarily provide all the pieces, and you may still have to write a great deal of code to tie everything together. Because of this, building a game with a game framework can take more time than one built with a full game engine.

A game engine is a collection of tools and technologies designed to ease the process of game-making by removing the need to reinvent the wheel for each new game project. It provides a collection of commonly needed functionality that often would require a significant investment in time and effort to develop.

Here are some of the main features a typical game engine will provide:

Rendering (2D and 3D): Rendering is the process of displaying the game on the player’s screen. A good rendering pipeline must take into account modern GPU support, high-resolution displays, and effects such as lighting, perspective, and viewports, all while maintaining a very high framerate.Physics: While a very common requirement, building a robust and accurate physics engine is a monumental task. Most games require some sort of collision detection and response system, and many need physics simulations, but few developers want to take on the task of writing one - especially if they have never tried to do so before!Platform support: In today’s market, most developers want to be able to release their games on multiple platforms, such as desktops, consoles, mobile, and/or the web. A game engine provides a unified exporting process to publish games on multiple platforms without needing to rewrite game code or support multiple versions.Common development environment: By using the same unified interface to make multiple games, the developer doesn’t have to re-learn a new workflow every time they start a new project.

In addition to these, there will be tools to assist with features such as networking, easing the process of managing images and sound, animations, debugging, and many more. Often, game engines will include the ability to import content from other tools, such as those used to create animations or 3D models.

Using a game engine allows the developer to focus on building their game rather than creating the underlying framework needed to make it work. For small or independent developers, this can mean the difference between releasing a game after one year of development instead of three, or even never at all.

There are dozens of popular game engines on the market today, such as Unity, Unreal Engine, and GameMaker Studio, just to name a few. An important fact to be aware of is that the majority of popular game engines are commercial products. They may or may not require any financial investment to get started, but they will require some kind of licensing and/or royalty payments if your game makes money. Whatever engine you choose, you need to carefully read the user agreement and make sure you understand what you are and are not allowed to do with the engine, and what hidden costs, if any, you may be responsible for.

On the other hand, some engines are non-commercial and open source, such as the Godot game engine, which is what this book is all about.

What is Godot?

Godot is a fully featured modern game engine, providing all of the features described in the previous section and more. It is also completely free and open source, released under the very permissive MIT license. This means there are no fees, no hidden costs, and no royalties to pay on your game’s revenue. Everything you make with Godot 100% belongs to you, which is not the case with many commercial game engines that require an ongoing contractual relationship. For many developers, this is very appealing.

If you’re not familiar with the concept of open source, community-driven development, this may seem strange to you. However, much like the Linux kernel, Firefox browser, and many other very well-known pieces of software, Godot is not developed by a company as a commercial product. Instead, a dedicated community of passionate developers donates their time and expertise to building the engine, testing and fixing bugs, producing documentation, and more.

As a game developer, the benefits of using Godot are many. Because it is unencumbered by commercial licensing, you have complete control over exactly how and where your game is distributed. Many commercial game engines restrict the types of projects you can make or require a much more expensive license to build games in certain categories, such as gambling.

Godot’s open source nature also means there is a level of transparency that doesn’t exist with commercial game engines. For example, if you find that a particular engine feature doesn’t quite meet your needs, you are free to modify the engine itself and add the new features you need, with no permission required. This can also be very helpful when debugging a large project because you have full access to the engine’s internal workings.

It also means that you can directly contribute to Godot’s future. See additional topics in Chapter 7 for more information about how you can get involved with Godot development.

Now that you have an understanding of what Godot is and how it can help you build a game, it’s time to get started. In the next section, you’ll see how to download Godot and set it up for use on your own computer.

Downloading Godot

You can download the latest version of Godot by visiting https://godotengine.org/ and clicking Download Latest. This book is written for version 4.0. If the version you download has another number at the end (such as 4.0.3), that’s fine – this just means that it includes updates to version 4.0 that fix bugs or other issues.

On the download page, you will also see a standard version and a .NET version. The .NET version is specially built to be used with the C# programming language. Don’t download this one unless you plan to use C# with Godot. The projects in this book do not use C#.

Figure 1.1: The Godot download page

Unzip the downloaded file, and you’ll have the Godot application. Optionally, you can drag it to your Programs or Applications folder, if you have one. Double-click the application to launch it and you’ll see Godot’s Project Manager window, which you’ll learn about in the next section.

Alternate installation methods

There are a few other ways to get Godot on your computer besides downloading it from the Godot website. Note that there is no difference in functionality when installed this way. The following are merely alternatives for downloading the application:

Steam: If you have an account on Steam, you can install Godot via the Steam desktop application. Search for Godot in the Steam store and follow the instructions to install it. You can launch Godot from the Steam application:

Figure 1.2: The Godot engine on Steam

Itch.io: You can also download Godot from the popular itch.io website. Itch is a marketplace for independent game developers and creators. Search for Godot and download it from the provided links.Package Managers: If you’re using one of the following operating system package managers, you can install Godot via its normal installation process. See the documentation for your package manager for details. Godot is available in these package managers:Homebrew (macOS)Scoop (Windows)Snap (Linux)

Android and web versions

You will also see downloads available for Godot versions that run on Android and in your web browser. At the time of this writing, these versions are listed as “experimental” and may not be stable or fully functional. It is recommended that you use the desktop version of Godot, especially while you’re learning.

Congratulations, you have successfully installed Godot on your computer. In the next section, you will see an overview of Godot’s editor interface – the purposes of the various windows and buttons you’ll use when working with the editor.

Overview of the Godot UI

Like most game engines, Godot has a unified development environment. This means that you use the same interface to work on all of the aspects of your game – code, visuals, audio, and so on. This section is an introduction to the interface and its parts. Take note of the terminology used here; it will be used throughout this book when referring to actions you’ll take in the editor window.

Project Manager

The Project Manager window is the first window you’ll see when you open Godot:

Figure 1.3: Project Manager

Opening Godot for the first time

The first time you open Godot, you won’t have any projects yet. You’ll see a pop-up window asking if you want to explore official example projects in the Asset Library. Select Cancel, and you’ll see the Project Manager as it appears in the preceding screenshot.

In this window, you can see a list of your existing Godot projects. You can choose an existing project and click Run to play the game or Edit to work on it in the Godot editor. You can also create a new project by clicking New Project:

Figure 1.4: New project settings

Here, you can give the project a name and create a folder to store it in. Note the warning message – a Godot project is stored as a separate folder on the computer. All the files that the project uses must be located in this folder. This makes it convenient to share Godot projects because you only need to zip the project folder and you can be confident that another Godot user will be able to open it and not be missing any necessary data.

Renderer

When creating a new project, you also have the choice of Renderer. The three options represent the balance between advanced, high-performance graphics that require a modern desktop GPU, and compatibility with less-capable platforms such as mobile and older desktops. You can change this option later if you need, so it’s OK to leave it as the default setting. If you later decide to build games for the mobile platform, the Godot documentation has a great deal of information regarding performance and rendering options. See Chapter 7 for links and more information.

Choosing filenames

When you’re naming your new project, there are a few simple rules you should try and follow that may save you some trouble in the future. Give your project a name that describes what it is – Wizard Battle Arena is a much better project name than Game #2. In the future, you’ll never be able to remember which game number two was, so be as descriptive as possible.

You should also think about how you name your project folder and the files in it. Some operating systems are case-sensitive and distinguish between My_Game and my_game, while others do not. This can lead to problems if you move your project from one computer to another. For this reason, many programmers develop a standardized naming scheme for their projects, such as not using spaces in filenames and using _ between words. Regardless of what naming scheme you adopt, the most important thing is to be consistent.

Once you’ve created the project folder, the Create Edit button will open the new project in the editor window. Try it now: create a project called test_project.

Console window

If you’re using a version of the Windows operating system, you’ll also see a console window open when you run Godot. In this window, you can see warnings and errors produced by the engine and/or your project. This window doesn’t appear on macOS or Linux, but you can see the console output if you launch the application from the command line using a Terminal program

Editor window

The following figure is a screenshot of the main Godot editor window. This is where you will spend most of your time when building projects in Godot. The editor interface is divided into several sections, each offering different functionality. The specific terminology for each section is described after Figure 1.5:

Figure 1.5: The Godot editor window

The main portion of the editor window is the Viewport. This is where you’ll see the parts of your game as you’re working on them.

In the top center of the window is a list of the Workspaces you can switch between when working on different parts of your game. You can switch between 2D and 3D mode, as well as Script mode, where you’ll edit your game’s code. AssetLib is a place where you can download add-ons and example projects contributed by the Godot community. See Chapter 7 for more information about using the asset library.

Figure 1.6 shows the toolbar for the current workspace you’re using. The icons here will change based on what kind of object you’re working with:

Figure 1.6: Toolbar icons

The buttons in the upper-right playtest area are for launching the game and interacting with it when it’s running:

Figure 1.7: Playtest buttons

On the left and right sides are the Docks or Tabs you can use to view and select game items and set their properties. On the bottom of the left-hand dock, you’ll find the FileSystem tab. All the files in the project folder are shown here, and you can click on folders to open them and see what they contain. All resources in your project will be located relative to the res:// path, which is the project’s root folder. For example, a file path might look like this: res://player/player.tscn. This refers to a file in the player folder:

Figure 1.8: The FileSystem tab

At the top of the left-hand dock is the Scene tab, which shows the current scene you are working on in the viewport (more about scenes after Figure 1.9):

Figure 1.9: The Scene tab

On the right-hand side, you’ll find a box labeled Inspector, where you can see and adjust the properties of your game objects.

As you work through the game projects in this book, you’ll learn about the functionality of these items and become familiar with navigating the editor interface.

After reading this section, you should feel comfortable with the layout of the Godot editor window and the names of the elements you’ll be seeing throughout the book. You’re one step closer to finishing this introduction and getting started on a game. First, though, did you notice those items in Figure 1.9? Those are called nodes, and you’ll find out what they’re all about in the next section.

Learning about nodes and scenes

Nodes are the basic building blocks for creating games in Godot. A node is an object that can give you a variety of specialized game functions. A given type of node might display an image, play an animation, or represent a 3D model. The node contains a collection of properties, allowing you to customize its behavior. Which nodes you add to your project depends on what functionality you need. It’s a modular system designed to give you flexibility in building your game objects.

The nodes you add are organized into a tree structure. In a tree, nodes are added as children of other nodes. A particular node can have any number of children, but only one parent node. When a group of nodes is collected into a tree, it is called a scene:

Figure 1.10: Nodes arranged in a tree

Scenes in Godot are typically used to create and organize the various game objects in your project. You might have a player scene that contains all the nodes and scripts that make the player’s character work. Then, you might create another scene that defines the game’s map: the obstacles and items that the player must navigate through. You can then combine these various scenes into the final game.

While nodes come with a variety of properties and functions, any node’s behavior and capabilities can be extended by attaching a script to the node. This allows you to write code that makes the node do more than it can do in its default state. For example, you can add a Sprite2D node to display an image, but if you want that image to move or disappear when clicked, you’ll need to add a script to create that behavior.

Nodes are powerful tools, and understanding them is the key to effectively building game objects in Godot. However, on their own, they can only do so much. It’s still up to you to provide the game logic – the rules that objects in your game will follow. In the next section, you can see how that’s done by writing code using Godot’s scripting language.

Scripting in Godot

Godot provides two official languages for scripting nodes: GDScript and C#. GDScript is the dedicated built-in language, providing the tightest integration with the engine, and is the most straightforward to use. For those that are already familiar or proficient with C#, you can download a version that supports that language.

In addition to the two supported languages, Godot itself is written in C++, and you can get even more performance and control by extending the engine’s functionality directly. See Additional topics in Chapter 7 for information on using other languages and extending the engine.

All the games in this book will use GDScript. For the majority of projects, GDScript is the best choice of language. It is tightly integrated with Godot’s Application Programming Interface (API) and is designed for rapid development.

About GDScript

GDScript’s syntax is very closely modeled on the Python language. If you are familiar with Python already, you will find GDScript very familiar. If you are comfortable with another dynamic language, such as JavaScript, you should find it relatively easy to learn. Python is very often recommended as a good beginner language, and GDScript shares that user-friendliness.