100% found this document useful (3 votes)
638 views66 pages

Programming For Game Design: A Hands-On Guide With Godot 1st Edition Wang All Chapter Instant Download

Wang

Uploaded by

keyrahadjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
638 views66 pages

Programming For Game Design: A Hands-On Guide With Godot 1st Edition Wang All Chapter Instant Download

Wang

Uploaded by

keyrahadjay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Download Full Version ebookmass - Visit ebookmass.

com

Programming for Game Design: A Hands-On Guide with


Godot 1st Edition Wang

https://ebookmass.com/product/programming-for-game-design-a-
hands-on-guide-with-godot-1st-edition-wang/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Programming for Game Design: A Hands-On Guide with Godot


1st Edition Wallace Wang

https://ebookmass.com/product/programming-for-game-design-a-hands-on-
guide-with-godot-1st-edition-wallace-wang/

ebookmass.com

Programming for Game Design: A Hands-On Guide with Godot


1st Edition Wallace Wang

https://ebookmass.com/product/programming-for-game-design-a-hands-on-
guide-with-godot-1st-edition-wallace-wang-2/

ebookmass.com

Game Programming with Unity and C#: A Complete Beginner's


Guide, 2nd Edition Casey Hardman

https://ebookmass.com/product/game-programming-with-unity-and-c-a-
complete-beginners-guide-2nd-edition-casey-hardman/

ebookmass.com

Fungipedia : A Brief Compendium of Mushroom Lore Lawrence


Millman

https://ebookmass.com/product/fungipedia-a-brief-compendium-of-
mushroom-lore-lawrence-millman/

ebookmass.com
The Psychology of Investing 6th Edition, (Ebook PDF)

https://ebookmass.com/product/the-psychology-of-investing-6th-edition-
ebook-pdf/

ebookmass.com

Harrison’s principles of internal medicine: self-


assessment and board review 19th Edition Charles Wiener Et
Al.
https://ebookmass.com/product/harrisons-principles-of-internal-
medicine-self-assessment-and-board-review-19th-edition-charles-wiener-
et-al/
ebookmass.com

Pharmacie Clinique Pratique en Oncologie 1st Edition


Edition Association Nationale Des Enseignants De Pharmacie
Clinique
https://ebookmass.com/product/pharmacie-clinique-pratique-en-
oncologie-1st-edition-edition-association-nationale-des-enseignants-
de-pharmacie-clinique/
ebookmass.com

Medical Management of Vulnerable and Underserved Patients:


Principles, Practice and Populations 2nd Edition Talmadge
E. King Jr
https://ebookmass.com/product/medical-management-of-vulnerable-and-
underserved-patients-principles-practice-and-populations-2nd-edition-
talmadge-e-king-jr/
ebookmass.com

The Paradox of the Immune System: Protection, Chronic


Inflammation, Autoimmune Disease, Cancer, and Pandemics
1st Edition Louis J. Catania
https://ebookmass.com/product/the-paradox-of-the-immune-system-
protection-chronic-inflammation-autoimmune-disease-cancer-and-
pandemics-1st-edition-louis-j-catania/
ebookmass.com
Nutrition for Sport and Exercise, 4th Edition J. Andrew
Doyle

https://ebookmass.com/product/nutrition-for-sport-and-exercise-4th-
edition-j-andrew-doyle/

ebookmass.com
Wallace Wang and Tonnetta Walcott

Programming for Game Design


A Hands-On Guide with Godot
Wallace Wang
San Diego, CA, USA

Tonnetta Walcott
El Cajon, CA, USA

ISBN 979-8-8688-0189-1 e-ISBN 979-8-8688-0190-7


https://doi.org/10.1007/979-8-8688-0190-7

© Wallace Wang, Tonnetta Walcott 2024

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any
other physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks, service


marks, etc. in this publication does not imply, even in the absence of a
specific statement, that such names are exempt from the relevant protective
laws and regulations and therefore free for general use.

The publisher, the authors, and the editors are safe to assume that the advice
and information in this book are believed to be true and accurate at the date
of publication. Neither the publisher nor the authors or the editors give a
warranty, expressed or implied, with respect to the material contained
herein or for any errors or omissions that may have been made. The
publisher remains neutral with regard to jurisdictional claims in published
maps and institutional affiliations.

This Apress imprint is published by the registered company APress Media,


LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
Any source code or other supplementary material referenced by the author
in this book is available to readers on GitHub. For more detailed
information, please visit https://www.apress.com/gp/services/source-code.
Table of Contents
Why Learn Programming with the Godot Game Engine?​
Chapter 2:​Getting to Know Godot
Creating and Opening a Godot Project
Creating a Scene and Nodes
Viewing and Modifying a Scene
Rotating and Scaling a Node
Summary
Chapter 3:​Writing Scripts
Creating a Script
Writing a Script
Viewing the GDScript Documentation
Summary
Chapter 4:​Storing Data in Variables
Creating a Variable
Storing and Retrieving Values in a Variable
Understanding Data Types
Understanding Variable Scope
Constants and Enumerations
Comments
Exercise:​Seeing Variables Change
Summary
Chapter 5:​Mathematical Operations
Mathematical Operators
Creating Constants
Understanding Precedence
Using Math Functions
Creating Random Numbers
Manipulating Strings
Exercise:​Randomizing an X and Y Position
Summary
Chapter 6:​Branching Statements
Working with Comparison Operators
Working with Logical Operators
The if Statement
The if-else Statement
The if-elif Statement
The match Statement
Exercise:​Reacting to Different Boolean Values
Summary
Chapter 7:​Looping Statements
Using a For Loop
Using a For Loop to Count with Different Values
Using the For Loop with Strings and Arrays
The While Loop
Comparing For and While Loops
Exercise:​Repeating Code with Loops
Summary
Chapter 8:​Understanding Arrays
Using Arrays
Creating and Adding Items to an Array
Getting Information About Arrays
Retrieving Data from Arrays
Manipulating Arrays
Searching for Data in an Array
Deleting Data from an Array
Exercise:​Using Arrays
Summary
Chapter 9:​Understanding Dictionaries
Creating Dictionaries
Retrieving Data from a Dictionary
Getting Information About Dictionaries
Changing and Deleting Data in Dictionaries
Exercise:​Using Dictionaries
Summary
Chapter 10:​Functions
Understanding Functions
Creating Functions
Using Parameters with Functions
Optional Parameters
Returning Values with Functions
Exercise:​Using Functions
Summary
Chapter 11:​Object-Oriented Programming
Creating a Class
Initializing Properties
Inheriting Classes
Polymorphism
Exercise:​Understanding How Object-Oriented Programming
Works in Godot
Summary
Chapter 12:​Getting Input from the User
Detecting Keyboard and Mouse Input
Defining an Input Map
Detecting Modifier Keys in an Input Map
Summary
Chapter 13:​Shooting Projectiles
Creating a Projectile Scene
Changing the Name of a Node
Adding a Projectile Image
Adding a Collision Shape
Making the Projectile Move
Summary
Chapter 14:​Adding Projectiles to a Player
Creating a Player Scene
Changing the Name of a Node
Adding a Player Image and Collision Shape
Using the Marker2D Node to Define the Projectile Location
Defining Ways to Control the Player
Writing GDScript Code to Control the Player
Firing a Projectile
Removing Projectiles
Summary
Chapter 15:​Hitting Enemies with Projectiles
Creating an Enemy Scene
Changing the Name of a Node
Adding an Enemy Image and Collision Shape
Creating a Main Scene
Detecting Collisions
Summary
Chapter 16:​Displaying a User Interface
Inputting and Displaying Text
Using Signals
Working with TextEdit and Buttons
Using Option Buttons and Item Lists
Working with CheckButtons
Working with Sliders
Summary
Chapter 17:​Adding Physics
Playing with Gravity
Adding Damping
Working with Static and Rigid Bodies
Working with Polygons
Using Layers and Masks
Restricting Movement
Summary
Chapter 18:​Playing Audio
Audio Formats in Godot
Starting and Stopping Audio
Pausing Audio
Looping Audio
Playing Audio When Detecting a Collision
Summary
Chapter 19:​Creating and Using Scenes
Automatically Adding Objects in Scenes
Modifying Instances of a Scene
Automatically Moving and Rotating a Scene
Following the Player with a Camera
Summary
Chapter 20:​Using Signals
Calling Down to a Function
Signaling Up
Summary
Chapter 21:​Creating a Simple Tic-Tac-Toe Game
Detecting Clicks on the Board
Displaying Player Moves
Summary
Index
About the Authors
Wallace Wang
has been writing computer books for over
30 years, including Steal This Computer
Book, Microsoft Office for Dummies,
Beginning Programming for Dummies,
Beginning iPhone Development with
SwiftUI, and The Structure of Game
Design, to name just a few. He created the
board game “Orbit War” for Steve Jackson
Games, which simulated satellite warfare
in the near future. He also writes
screenplays and won first place in
Scriptapalooza’s 2023 screenwriting
competition.

Tonnetta Walcott
is a writer, podcaster, gamer, and
programmer who is passionate about video
games and technology. She graduated from
San Diego State University with a
bachelor’s in English and has a certificate
in computer programming. After being
offered an internship at Sony Online
Entertainment, Tonnetta learned computer
programming (C++ and Java), web
development, and game design using the
Unity and Godot game engines. Tonnetta
has programmed a simulation to chess,
Battleship, and a matching concentration
game and is currently working on a game
called NinChibi, where tiny chibi ninjas
play tag in single-player and multiplayer modes. The NinChibi game is
built with the Godot game engine.
About the Technical Reviewer
Massimo Nardone
has more than 27 years of experience in
security, web/mobile development, and
cloud and IT architecture. His true IT
passions are security and Android. He has
been programming and teaching how to
program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more
than 27 years. He holds a Master of
Science degree in Computing Science from
the University of Salerno, Italy. He has
worked as chief information security
officer (CISO), software engineer, chief
security architect, security executive, and
OT/IoT/IIoT security leader and architect
for many years.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
W. Wang, T. Walcott, Programming for Game Design
https://doi.org/10.1007/979-8-8688-0190-7_1

1. Why Learn Programming with the


Godot Game Engine?
Wallace Wang1 and Tonnetta Walcott2
(1) San Diego, CA, USA
(2) El Cajon, CA, USA

Many people want to learn programming because the idea of creating a


