50,39 €
Godot Engine Game Development Projects is an introduction to the Godot game engine and its new 3.0 version. Godot 3.0 brings a large number of new features and capabilities that make it a strong alternative to expensive commercial game engines. For beginners, Godot offers a friendly way to learn game development techniques, while for experienced developers it is a powerful, customizable tool that can bring your visions to life.
This book consists of five projects that will help developers achieve a sound understanding of the engine when it comes to building games.
Game development is complex and involves a wide spectrum of knowledge and skills. This book can help you build on your foundation level skills by showing you how to create a number of small-scale game projects. Along the way, you will learn how Godot works and discover important game development techniques that you can apply to your projects.
Using a straightforward, step-by-step approach and practical examples, the book will take you from the absolute basics through to sophisticated game physics, animations, and other techniques. Upon completing the final project, you will have a strong foundation for future success with Godot 3.0.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 298
Veröffentlichungsjahr: 2018
Copyright © 2018 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.
Acquisition Editor: Nigel FernandesContent Development Editor: Jason PereiraTechnical Editor:Rutuja VazeCopy Editor:Safis EditingProject Coordinator:Sheejal ShahProofreader: Safis EditingIndexer: Mariammal ChettiyarGraphics: Disha HariaProduction Coordinator:Shraddha Falebhai
First published: June 2018
Production reference: 1270618
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78883-150-5
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
In December 2014, Godot Engine 1.0 was released. With this first public release, the feature-packed, free, and open source project delivered on its promise of a cross-platform, easy-to-use, and powerful game creation tool.
I fell in love with Godot's high-level features and its permissive license, so I jumped right in, with no prior game development experience. I felt a bit lost when I first opened the editor. I moved on to the online documentation and started reading the well-written, step-by-step introduction. It covered basic concepts, such as scenes and nodes and the GDScript programming language, and it showed how to create a Pong clone, and that was basically it, at that time. There were some more tutorials on advanced features, but there was a gap between them and the first guide. As a complete beginner, I was stuck with the following question: how do I make my first game? Yet, I kept exploring, and with the help of the Godot community, I could eventually build a simple 2D game with a local multiplayer. What a feeling to see your first game on the screen!
Fast-forward to 3 years from then, Godot has grown a lot as a project, a community, and an engine. Godot 3.0 was released in January 2018 after 18 months of work. It brought this free, community-driven project to the level of its proprietary counterparts for 2D and 3D game development. The beginner game developer that I was became a project manager, helping to organize and focus the work of hundreds of contributors revolving around the engine. Working together with people from all around the world improved all areas of the project: engine features, usability, localization, and, of course, documentation. Thanks to many dedicated contributors, Godot's documentation became one of the most accessible technical resources that I have seen in free and open source projects. This is in great part thanks to Chris Bradfield, the author of this book, who spent countless hours writing new material and reviewing contributions to ensure their accuracy and quality of writing.
With this book, Chris goes one step further and provides a thorough answer to that question (how do I make my first game?), shared by many Godot beginners. Indeed, he goes beyond that, as Godot Engine Game Development Projects will lead you through the creation of five full-featured games—four in 2D and one in 3D. Each game introduces new features and concepts of Godot so that you can learn how and when to use them in your own creations. Advanced users with experience in other game development tools (or even Godot itself) will learn how to use Godot's unique architecture and features to write better, more maintainable code through Chris' showcase of best practices.
From setting up Godot for the first time on your computer to publishing your own games to a wide range of platforms, Chris runs you through all the steps in a concise yet thorough way. After the first lesson, you should already be able to see how straightforward and accessible game development can be with a tool such as Godot, even if you had no prior experience in game creation. You will also feel a great sense of accomplishment seeing your own creation playing on your computer or smartphone, with the power to implement new gameplay elements with just a few lines of code. I wish you a lot of fun on your game development journey, and a warm welcome to the Godot community.
Rémi Verschelde
Godot Engine – Project Manager
Chris Bradfieldhas beenworking 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 his love for teaching and founded KidsCanCode to provide programming instruction and curriculum to middle and high school students. He is also a member of the Godot Engine documentation team and works to provide learning resources for game development students around the world.
Max Hilbrunner is a Godot Engine contributor and CTO at aiPhilos and works on providing better product search experiences using artificial intelligence, natural language processing, and machine learning in cooperation with the German Research Center for Artificial Intelligence (DFKI).
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Godot Engine Game Development Projects
Dedication
www.packtpub.com
Why subscribe?
PacktPub.com
Foreword
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Introduction
General advice
What is a game engine?
What is Godot?
Downloading Godot
Alternate installation methods
Overview of the Godot UI
Project Manager
Choosing filenames
Editor window
About nodes and scenes
Scripting in Godot
About GDScript
Summary
Coin Dash
Project setup
Vectors and 2D coordinate systems
Vectors
Pixel rendering
Part 1 – Player scene
Creating the scene
Sprite animation
Collision shape
Scripting the Player
Moving the Player
About delta
Choosing animations
Starting and Ending the Player's Movement
Preparing for collisions
Part 2 – Coin scene
Node setup
Using groups
Script
Part 3 – Main scene
Node setup
Main script
Initializing
Starting a new game
Checking for remaining coins
Part 4 – User Interface
Node setup
Anchors and margins
Message label
Score and time display
Containers
Updating UI via GDScript
Using buttons
Game over
Adding the HUD to Main
Part 5 – Finishing up
Visual effects
What is a tween?
Sound
Powerups
Coin animation
Obstacles
Summary
Escape the Maze
Project setup
Project organization
Inheritance
Character scene
Animations
Collision detection
Character script
Player scene
Player script
Enemy scene
Optional – turn-based movement
Creating the level
Items
TileSets
Creating a TileSet
TileMaps
Level script
Adding more levels
Game flow
Start and end screens
Globals
Global script
Score
Saving the High Score
Reading and writing files
Finishing touches
Death animation
Sound effects
Summary
Space Rocks
Project setup
Rigid body physics
Player ship
Body setup and physics
State machines
Controls
Screen wrap
Shooting
Bullet scene
Firing bullets
Rocks
Scene setup
Variable size
Instancing
Exploding rocks
Explosion scene
Adding to Rock
Spawning smaller rocks
UI
Layout
UI functions
Main scene code
Player code
Game over
Detecting collisions between physics bodies
Pausing the game
Enemies
Following a path
Enemy scene
Moving the Enemy
Spawning enemies
Enemy shooting and collisions
Additional features
Sound/music
Particles
Enemy trail
Player shield
Summary
Jungle Jump (Platformer)
Project setup
Introducing kinematic bodies
Collision response
move_and_collide
move_and_slide
Player scene
Collision Layer/Mask
Sprite
Collision shape
Shapes
Animations
Finishing up the scene tree
Player states
Player script
Player movement
Testing the moves
Player health
Collectible items
Collectible scene
Collectible script
Designing the level
TileSet configuration
Base-level setup
Designing the first level
Scrolling background
Dangerous objects
About slide collisions
Enemies
Scene setup
Script
Damaging the enemy
HUD
Scene setup
Script
Attaching the HUD
Title screen
Scene setup
Main scene
Level transitions
Door scene
Finishing touches
Sound effects
Infinite falling
Double jump
Dust particles
Crouching state
Climbing ladders
Player code
Level code
Moving platforms
Summary
3D Minigolf
Introduction to 3D
Orienting in 3D space
Godot's 3D editor
Adding 3D objects
Global versus Local Space
Transforms
Transforms in code
Meshes
Importing meshes
Primitives
Multiple meshes
Cameras
Project setup
Creating the course
GridMaps
Making a MeshLibrary
Drawing the course
WorldEnvironment
Finishing the scene
Ball
Testing the ball
Improving collisions
UI
Aiming arrow
UI display
Scripts
UI
Main
Ball
Hole
Testing it out
Improving aiming – option 1
Improving aiming – option 2
Camera improvements
Multiple cameras
Orbiting camera
Creating a gimbal
Tracking camera
Visual effects
SpatialMaterials
Environment options
Lighting
Summary
Additional Topics
Using Godot's documentation
Reading the API documentation
Exporting projects
Getting the export templates
Export presets
Exporting
Example – Coin Dash for Android
Modifying the game
Preparing your system
Exporting
Shaders
Creating a shader
Learning more
Using other languages
C#
VisualScript
Native code – GDNative
Language bindings
Asset library
Contributing to Godot
Contributing to the engine
Writing documentation
Donations
Getting help – community resources
GitHub
Godot Q and A
Discord / Forum
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
This book is an introduction to the Godot game engine and its new version, 3.0. Godot 3.0 has a large number of new features and capabilities that make it a strong alternative to more 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 will have a project-based approach. It consists of five projects that will help developers achieve a sound understanding of how to use the Godot engine to build games.
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.
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 project.
Chapter 1,Introduction, introduces the concept of game engines in general and Godot specifically, including how to download Godot and install it on your computer.
Chapter 2,Coin Dash, deals with a small game that demonstrates how to create scenes and work with Godot's node architecture.
Chapter 3,Escape the Maze, entails a project based on a top-down maze game that will show how to use Godot's powerful inheritance features and nodes for tile maps and sprite animation.
Chapter 4,Space Rocks, demonstrates working with physics bodies to create an Asteroids-style space game.
Chapter 5,Jungle Jump, involves a side-scrolling platform game in the spirit ofSuper Mario Brothers. You'll learn about kinematic bodies, animation states, and parallax backgrounds.
Chapter 6,3D Minigolf, extends the previous concepts into three dimensions. You'll work with meshes, lighting, and camera control.
Chapter 7,Additional Topics, covers even more topics to explore once you've mastered the material in the previous chapters.
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 Python tutorial before diving into the game projects in this book.
Godot will run on any relatively modern PC running Windows, macOS, or Linux operating systems. Your video card must support OpenGL ES 3.0.
You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packtpub.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/Godot-Game-Engine-Projects/issues. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here:https://www.packtpub.com/sites/default/files/downloads/GodotEngineGameDevelopmentProjects_ColorImages.pdf.
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
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/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
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.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packtpub.com.
Whether it's your desired career 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 of your dreams.
This book is an introduction to the Godot game engine and its new 3.0 version, which was released in early 2018. Godot 3.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 fundamental game development techniques. For more experienced developers, Godot is a powerful, customizable, and open tool 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 games 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 projects.
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. Repetition is the key to learning complex topics; the more you work with Godot's features, the more familiar and easy they will start to seem. Try looking back at Chapter 2, Coin Dash, when you finish Chapter 7, Additional Topics. You'll be surprised at how much more you'll understand compared to the first time you read it.
If you're using the PDF version of this book, resist the temptation to copy and paste the code. Typing the code yourself will engage more of your brain. It's similar to how taking notes during a lecture helps you learn better than just listening, even if you never read 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 this 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 teaching you the basics. As you build them, 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, and it's a trap that has led to many an unfinished game. 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 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.
Game development is complex and involves a wide variety of knowledge and skills. In order 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 own 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 build everything you needed.
In addition, there are 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 framework of commonly needed functionality that often needs a significant investment in time to develop.
Here is a list of some of the main features a game engine will provide:
Rendering (2D and 3D)
: Rendering is the process of displaying your game on the player's screen. A good rendering pipeline must take into account modern GPU support, high-resolution displays, and effects like lighting, perspective, and viewports, while maintaining a very high frame rate.
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 simulation, but few developers want to take on the task of writing one, especially if they have ever tried to do so.
Platform support
: In today's market, most developers want to be able to release their games on multiple platforms, such as consoles, mobile, PC, and/or the web. A game engine provides a unified exporting process to publish 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, you don't have to re learn a new workflow every time you start a new project.
In addition, there will be tools to assist with features such as networking, easing the process of working with images and sound, animations, debugging, level creation, 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 all of 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 with the engine, and what hidden costs, if any, you may be responsible for.
On the other hand, there are some engines which are non-commercial and open source, such as the Godot game engine, which is what this book is all about.
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 donate 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 vast. 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, 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 Chapter 7, Additional Topics, for more information about how you can get involved with Godot development.
You can download the latest version of Godot by visitinghttps://godotengine.org/and clicking Download. This book is written for version 3.0. If the version you download has another number at the end (like 3.0.3), that's fine—this just means that it includes updates to version 3.0 that fix bugs or other issues.
On the download page, there are a few options that bear explaining. First, 32-bit versus 64-bit: this option depends on your operating system and your computer's processor. If you're not sure, you should choose the 64-bit version. You will also see a Mono Version. This is a version specially built to be used with the C# programming language. Don't download this one unless you plan to use C# with Godot. At the time of writing, C# support is still experimental, and is not recommended for beginners.
Double-click on the file you downloaded to unzip it, 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 Managerwindow.
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 and it will even track your
playtime
.
Package Managers
: If you're using one of the following operating system package managers, you can install Godot via its normal install process. See the documentation for your package manager for details. Godot is available in these package managers:
Homebrew (macOS)
Scoop (Windows)
Snap (Linux)
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.
The Project Manager is the first window you'll see when you open Godot:
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 click Edit to work on it in the Godot Editor (refer to the following screenshot). You can also create a new project by clicking New Project:
Here, you can give the project a name and create a folder to store it in. Always try to choose a name that describes the project. Also keep in mind that different operating systems handle capitalization and spaces in filenames differently. It's a good idea to stick to lowercase and use underscores, _, instead of spaces for maximum compatibility.
Note the warning message—in Godot, each project is stored as a separate folder on the computer. All the files that the project uses are in this folder. Nothing outside of this project folder will be accessible in the game, so you need to put any images, sounds, models, or other data into the project folder. This makes it convenient to share Godot projects; 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.
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 #2 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, for example: No spaces in filenames, use "_" 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.