program can be fun and exciting. Although programming is a skill that
anyone can learn, far too many beginner programming books and courses
forget about making programming fun right from the start.
Programming appeals to people because they want to create projects
that are interesting and show off their programming skills. Unfortunately,
the time for novices to gain the necessary skills to achieve their dreams can
take way too long. The end result is that too many programming students
give up because they fail to see how the skills that they gradually learn can
be useful in achieving the dreams that they want to achieve.
It doesn’t have to be that way. Persistency and patience are key.
Programming is about trial and error; however, it comes with the reward of
successfully completing a task.
That’s why this book is different. All beginning programming books
and courses must start with the basics. Unfortunately, those basics provide
minimal feedback to make programming interesting. That’s why this book
teaches the principles of programming using the Godot game engine.
Besides Unity and Unreal Engine, Godot is a top upcoming game engine
used to make mobile games, PC games, and any type of video game overall.
Learning to program through a game engine can offer greater
motivation. Rather than learn programming in isolation, it’s far better to use
a student’s interest and familiarity with video games to learn the basics of
programming while also learning how video games work. By visually
seeing, changing, and controlling simple video game elements using their
fledging programming skills, beginners can get instant feedback in a
meaningful way. This can help motivate students to keep learning more.
While there are plenty of game engines students can use, the Godot
game engine is unique for several reasons. First, the Godot game engine
runs on the three major operating systems for personal computers:
Windows, macOS, and Linux. That means the Godot game engine is
accessible to the greatest number of students than most other game engines.
Second, the Godot game engine is open source and completely free.
There are no licensing fees or restrictions for anyone to use the Godot game
engine. This makes Godot available to everyone.
Third, and most importantly, the Godot game engine is far smaller than
most of the major game engines on the market today. The Godot game
engine can run just fine on older and slower computers with minimal
storage that cannot run many other game engines. This makes the Godot
game engine especially suitable for most people who do not have access to
the latest, fastest, or most expensive computers on the market that most
other game engines require before you can use them. Godot also excels in
building 2D platforms and has recently been updated to also support 3D
games.
Because the Godot game engine is free, runs on all the major platforms
(Windows, macOS, and Linux), and runs on older, slower computers, the
Godot game engine offers a perfect introduction to both programming and
video game development.
You won’t learn how to develop the next massively multiplayer AAA
game title from this book, but you will learn programming principles and
basics in a fun and engaging manner. Although Godot uses its own
proprietary programming language called GDScript, it’s based on Python
and C. That means learning GDScript will prepare students to learn other
programming languages in the future.
So if you’re interested in both programming and video games, this book
is for you. We’ll start with the basics of a video game, then focus on
programming principles common in all programming languages. Finally,
we’ll focus on the specifics to making 2D video games. By the time you
complete this book, you should have a solid understanding of programming
principles and video game development.
This book will make programming fun by teaching video game design
in an accessible, fun, and interesting step-by-step manner. When you finish
this book, you’ll be well on your way to creating more sophisticated
programs and more complex video games. This book can help open the
doors to the fun and excitement of programming and video game
development. After this book, the entire world of programming and video
game development will be open to you no matter what programming
language or game engine you choose next.
As the Chinese proverb states, “A journey of a thousand miles begins
with a single step.” Let this book be your first step and you’ll find that
programming can be just as fun and exciting as you always thought it
should be.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2024
W. Wang, T. Walcott, Programming for Game Design
https://doi.org/10.1007/979-8-8688-0190-7_2

2. Getting to Know Godot


Wallace Wang1 and Tonnetta Walcott2
(1) San Diego, CA, USA
(2) El Cajon, CA, USA

The best way to learn any new skill is to start practicing it and not be afraid
of making a mistake. To learn programming, you need to spend time
practicing on your computer, so before you go any further, download and
install the Godot game engine (https://godotengine.org) on your
computer. Once you’ve installed Godot, you won’t need to install any other
programs to write programs in Godot. Remember, practicing takes time and
patience in order to be good at something. Learning Godot is a fresh start!
The main steps to using Godot involve creating, editing, and running a
project. A project represents a complete video game. Each time you want to
create a different video game, you’ll need to create a separate project.
Godot isolates projects by storing them in different folders. The more
projects that you create, the more you’ll understand the mechanisms of
Godot. Still, it would be wise to focus on one project at a time to avoid
overload.
Although projects represent a complete video game, you may want to
create projects to test out different ideas. For example, you might want to
create a project to test out a combat system and another project to test out
an inventory system. Separate projects let you experiment with different
ideas in isolation, making them easier and faster to test without worrying
about integrating with the rest of an existing project.
While you can create as many projects as you wish, you’ll most likely
spend the bulk of your time editing an existing project rather than creating
new projects. Editing a project involves several tasks. The first way to edit
any project is to add assets such as graphic items to represent players,
obstacles, or background images. The best part of the project is that you can
be as creative as you want with your assets to your game. There are
different ways to create or obtain assets with enough research, so you don’t
have to make everything yourself.
Once you’ve added assets to a project, a second way to edit a project is
to modify the assets such as defining their position on the game field, their
size, their orientation, and their appearance. Assets have both a physical
appearance and a spatial location that you can define. Take as much time as
you need to modify and position your assets in order to build a fun,
playable, and functional game.
The appearance and position of assets create a static image. To make a
project interactive, you’ll need to write scripts that define how an asset
should behave when your project runs. A script is a code or program that
gives instructions to make assets function in a certain way. You will learn
more about scripts later on throughout this book. For example, a cartoon car
might need to avoid running into trees, telephone poles, and other cars. If
that should happen, then the cartoon car needs to change its appearance to
show the results of the crash. In addition, the cartoon car should also behave
differently after it’s been damaged.
In Godot, such scripts are written in a proprietary language called
GDScript, which resembles the Python programming language. Scripts let
assets in a project respond to user control through a keyboard or touch
screen and interact with other game assets.
A cartoon spaceship might fire lasers that can destroy asteroids in the
way. This might require a script to control and fire lasers from the spaceship
and another script for the asteroid to detect when it’s been hit by a laser.
Essentially, scripts make assets interactive and controllable by the user.
Editing a project lets you change the way the project looks and behaves.
To test if your project looks and works the way you want, you’ll need to run
the project periodically. These three steps (creating a project, editing a
project, and running a project) define the main actions you’ll take while
using Godot.

Creating and Opening a Godot Project


When you use a word processor, you create an empty document that you
can fill with words that you can rearrange and format to change its
appearance. Likewise, when you use a game engine like Godot, you create a
bare-bones video game that you can fill with graphics and audio that you
can rearrange and modify to change their appearance.
Before you can use Godot, you must first know how to create a Godot
project. Every Godot project must be stored in a folder. To avoid mixing
Godot files with any existing files, it’s best to create a new, empty folder to
hold your Godot project.
To create a new Godot project, follow these steps:
1. Start Godot. Godot displays a Project Manager window. The Project
Manager window lists any previously opened Godot projects as well as
gives you options to create a new project as shown in Figure 2-1.

Figure 2-1 The Project Manager window

2. Click New in the upper left corner. A Create New Project dialog box
appears as shown in Figure 2-2. Godot requires that you create a new
folder for each project.
Figure 2-2 The Create New Project dialog box

3. Click the Browse button in the Project Path. A dialog box appears,
showing all the folders available.
4. Click a folder where you want to store your Godot project and click
Select Current Folder.
5. Click the Project Name text field and type a folder name to store your
project. (The default folder/project name is New Game Project.)
6. Click the Create Folder button.
7. (Optional) Click the Option button to choose a renderer version. For this
project, it doesn’t matter which renderer option you choose.
8. Click the Create & Edit button. Godot creates an empty project in the
folder that you selected in step 4.
Once you’ve created at least one Godot project, you can open that
project at a later time. To open an existing Godot project, follow these
steps:
1. Start Godot. Godot displays a Project Manager window (see Figure 2-1).
2. Click the Import button. An Import Existing Project dialog box appears
as shown in Figure 2-3.

Figure 2-3 The Import Existing Project dialog box

3. Click the Browse button. A Directories & Files dialog box appears as
shown in Figure 2-4.

Figure 2-4 The Open a File dialog box


4. Double-click the folder that contains the Godot project file that you want
to load. (You may need to repeat this process until you find the
project.godot file that you want to load as shown in Figure 2-5.)

Figure 2-5 Look for the project.godot file stored in your Godot project folder

5. Click the project.godot file and then click the Open button. Godot loads
your chosen project.
If you had created or opened a project recently, the name of your project
may appear in the Project Manager window (see Figure 2-1). In that case,
you can skip all of the preceding steps and simply double-click the Godot
project you want to open that appears in the Project Manager window.

Creating a Scene and Nodes


Whether you create a new project or open an existing project, you’ll see the
Godot editor window where you can add, delete, and modify the different
parts of your project. The main window in the center of the screen, called
the viewport, is where you can create and modify data.
The viewport can display two types of project data:
Graphic elements that define the visual appearance of a scene (2D or 3D)
GDScript code that defines how to respond to an action such as the user
pressing a key or the objects colliding (Script)
In Godot, a project consists of one or more scenes. One scene might
define a game level or playing field, a second scene might define the player
in the level or playing field, and a third scene might define a weapon that
the player can hold. Godot stores scenes in files that end with the .tscn file
extension as shown in Figure 2-6.
Figure 2-6 Every Godot scene gets stored in a file with the .tscn file extension

A single scene consists of one or more nodes where nodes provide


additional features for customizing the appearance or behavior of a scene.
One node might define an area to detect collisions, while another node
might define the graphic images to display on the screen as shown in Figure
2-7.
Figure 2-7 A scene can consist of multiple nodes

To design the visual appearance of your Godot project, you’ll need to


create one or more scenes and then customize each scene with one or more
nodes.
To see how to create a scene and add a node, follow these steps:
1. Create a new Godot project and give it a descriptive name. Until you add
a scene, Godot displays a menu of the different types of scenes you can
add as the initial or root node as shown in Figure 2-8.

Figure 2-8 Choosing an initial scene for a project

2. Click Other Node. A Create New Node window appears as shown in


Figure 2-9.
Figure 2-9 The Create New Node window

3. Click the Search text field at the top of the Create New Node window
and type node. The Create New Node window only displays those
options that contain the word “node” as shown in Figure 2-10.
Figure 2-10 Typing in the Search text field filters out the list of options

4. Click Node2D and click the Create button. Godot displays the Node2D
in the Scene dock, a cross representing the Node2D in the viewport, and
all the different properties you can change in the Node2D in the
Inspector pane as shown in Figure 2-11.
Figure 2-11 The Node2D in the Godot editor

5. Click the Node2D in the Scene dock to select it. To display a graphic
image on the Node2D, we need to attach another node, called a child
node, to the Node2D.
6. Attach a child node to the Node2D using one of the following methods
as shown in Figure 2-12:
Click the Add Child Node icon that appears as a + icon.
Press Ctrl+A (Windows/Linux) or Command+A (Macintosh).
Right-click, and when a pop-up menu appears, choose Add Child
Node.

Another Create New Node window appears (see Figure 2-9).


Figure 2-12 Adding a child node

7. Click the Search text field at the top of the Create New Node window
and type sprite.
8. Click Sprite2D and click the Create button. The Scene dock displays the
Sprite2D node as a child attached to Node2D as shown in Figure 2-13.
Figure 2-13 The Sprite2D child node attached to Node2D

9. Click Sprite2D in the Scene dock to select it. Notice that the Inspector
dock now displays properties you can modify.
10. Click <empty> in the Texture property in the Inspector dock. A pop-up
menu appears as shown in Figure 2-14.
Figure 2-14 The Texture pop-up menu in the Inspector dock

11. Choose Load or Quick Load. A dialog box appears as shown in Figure
2-15.

Figure 2-15 The Load and Quick Load dialog boxes

12. Click icon.svg and click Open. Godot displays the icon.svg graphic
image in the viewport as shown in Figure 2-16.

Figure 2-16 The icon.svg graphic file displayed in the viewport

13. Choose Scene ➤ Save Scene or choose Ctrl+S (Windows/Linux) or


Command+S (Macintosh). A Save Scene As dialog box appears. The
default name is node_2d.tscn, but you can give it a more descriptive
name if you wish.
14. Click Save. Godot saves your changes to the project. It’s generally a
good idea to save your scene periodically to avoid losing data if your
computer crashes.
At this point, we’ve created a scene (Node2D). Since the Node2D
doesn’t look like anything, we attached a child node to it (Sprite2D). Using
this Sprite2D node, we could then display a graphic image through the
Sprite2D’s Texture property to load the icon.svg file.

Viewing and Modifying a Scene


After creating a scene, attaching child nodes, and modifying the different
properties of these nodes, you can test what the scene looks when it’s
actually running. To run a project, follow these steps:
1. Click the Run icon at the top of the screen as shown in Figure 2-17. The
first time you run a project, it may ask you to define the main scene,
which is the first scene to appear.
Figure 2-17 The Run icon

2. (Optional) If a dialog box appears, asking for you to choose a main


scene, click the Select Current button to use the currently open scene.
When a project runs, it appears in a (DEBUG) window. Notice that the
image, stored in the Sprite2D node, appears partially cut off in the upper
left corner of the window as shown in Figure 2-18.

Figure 2-18 The icon.svg image appears partially cut off

3. Click the close icon in the (DEBUG) window to stop running the
project.
You may wonder why the graphic image appears partially cut off in the
upper left corner of the (DEBUG) window. That’s because the upper left
corner is the default position every time you create a node. To see how to
view the contents of a scene, follow these steps:
1. Click the Node2D in the Scene dock to select it. Notice that the icon.svg
graphic image appears at the origin of an x axis (red horizontal line) and
y axis (green vertical line) as shown in Figure 2-19.
Figure 2-19 Displaying the Node2D in the viewport

2. Click the Distraction Free Mode icon in the upper right corner of the
viewport window twice. This icon toggles between expanding the
viewport window to fill the entire screen or shrinking it down to also
display the Scene, FileSystem, and Inspector docks on the left and right
side of the screen.
3. Click the – and + Zoom icons in the upper left corner of the viewport
window. The – icon decreases the magnification of the viewport
window, while the + icon increases magnification.
4. Click the – Zoom icon until the magnification displays 50%. At 50%
magnification, Godot displays a faint outline that defines the size of the
project window as shown in Figure 2-20. Notice that 50% magnification
makes it easy to see the entire project window boundary and how the
icon.svg appears cut off in the upper left corner of the window when you
run the project.
Figure 2-20 At 50% magnification, the viewport displays the faint outline of the project window

5. Choose Project ➤ Project Setting. A Project Settings window appears.


6. Click Window under the Display category. Notice that you can now
change the Viewport Width and Height as shown in Figure 2-21.
Figure 2-21 The Project Settings window lets you change the size of the window when your project
runs

7. (Optional) Change the Viewport Width and Viewport Height values.


8. Click the Close button. The Project Settings window goes away. Let’s
move the position of Node2D so it doesn’t appear in the upper left
corner of the window.
9. Click the Node2D in the Scene dock to select it.
10. Click the Move icon (see Figure 2-19). Godot displays a right-pointing
arrow (red) and a downward-pointing arrow (green) as shown in Figure
2-22.
Figure 2-22 The Move icon displays an x axis and y axis arrow on the selected node

11. Drag the red and green arrows to position the Node2D in the middle of
the window outline.
12. Click the Run icon. The (DEBUG) window appears, but notice that the
icon.svg image now appears near the middle of the window where you
dragged the Node2D.
13. Click the close icon of the (DEBUG) window to stop running the
project.

Rotating and Scaling a Node


By using the Move icon, you can change a node’s position from the upper
left corner of the project window (where it got partially cut off) to the
middle of the project window. In addition to the Move icon, you can also
use the Rotate and Scale icons to modify the appearance of the Node2D.
The Rotate icon lets you rotate a node in different positions, while the
Scale icon lets you shrink or enlarge an icon. To see how to use the Rotate
and Scale icons, follow these steps:
1. Click the Node2D in the Scene dock to select it.
2. Click the Rotate icon near the top of the viewport.
3. Move the mouse pointer over the icon.svg image and drag the mouse
clockwise and counterclockwise to rotate the image.
4. Press Ctrl+Z (Windows/Linux) or Command+Z (Macintosh) to undo any
rotation you added to the image.
5. Click the Scale icon near the top of the viewport. A red line and square
(x axis) and green line and square (y axis) appears on the selected node
as shown in Figure 2-23.
Figure 2-23 The Scale lines and squares

6. Drag the red square right and left. Notice that this expands and shrinks
the width of the selected image.
7. Press Ctrl+Z (Windows/Linux) or Command+Z (Macintosh) to undo
any scaling you added along the x axis to the image.
8. Drag the green square up and down. Notice that this expands and
shrinks the height of the selected image.
9. Press Ctrl+Z (Windows/Linux) or Command+Z (Macintosh) to undo
any scaling you added along the y axis to the image.
10. Hold down the Shift key and drag either the red or green square. Notice
that when you hold down the Shift key, both the width and the height of
the image expand or shrink at the same time.
11. Press Ctrl+Z (Windows/Linux) or Command+Z (Macintosh) to undo
any scaling.
When you want to keep the proportion of the width and the height
constant, hold down the Shift key before dragging one of the scaling
squares. By using the Rotate and Scale icons, you can modify the
appearance of an image displayed in the viewport.

Summary
You should store every Godot project in a separate folder. That will keep
files from one project from accidentally interfering with files used in a
different project. While each project creates a complete video game, don’t
be afraid to create projects to test ideas out or to learn different features of
Godot.
A Godot project consists of one or more scenes where a scene can
represent a playing field, a single object, or parts of an object such as the
separate tires of a cartoon car. Scenes define what users see when they run
your project.
Scenes are made up of one or more nodes. Nodes contain properties that
you can modify in the Inspector dock. You may need to add multiple nodes
to include all the features you need for a particular object in your project. A
common node for displaying graphics is the Sprite2D node. There are many
types of nodes to work with, so do not be afraid to test out different nodes
that you may find suitable for your project.
Once you’ve created a scene, you can arrange objects in that scene
using the Move, Rotate, or Scale icons. The Move icon lets you place an
object on the screen. The Rotate icon lets you change the angle of an object
so that it appears tilted or on its side. The Scale icon lets you change the
height and width of an object.
The main steps to using Godot are creating and opening projects. Once
you open a project, you can edit it by adding, deleting, and changing scenes
through nodes that add additional features. Modifying a project defines
what users will see when your project runs.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of The lively
adventures of Gavin Hamilton
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: The lively adventures of Gavin Hamilton

Author: Molly Elliot Seawell

Illustrator: H. C. Edwards

Release date: July 28, 2022 [eBook #68630]

Language: English

Original publication: United States: Harper and Brothers Publishers,


1899

Credits: D A Alexander, Newberry Library, Chicago, Illinois, for a


scan of the publisher's cover and the Online Distributed
Proofreading Team at https://www.pgdp.net (This file was
produced from images generously made available by
University of California libraries)

*** START OF THE PROJECT GUTENBERG EBOOK THE LIVELY


ADVENTURES OF GAVIN HAMILTON ***
THE LIVELY ADVENTURES
OF
GAVIN HAMILTON
By

MOLLY ELLIOT SEAWELL


AUTHOR OF “THE ROCK OF THE LION”
“A VIRGINIA CAVALIER” ETC.
ILLUSTRATED
BY H. C. EDWARDS

NEW YORK AND LONDON


HARPER & BROTHERS PUBLISHERS
1900
“‘IT IS MY TURN NOW!’ SHOUTED GAVIN”
By MOLLY ELLIOT SEAWELL.
THE ROCK OF THE LION. Illustrated by A. I. Keller.
Post 8vo, cloth, $1 50.
The book is written with much dash and spirit, as
well as with painstaking accuracy.—N. Y. Times.
A VIRGINIA CAVALIER. Illustrated. Post 8vo, Cloth,
$1 50.
A Virginia cavalier is the title under which George
Washington as a youth is presented to us. Some of
the incidents of his boyhood and early manhood are
told in a picturesque way, and the spirit and manners
of the time are well shown forth.—Atlantic Monthly.

NEW YORK AND LONDON:


HARPER & BROTHERS, PUBLISHERS.

Copyright, 1899, by Harper & Brothers.


All rights reserved.
NOTE
In this story, as in all the other stories for the young written by
the author, few, or no liberties have been taken with history and
chronology.
Molly Elliot Seawell
ILLUSTRATIONS
ILLUSTRATED HALF-TITLE vii
“‘IT IS MY TURN NOW!’ SHOUTED GAVIN” Frontispiece
GAVIN THROWS AWAY HIS TROOPER’S
Facing p.
SABRE 18
THE KING DRAGGED GAVIN OUT OF THE

CLOSET 46
HE DROPPED SIR GAVIN ON TO THE
FLOWER-BED ”
FIFTEEN FEET BELOW 130
GAVIN CARRIES THE KING ACROSS THE
FLOODED ”
GARDEN 184
“TAKE CHARGE OF THE PRISONER UNTIL I
SEND ”
FOR HIM” 216
THE LIVELY
ADVENTURES OF GAVIN HAMILTON
CHAPTER I
In Silesia, the autumn of 1757 was one of frightful cold, of icy
winds, of sunless days, and freezing nights. The land, made
desolate by the contending armies of the Empress Queen, Maria
Theresa, and Frederick the Great, of Prussia, suffered still more from
this bitter and premature winter. The miserable inhabitants, many of
them houseless, died by thousands, of cold and starvation. The
wretched remnant of cattle left them perished; the fields lay untilled,
the mills were only piles of charred ruins, and desolation brooded
over the land. War could add but little more to the miseries of this
unfortunate region; but Frederick of Prussia and the lion-hearted
Empress of Austria fought as fiercely as they had done sixteen years
before when the Titanic combat had first begun. Rosbach had been
fought—that terrible battle in which Frederick prevailed against the
Austrians, who were assisted by the soldiers of France and the
money of England. The Austrians and French had, at first, attempted
an orderly retreat; but the piercing cold, the constant fall of snow,
and the difficulties of subsistence, had very much interfered with this.
Their object was to reach Prince Charles of Lorraine, in northwest
Silesia, and many small bodies of troops succeeded in maintaining
their organization until they joined Prince Charles. Others were not
so fortunate; soldiers found themselves without officers, and officers
found themselves without men. In this last case was Captain St.
Arnaud, of the French regiment of Dufour, a young gentleman who
had exchanged his commission in the King’s Musketeers, the most
royal of all the royal guards, for a line regiment where he could see
service. It cannot be denied that this decision on Captain St.
Arnaud’s part surprised his world, for he was a curled darling among
the ladies, and the most superlative dandy in Paris. And, wonderful
to say, he still looked the superlative dandy on the afternoon of the
coldest day he ever felt in his life, amid the snowy wastes of Silesia,
when, after two weeks of starving and running away from the
Prussians, it looked as if the inevitable hour had come. There was,
yet, not a speck upon his handsome uniform; his long, light hair lay
in curls upon his shoulders—he had admired his own locks too much
to cover them up with a periwig; and his delicate, handsome face,
now gaunt and pale, was exquisitely shaven. Clearly, starving did not
agree with his constitution. His whole life before that campaign had
been spent in the courts and camps of kings, and he had missed
those hardening and fortifying influences which is Fate’s rough way
of benefiting her favorites. But faint and weak and hopeless as he
seemed, his soul was still unconquered, and his eyes looked bravely
around upon the desolate waste before him. The cold, already
intense, was becoming severer every hour. St. Arnaud, being
naturally of a reflective nature, which he hid under a mask of the
utmost levity, was thinking to himself, as he patted the neck of his
lean and patient horse, “The whole social order depends on the
mercury in the tube. At a certain point, varying in different races, all
distinctions are abolished. If my general were here this moment, I
would be as good as he; for the best man would be he who could
keep up his circulation best. And if my orderly were here—bah! he
could only deprive me of my last chance of living through this night
by rubbing down my horse for me, which exercise would keep my
blood in circulation and increase the poor beast’s chances of
carrying me through to the end.” His piercing eyes had swept the
view in front of him, but he almost jumped out of his saddle as a
voice at his elbow said: “My Captain! I salute you!”
Close behind him, on a very good horse, sat a young private
soldier of St. Arnaud’s company. St. Arnaud at once recognized him;
he was so tall, so fresh coloured, so well made that he attracted
attention in the ranks; but private soldiers to St. Arnaud represented
not names, but numbers. He thought this young fellow was 472 on
the regimental roll, but had no idea of his name. He was a contrast to
St. Arnaud in every way; for besides being a perfect picture of
physical well-being, the young soldier was in rags. In one the inner
man had suffered, in the other the outer man. Having spoken, the
young man awaited speech from his officer with as much coolness
as if he were on parade at Versailles, instead of being alone with him
at nightfall in a frozen desert.
“I recognize you,” said St. Arnaud, after a moment; “where are
the others of your company?”
“I am the only man left, sir,” replied the soldier; “as you know, we
were very much cut up that villainous day at Rosbach; and when you
were swept from us, in that last charge, we had already lost half our
men. I don’t know how it was, sir; certainly it was not the fault of our
officers”—with another salute—“but I believe ours was the worst
demoralized regiment in the French forces after Rosbach, and my
company was the worst demoralized in the regiment. We had not an
officer left above a corporal, but the handful of us could have
remained together. Instead of doing that, it was sauve qui peut with
all of us. Note, sir, I do not say we did not fight like devils at
Rosbach; but being unused to defeat, we did not know how to take it.
I cannot tell you how it is I come to be here alone; only I know that I,
with twenty others, started out to make our way toward Prince
Charles, and one by one the men dropped off, until yesterday
morning, when, at sunrise, I found myself alone where I had
bivouacked the night before with three comrades. They had gone off
in the night, or early in the morning, to follow a road I did not believe
would lead us where we wanted to go. I came this way, and well it
was for me.”
The young soldier’s story, told jauntily, produced a singular effect
on St. Arnaud. He had kept on hoping that, in spite of the accident of
his being separated from his command—an accident caused by his
own impetuosity carrying him too far in advance of his men—he
would yet find his own personal command intact. But there was no
more room for hope in the face of what was before his eyes and
ringing in his ears. His countenance became so pale with grief and
chagrin that he seemed about to drop from his saddle. He laid the
reins on his horse’s neck, and raised both arms above his head in a
gesture of despair, but he said no word. The soldier, after waiting
vainly for a question or an answer, spoke again.
“We have no time to lose, sir; we must cross this plain before
night. I have some forage here and something in my haversack, and
if we can get a fire we can live.”
St. Arnaud, still silent, mechanically gathered up the reins again,
and the horse instinctively made for a faint track beaten through the
snow. The soldier followed, ten paces behind. On they travelled for
an hour or two. As the sickly sun sank below the fringe of dun clouds
in the west the cold became more terrible. A fierce wind set in, which
drifted furious flurries of snow across the vast, white plain; and when
the sky showed black against the white earth, neither man nor horse
could travel farther. There was not a tree or even a bush in sight.
They had passed a few dead horses on the dreary waste, but that
was the only thing that broke the ghastly monotony of the way. Now
they involuntarily halted, and each knew that from then until sunrise
they would be fighting with the cold for life. The thought came back
to St. Arnaud, who had scarcely spoken a word to his companion,
how calamity levels all distinctions. It would not have surprised him
in the least if, when he dismounted, and mechanically threw the reins
to the soldier, to have heard him say: “Take care of your own horse,
and I will attend to mine.” Instead of this, the soldier only pointed to a
little hillock near by, and said: “That place, sir, is a little sheltered
from the wind. It will do us good to walk there.”
St. Arnaud, whose faculties seemed frozen, obeyed the soldier.
As he was tramping through the half darkness, his eyes blinded by
the snow, and the icy blast nearly cutting him to pieces, he heard a
shout of joy behind him. The soldier had suddenly stumbled upon
something which was worth to them at that moment all the gold in
the Bank of France. It was nothing less than a broken gun-carriage,
of which a few inches of the wheel appeared above the snow. The
soldier dashed toward it, and tugged and pulled at it, shouting out
exclamations of joy, as a man will who has found that which will give
him life. St. Arnaud watched him dully as he wrenched such of it
apart as he could, and dragging it to the sheltered spot under the
hillock, where St. Arnaud held the trembling horses, scooped out a
hole in the snow, and with a flint and steel struck a flash of fire.
At first, the flame flickered tamely; then, suddenly, it burst into a
glory of light and warmth. St. Arnaud advanced, still leading the poor
horses, who gazed at the flames with an intelligent joy, almost
human.
By that time it was so black overhead and so white underfoot,
and the swirling snow was so whipped about by the furious north
wind, that it seemed as if the two men and the two shivering horses
were alone in a universe of cold and snow and blackness. The
young soldier first gave the horses the feed they had carried, and
melting some snow in a tin pan he carried in his knapsack, gave
them to drink. Then, washing out the pan, he produced some bacon
and cheese and black bread. St. Arnaud showed the first sign of
interest so far, by handing out his canteen, of which one whiff caused
the young soldier’s wide mouth to come open with a grin, that
showed the whitest teeth imaginable. And then, huddling under their
cloaks, officer and soldier shared their first meal together. That day
month St. Arnaud had been entertained by a countess in one of the
finest houses in Vienna, and the young soldier had fared
sumptuously in the kitchen with the maids; but to-night they were
supping together, and only too glad to sup at all. At last, all the bacon
and cheese being devoured, St. Arnaud’s spirit seemed to rouse
from its torpor. He looked at the soldier attentively and asked:
“What is your name?”
“Ameeltone,” was the response.
St. Arnaud’s French ear did not detect the strange pronunciation
of the name, yet he could not quite make it out.
“Can you spell it?” he asked.
“Oh, yes. H-a-m-i-l-t-o-n—Ameeltone.”
“But that is English.”
“Yes; my name is English all over. Gavin is my first name”—and
he pronounced it Garvan.
“Have you any English blood in you?”
“I have not a drop of any but English blood, my Captain. My
father, Sir Gavin Hamilton, is an Englishman; and my mother, God
bless her, is Lady Hamilton.”
“Then,” said St. Arnaud, very naturally, “what are you doing as a
trooper in Dufour’s regiment?”
“Because,” replied Gavin, taking up the tin pan and scooping out
the last remnants of their supper, “my father is a great rascal.” And
he washed the pan out with snow.
St. Arnaud, accustomed to the extreme filial respect of the
French for their parents, felt a shock at Gavin’s cool characterization
of his father, and said in reply:
“A man sometimes has cause for resentment against his father,
but seldom calls him a rascal.”
“True, my Captain,” cheerfully replied Gavin, “but my father is a
terrible rascal. He has ill-used my mother, the finest creature God
ever made. What do you think of a man with a great fortune
deserting his wife and child in a foreign land and then using all his
power to make her admit she is not his wife, when he knows she is;
and when he finds she has a soul not to be terrified, trying to fool her
into a divorce? But I tell you, my Captain, my mother is a brave lady.
She told him and wrote him that she was his lawful wife, and that she
would defend me—I was a little boy then—that she would have no
divorce, lest it reflect on me, and that no one of my rights would be
bartered away by her. And at that very time she could barely keep
body and soul together by giving lessons in Paris. She is well
educated, luckily, being an English officer’s daughter. The English
laws are hard on poor and friendless women, and being in France,
too, my mother had little chance to prove her rights. She looked to
me, however, to be able one day to maintain all she had claimed;
and she taught me carefully, so that, as she said, when I came to the
condition and estate of a gentleman, I might know how to bear
myself. She did not wish to go back to England, where she knew
persecution awaited her, and brought me up as much an English boy
as she could in France. The only thing that troubled her was my
pronunciation—she always laughs when I pronounce my own name.
I have an English way of using my fists when I am angry. She scolds
me, but I know her brothers fought like that when they were lads at
school.”
“How came you to join the army?”
“Faith, sir, I had no choice. The King’s recruiting officers came
after me, and I had to go. But I cannot say I regretted it, for I could
never have been anything else but a soldier, and I have a better
chance to rise in the army than in any of the humble callings open to
me in civil life. My mother said it was best—that I came of good
fighting stock on her side—her brothers were officers, and as far
back as she knows her ancestors they were mostly in the army and
navy.”
The fire was burning brightly now; they were warmed through,
their hunger was appeased, and so comfortable was their situation
that they were both in a mood to entertain and be entertained. A fire
in the snow and a supper of cheese and bacon meant luxury to St.
Arnaud now, who had been brought up in palaces, and he found
himself listening to Gavin’s story with the same interest that the Arab
in the parching desert listens to the story-teller who makes him forget
all his miseries.
“Did you ever see your father?” he asked.
“Once. My father was sent to the court of the Empress Queen on
a diplomatic mission. He passed secretly through Paris and sent for
me. I went with the sole idea that he might do justice to my mother.
But I might have saved my shoe leather. However, what I did that
day to my father is written to my credit in heaven’s books, for I
mauled him well, and I was but eighteen—I am only nineteen now.”
St. Arnaud could not refrain from a look of disapproval, and
Gavin, noting it, asked at once, with the greatest naïveté:
“But he spoke abominably of my mother, and any man who
speaks one disrespectful word of her—he is my enemy, and I am his.
Would not you do the same by your mother?”
And St. Arnaud involuntarily answered “Yes.”
“Well, then,” continued Gavin, rising to his feet, “are you
surprised that I should think I did a righteous act in flying at Sir
Gavin? He is a strong, well-made man, though not so big as I am
now, and as I took him by surprise, I succeeded in knocking him off
his chair before he had got out half he had meant to say about my
mother. His valet came running in then, and Sir Gavin, smiling as he
wiped some blood off his face, sent the man away. Oh, he was a
cool one! He smiled all the time we were together, and he laughed
aloud when I called myself Gavin Hamilton.
“‘Garvan Ameeltone!’ he cried, mocking me.”
Gavin was now thoroughly inspired by his own eloquence. He
stood up and put his hands behind his back, English fashion, while
repeating his father’s words and mimicking him in an odd, drawling
voice. St. Arnaud fully believed in the scene that Gavin not only told,
but acted before him. Even the two horses, tethered close to the red
circle of light, lifted their heads, attracted by the ringing human voice,
and seemed to be listening attentively to the story of Gavin
Hamilton’s wrongs and revenges.
“My father then, instead of being angry with me, seemed to like
me the better, and offered me everything—everything if I would
abandon my mother. He would acknowledge me as his son,
according to both the French and English law, for I was born in
France; he would promise never to marry again, and I don’t know
what else beside. It was then my turn to laugh. I said: ‘Wait until I am
twenty-one, and then see if I do not prove I am your son. And as for
marrying again, you dare not in my mother’s lifetime.’
“There was an hour-glass in the room, and Sir Gavin said to me:
‘In about twenty minutes all the sand will have run out of that glass. I
give you until then to accept my offer.’ For answer I smashed the
hour-glass on the hearth. It was then he spoke insultingly of my
mother, and it was then that I think I laid up treasures in heaven by
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like