Download (Ebook) Learning C# by Developing Games with Unity 5.x: Develop your first interactive 2D platformer game by learning the fundamentals of C# - Second Edition by Greg Lukosek ISBN 9781785287596, 1785287591 ebook All Chapters PDF
Download (Ebook) Learning C# by Developing Games with Unity 5.x: Develop your first interactive 2D platformer game by learning the fundamentals of C# - Second Edition by Greg Lukosek ISBN 9781785287596, 1785287591 ebook All Chapters PDF
com
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
(Ebook) Learning C# by developing games with Unity 2020:
An enjoyable and intuitive approach to getting started
with C# programming and Unity by Harrison Ferrone ISBN
9781800204447, 1800204442
https://ebooknice.com/product/learning-c-by-developing-games-with-
unity-2020-an-enjoyable-and-intuitive-approach-to-getting-started-
with-c-programming-and-unity-12073856
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
Learning C# by Developing
Games with Unity 5.x
Second Edition
Greg Lukosek
BIRMINGHAM - MUMBAI
Learning C# by Developing Games with Unity 5.x
Second Edition
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, and its dealers and distributors will be held liable for any damages
caused or alleged to be 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.
ISBN 978-1-78528-759-6
www.packtpub.com
Credits
Copy Editor
Vikrant Phadke
About the Author
Greg Lukosek was born and raised in the Upper Silesia region of Poland. When
he was about 8 years old, his amazing parents bought him and his brother a
Commodore C64. That was when his love of programming started. He would spend
hours writing simple basic code, and when he couldn't write it on the computer
directly, he used a notepad.
Greg met the love of his life, Kasia, in 2003, which changed his life forever. They both
moved to London in search of adventure and decided to stay there.
He started work as a 3D artist and drifted away from programming for some years.
Deep inside, he still felt the urge to come back to game programming. During
his career as a 3D artist, he discovered Unity and adopted it for an interactive
visualizations project. At that very moment, he started programming again.
His love for programming overcomes his love for 3D graphics. Greg ditched his 3D
artist career and came back to writing code professionally. He is now doing what he
really wanted to do since he was 8 years old—developing games.
These days, Greg lives in a little town called Sandy in the UK with Kasia and
their son, Adam.
I want to thank my loving wife, Kasia, for all her love and support.
Without her, writing this book would be simply impossible. I also
want to thank my loving parents, Ela and Marek, and brother, Artur,
for always believing in me and giving me exceptional support when
I needed it.
Then, I want to thank our son, Adam, for being an awesome child.
I hope you will also do what you love in your life.
About the Reviewer
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.
TM
https://www2.packtpub.com/books/subscription/packtlib
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
Table of Contents
Preface vii
Chapter 1: Discovering Your Hidden Scripting Skills and
Getting Your Environment Ready 1
Prerequisite knowledge to use this book 2
Dealing with scriptphobia 2
Downloading Unity 3
Obtaining a free license 4
Teaching behavior to GameObjects 6
Using Unity's documentation 6
Do I need to know all that? 8
C# documentation – where to find it? Do I need it at all? 9
The Unity community – asking others for help 9
Working with C# script files 9
Lots of files can create a mess 10
Why does my Project tab look different? 11
Creating a C# script file 13
Introducing the MonoDevelop code editor 13
Syncing C# files between MonoDevelop and Unity 13
Opening LearningScript in MonoDevelop 13
The namespace – highlighted in blue 14
The class definition – highlighted in green 15
Watching for possible gotchas while creating script files in Unity 16
Fixing synchronization if it isn't working properly 16
Adding our script to GameObject 16
Instance? What is it? 18
Summary 19
[i]
Table of Contents
[ ii ]
Table of Contents
[ iii ]
Table of Contents
Modulo 86
Searching for data inside an array 87
Breaking the loop 88
Summary 88
Chapter 7: Object, a Container with Variables and Methods 89
Working with objects is a class act 89
Few facts 93
Example 94
Instantiating an object 94
Bored yet? 96
Using methods with objects 97
Custom constructors 100
Overloading 102
Summary 104
Chapter 8: Let's Make a Game! – From Idea to Development 105
Your first game – avoiding the trap of the never-ending concept 105
The idea 106
Game mechanics and core components 107
Breaking a complex idea into smaller parts 108
Jake on the mysterious planet – the feature list 109
Procedural level generation 110
An animated 2D character 111
Physics 111
Mouse and touch controls 111
Collectables and obstacles 112
Scoring 112
UI – the user interface 113
Target platform and resolution 114
Target screen resolution 115
Summary 115
Chapter 9: Starting Your First Game 117
Setting up a new Unity Project for our game 118
Backup 118
Keeping your project clean 118
Preparing the player prefab 120
Rigidbody2D 123
CircleCollider2D 123
PlayerController 124
User input 124
Jump 126
[ iv ]
Table of Contents
Animator 131
Running 133
Code 134
PlayerController.cs 134
Summary 135
Chapter 10: Writing GameManager 137
Gameplay loops 137
Singleton class 140
Starting the game 142
Setting up input keys 143
Using triggers 144
Restarting the game 147
Setting up the player starting position 147
Code in this chapter 149
Summary 152
Chapter 11: The Game Level 153
Generating levels versus designed levels 153
Creating a level chunk 155
Planning the LevelGenerator class 156
Writing LevelGenerator 159
Commenting on your code 160
Creating a copy of the level piece 161
Instantiating 162
Vector3 163
Testing LevelGenerator 164
Extending the level 166
The code used in this chapter 168
Summary 170
Chapter 12: The User Interface 171
Introducting the Unity UI 172
Views 173
Constructing the view UI – how to keep things clean 173
Target screen resolution 174
Recognizing events 174
Buttons 176
A simple button 178
Image 179
The Button component 179
Interaction 179
The Button action 180
[v]
Table of Contents
[ vi ]
Preface
Hello, future game developers! If you are reading this book, you are probably
a curious person trying to learn more about a great game engine—Unity—and
specifically, programming in C#. This book will take you on a learning journey. We
will go through it together, beginning with the fundamentals of programming and
finishing with a functional 2D platform game.
Chapter 2, Introducing the Building Blocks for Unity Scripts, helps you develop the skill
of writing your first executable code.
Chapter 3, Getting into the Details of Variables, teaches you about creating and using C#
variables, followed editing them in Unity Inspector.
Chapter 4, Getting into the Details of Methods, helps you learn more in detail about
methods and how to use them to understand the importance of code blocks and the
variables used in them.
Chapter 5, Lists, Arrays, and Dictionaries, introduces slightly more complex ideas of
handling, lists, arrays, and dictionaries, which allow you to store many values at once.
Chapter 6, Conditions and Looping, helps you learn how to "ask" Unity to loop through
a section of code and do something useful.
Chapter 7, Objects, a Containers with Variables and Methods, dives into the subjects of
organizing your code and object-oriented programming.
Chapter 8, Let's Make a Game! – From Idea to Development, shows you how to turn an idea
into a ready-to-code project and how to break down complex mechanics into pieces.
[ vii ]
Preface
Chapter 9, Starting Your First Game, helps us transform an idea into a real Unity
project.
Chapter 10, Writing GameManager, gets you acquainted with the basics of the
singleton approach and also helps you work through the gameplay loop.
Chapter 11, The Game Level, helps you learn how to create reusable pieces
of a level and also how to populate them to create the illusion of an endlessly
running game.
Chapter 12, The User Interface, explains how to construct and implement the user
interface in our game.
Chapter 13, Collectables — What Next?, focuses on collectables and storing some data
between Unity sessions.
https://unity3d.com/unity/system-requirements
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"Add the Collectable script to your coin prefab."
[ viii ]
Preface
LevelGenerator.instance.AddPiece();
LevelGenerator.instance.RemoveOldestPiece();
}
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "When you
are ready, click on Play in Unity."
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
[ ix ]
Preface
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.
Once the file is downloaded, please make sure that you unzip or extract the folder
using the latest version of:
[x]
Preface
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ xi ]
Discovering Your Hidden
Scripting Skills and Getting
Your Environment Ready
Computer programming is viewed by the average person as requiring long
periods of training to learn skills that are totally foreign, and darn near impossible
to understand. The word geek is often used to describe a person who can write
computer code. The perception is that learning to write code takes great technical
skills that are just so hard to learn. This perception is totally unwarranted. You
already have the skills needed but don't realize it. Together, we will crush this false
perception that you may have of yourself by refocusing, one step at a time, on the
knowledge that you already possess to write code and develop an awesome game
from scratch.
Let's begin our journey by eliminating any anxiety about writing scripts for Unity
and become familiar with our scripting environment.
[1]
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
You've just learned a big lesson; all those fantastic, highly detailed GameObjects are
dumber than a hammer. They don't know anything, and they surely don't know how
to do anything.
So, you proceed to read the Unity Forums, study some scripting tutorials, and maybe
even copy and paste some scripts to get some action going when you click on Play.
That's great, but then you realize that you don't understand anything in the scripts
you've copied. Sure, you probably recognize the words, but you fail to understand
what those words do or mean in a script.
You look at the code, your palms get sweaty, and you think to yourself, "I'll never be
able to write scripts!" Perhaps, you have scriptphobia—a fear of not being able to write
instructions (I made that up). Is that what you have?
The fear that you cannot write down instructions in a coherent manner? You may
believe you have this affliction, but you don't. You only think you do.
The basics of writing code are quite simple. In fact, you do things everyday that are
just like steps executed in a script. For example, do you know how to interact with
other people? How to operate a computer? Do you fret so much about making a
baloney sandwich that you have to go to an online forum and ask how to do it?
Of course you don't. In fact, you know these things as every day routines or maybe
habits. Think about this for a moment: do you have to consciously think about these
routines that you do everyday? Probably not. After you do them over and over, they
become automatic.
[2]
Chapter 1
The point is that you do things everyday following sequences of steps. Who created
these steps that you follow? More than likely, you did, which means that you've been
scripting your whole life.
You just never had to write down the steps for your daily routines on a piece of
paper before you did them. You could write the steps down if you really wanted
to, but it takes too much time and there's no need of it; however, you do in fact
know how to. Well, guess what? To write scripts, you only have to make one small
change—start writing down the steps, not for yourself but for the world that you're
creating in Unity.
So as you see, you are already familiar with the concept of dealing with scripts. Most
beginners of Unity easily learn their way around the Unity interface, how to add
assets, and working in the Scene and Hierarchy windows. Their primary fear, and
roadblock, is their false belief that scripting is too hard to learn.
Relax! You now have this book. I am going to get really basic in the early chapters.
Call them baby steps if you want, but you will see that scripting for Unity is similar
to doing things that you are already doing everyday. I'm sure you will have many
Ah-Ha moments as you learn and overcome your unjustified fears and beliefs.
Downloading Unity
You have probably already installed and activated Unity. Where you should look for
the latest Unity version and license might be obvious. However, I've noticed lots of
questions online about where you can get Unity for free, and so I decided to cover
this subject. If you feel that this step is obsolete for you, skip this part.
The best place to download your Unity copy from is, of course, Unity's official
website: http://unity3d.com/unity/download.
In this book, we will be covering Unity Version 5.0 and higher. We need to download
the latest version of Unity and install it with all components ticked. It's a good idea
to install Unity with the example project. The Unity Example project (the Angry Bots
game) is there for us to play with, experiment, and learn.
[3]
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
1. Unity will present the Activate your Unity license window. Click on OK, as
shown here:
[4]
Chapter 1
2. Fill in your details so that Unity Technologies can send you your Unity free
license code:
3. You should receive a verification e-mail with a confirm email button. Once
you have clicked on it, you should be able to log in to Unity.
You are now all set with the latest version of Unity and a free license!
[5]
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
Notice the word behavior. It reminds me of a parent teaching a child proper behavior.
This is exactly what we are going to do when we write scripts for our GameObjects;
we'll teach them the behaviors we want them to have. The best part is that Unity has
provided a long list of all the behaviors that we can give to our GameObjects. This
list of behaviors is documented in the Scripting Reference.
This means that we can pick and choose anything that we want a GameObject to do
from this list of behaviors. Unity has done all the hard work of programming all of
these behaviors for you. All we need to do is use some code to tie into these behaviors.
Did you catch that? Unity has already created the behaviors; all that we have to do
is supply a bit of C# code to apply these behaviors to our GameObjects. Now, how
difficult can it really be since Unity has already done most of the programming?
[6]
Chapter 1
• Through the Help menu on the top bar. In this way, you can access a local
copy of Unity reference. This is worth remembering if there are Internet
connectivity issues:
• Through the Help menu next to the component name. This will work only
for Unity's built-in, standard components.
[7]
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
Let's open Scripting Reference now and search for a GameObject. This is the place
where we can find scripting documentation, answers to our questions, and a lot
of example code. You might feel a bit lost right now, but don't worry; this is quite
normal. The Unity documentation is really easy to use. For fastest access to relevant
information, use Search scripting... in the top-right corner, as shown here:
[8]
Chapter 1
Let's not worry about it too much at the moment. We agreed to take baby steps, so
bookmark this link in your web browser for now.
When we encounter some hurdles, why not ask others? In most cases, there is
someone like you out there with similar issues that have been resolved. A good place
to talk about issues in your project is Unity Forums. Go ahead and create a forum
account now! Don't be shy; say "hello" to others! Unity Forums are also the perfect
place to read announcements about upcoming updates.
Use Unity Forums to read about others' work, share your work, and connect with
other developers, at http://forum.unity3d.com/.
Use Unity Answers to ask specific questions about issues that you have encountered.
Remember to be very specific, try to describe the problem in detail, and don't ask
general questions (for example, "Why is my GameObject not moving?"). Instead,
ask specifically, "GameObject not moving when adding a rigid body force" and then
describe the details. Posting your code under the question is also a very good idea.
[9]
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
All of these ways create a .cs file in the Unity Assets folder. From now on,
whenever I tell you to create a C# script, use whichever method you prefer.
Let's keep our scripts in the Scripts folder, textures in Textures, and so on so that it
looks something like this:
From now on, let's not keep any loose files in the Assets folder.
[ 10 ]
Random documents with unrelated
content Scribd suggests to you:
“You mean we’ve got him,” interrupted Constable Walker. “I helped
catch him jest th’ same as you.”
“So ye did, but I discovered the clues.”
“Never mind, officers,” spoke the Judge sharply, as he did not think it
dignified to have a dispute in his office. “Who is the prisoner?”
“A burglar!” exclaimed Constable Wolff.
“Dan Hardy!” answered Constable Walker in the same breath.
“You don’t mean to tell me Dan Hardy has been arrested as a
burglar?” said the justice, as much surprised as he thought it
consistent with his dignity to be.
“Yep, Squire—I mean Your Honor,” answered Mr. Wolff. “I catched—I
mean we catched him this mornin’. He robbed Dr. Maxwell’s house
last night, an’ we discovered part of th’ evidence on him,” and he
showed the spoon he had found in Dan’s pocket. “Now we want you,
if you will, t’ hold court, an’ properly commit him t’ jail, until th’ Grand
Jury can sit on his case.”
“Wait a minute!” exclaimed the Squire. “I am the person to judge
what is to be done in this case, not the officer who makes the arrest.
It may be that I will find it unnecessary to commit him for the action
of the Grand Inquest. I shall judge of that when I hear the evidence.”
“But he’s guilty, Mr. Perk—I mean Judge,” said Mr. Walker quickly.
“Silence!” cried the Squire, offended at the slip Mr. Walker had made.
“I am the proper person to decide that. You may bring the prisoner
before me in half an hour. Meanwhile I will look up certain points of
law, and I do not wish to be disturbed. Now clear the court,” and the
justice spoke as if there was a crowd of persons before him.
The truth was he wanted to be alone, to look up some authority in
the matter and see if he had a right to hold court in the case of a
burglar. He had never done so before.
It did not take Squire Perkfell long to determine that he had authority
to act in the case of a person charged with robbery, and then he
waited for the officers to bring Dan in.
Meanwhile the two constables went to the jail, and got their prisoner.
“What are you going to do with me now?” asked Dan, curiously.
“Ye’re goin’ t’ be tried,” said Mr. Wolff.
“Will Mr. Savage be there? I think I have a right to have his
testimony,” declared Dan, who, from having read of trials knew a little
about law.
“I s’pose he’ll be there,” replied Jacob Wolff. “Mebby ye won’t be so
glad t’ see him, after he tells what he knows. Hank Lee is goin’ t’
testify too.”
“What does he know about me?”
“Better wait, an’ see.”
“I am entitled to some rights in this matter,” went on Dan. “I should
be represented by a lawyer.”
“There ain’t none in town now,” said Mr. Walker. “John Burge has
gone t’ Canestota, and Ed Lancing is over t’ his mother’s. But Judge
Perkfell will know what t’ do.”
“I am entitled to a representative in court,” insisted Dan, “and if I
can’t have a lawyer I wish you would send for Mr. Harrison.”
“What, that blacksmith? He don’t know no law,” objected Jacob
Wolff.
“Maybe not, but he is my friend, and he told me to let him know when
I was in trouble, and I’m in trouble now.”
“Wa’al, I’ll tell him,” said Mr. Walker, not very kindly, for he did not
want to lose anything of what was to take place. “I’ll tell him t’ come t’
Squire Perkfell’s court. Jake, d’ ye think ye kin manage him?” and he
nodded at Dan.
“Oh, don’t be afraid, I’m not going to escape,” said the boy,
understanding what was meant.
“I guess ye’d better not,” spoke Mr. Wolff fiercely taking a better grip
on Dan’s coat sleeve.
While one constable went, rather reluctantly, to summon the veteran
blacksmith, the other led Dan toward Hank Lee’s store, a crowd of
persons gathering as soon as they emerged from the town hall.
“Where are we going?” asked Dan.
“Through th’ store, t’ th’ Judge’s office,” replied Mr. Wolff. “Th’ Judge,
he’s lookin’ up th’ law, an’ he don’t want t’ be disturbed fer half an
hour. We’ll wait in Hank’s store.”
“I had rather wait in jail,” spoke Dan, who felt he would be subjected
to ridicule and abuse in the grocery, with its crowd of men and boys.
“Mebby so, but ye can’t do as ye like when ye’re under arrest.”
He led the boy into the store. Though it was quite early there was a
big throng in it, for the rumor had spread that Dan was to have a
preliminary hearing, and all wanted to be present. They knew they
could go through the store into the Squire’s office.
“Clear th’ way fer th’ representative of th’ law!” exclaimed Jacob
Wolff, as he led Dan in.
“Jake’s in his glory now,” said one man.
“That’s right,” added another. “He’d rather be where he is than
President of th’ United States, I guess.”
Dan was led to a chair, near the door which opened into the Squire’s
office. The half hour was not quite up, and Mr. Wolff knew better than
to go in before it was time.
“So you got him, did you?” asked Hank Lee, coming over and
standing before the constable and his prisoner. “I always knowed he
was bad. He played a mean trick on me one day, and I reckon I’ve
got even with him now. I’ll get some reward, won’t I, for telling you he
was the robber?”
“Mebby so,” answered Mr. Wolff. He would have preferred Mr. Lee
should say nothing about his information, as, if he did, it might take
away from the glory coming to the two officers.
“Did you give the constables information that led to my false arrest?”
asked Dan indignantly, of Hank Lee.
“Yes, I did, and I’m glad they got you. Now I’m even with you for
setting that bull after me. I told you I’d fix you.”
“I didn’t set the bull after you, Mr. Lee, and it wasn’t my fault that you
were frightened by it.”
“I wasn’t frightened, I tell you! I jest ran because I was afraid he
might hit me, and knock the money out of my pocket. I got up in the
tree so’s I could count it and see if it was right.”
At this version of the story, so different from the truth Dan could not
help smiling. It was evident that Mr. Lee had told no one exactly what
had happened, or how he had begged Dan not to desert him, to go
for help.
“Oh, you’re laughing now,” sneered the storekeeper, as he saw the
smile on Dan’s face, “but you’ll be sorry enough when you’re behind
the bars. I always knowed you’d come to no good end. It runs in the
family.”
“See here!” exclaimed Dan, springing to his feet. “You can insult me,
if you will, because you are bigger and stronger than I am, but you
shan’t insult the memory of my father and mother! I come of as good
family as you do, and you know it. You gave false information about
me, because you have a grudge against me. I don’t know what it
was, but it wasn’t true, and I’ll prove it.”
Dan’s righteous anger seemed to get the best of him, and he
struggled to get loose from the restraining hold of Constable Wolff.
He had no idea what he wanted to do, except he felt as if he would
like to strike the mean storekeeper.
“Here! Hold on!” cried the officer, roughly dragging Dan back. “None
of that! You’re a prisoner!”
“Yes, you’re a felon!” added Mr. Lee with a sneer.
“I’d rather be an innocent prisoner than a coward!” cried Dan,
remembering how the storekeeper whined when the bull had him up
a tree.
“Who’s a coward?”
“You are. You were afraid to stay up the tree alone when I wanted to
go after help to catch the bull.”
“What’s that?” asked Sam Porter, one of the men in the store. “I
didn’t hear the story that way. Tell us about it, Dan.”
Hardly knowing why he did so, Dan related the story, showing the
cowardice of the storekeeper.
“Ha! Ha! Ho! Ho!” laughed Sam. “That’s a good one on you, Lee.
Treed by a bull, and dasn’t stick your foot down! Ha! Ho! That’s
prutty good!”
The rest of the crowd joined in the laugh at the discomfited Mr. Lee,
who angrily retired to his private office to make out bills. Dan had
gotten the best of him, and, somehow the sympathy of the crowd,
which had been rather against the boy, now turned his way.
Suddenly the door leading to the office of the Squire opened, and Mr.
Perkfell announced:
“Let the prisoner enter. I will now hold court.”
There was a scramble on the part of the crowd to get good seats,
and Constable Wolff led Dan in. As the boy was arraigned before the
Squire, Constable Walker came in, followed by Mr. Harrison. Dan’s
heart leaped, and his courage came back as he saw his sturdy
friend, the village blacksmith.
“We will now proceed with the hearing,” announced the justice.
“Order in the court!”
“LET THE PRISONER STAND UP,” SAID THE JUSTICE.—Page
115.
CHAPTER XIV
THE TRIAL
Several minutes passed before the crowd settled down. There was
not room for all to sit, and many stood up in the back part of the
room.
The two constables, placing Dan between them, took seats near the
Squire’s desk. Judge Perkfell put on his glasses and selected a book
from the pile in front of him. He took the first one he came to, and
opened it at random. This was only done to impress the onlookers.
“Ahem! Let the prisoner stand up,” called the justice.
Dan arose.
“Ahem! That will do, be seated.”
Dan did not see what that amounted to. Neither did any one else but
the Squire. To him it showed the power he had to make prisoners do
whatever he commanded.
“Where is the complainant in this case?” went on the justice.
No one answered.
“Is the complainant not present? Unless he answers at once I shall
commit him for contempt of court.”
“I don’t think there is any com—complainant, Judge,” spoke Mr.
Wolff, wondering what the word meant.
“What? No complainant? Why there must be, or we can not hold
court.”
“Can’t I get you one, your Honor?” asked Mr. Walker, determined to
make up for past offenses. “If you tell me where it is I’ll bring it.”
“The complainant is the person who makes the complaint—who
brings the charge—who accuses the prisoner,” explained the justice,
frowning, as he saw some persons smiling.
“Oh, I’m makin’ th’ charge,” replied Constable Wolff.
“So am I!” exclaimed his fellow officer quickly, for he was not going to
be left out of the affair.
“You are both complainants? Why, I understood it was Dr. Maxwell’s
house that was burglarized.”
“So it was,” said Mr. Walker quickly.
“Then Dr. Maxwell is the complainant. Is he present?”
“He has got to see a sick lady,” explained Silas Martin, the doctor’s
hired man, as he stood up in the back of the room, blushing very
much at the notice he attracted.
“Ah, in that case we will proceed without him, and we can have his
evidence later. A doctor is privileged to stay away from court, to
attend the sick, as laid down in the Atlantic Reporter, 638, Barker
versus Sanderson, but for no other cause. Otherwise I should have
had to commit Dr. Maxwell for contempt of court.”
There was a sort of gasp at this, as the Squire intended there should
be, for, as he thought, it showed his power.
“Meanwhile we will proceed with the case. I will hear the evidence of
the two representatives of the law.”
The constables straightened up in their chairs at thus hearing
themselves mentioned.
At that moment Mr. Harrison, the blacksmith, went over and took a
seat beside Dan.
“Here!” exclaimed the Judge. “What are you doing? You have no
right there.”
“I am here to look after the interest of the prisoner, Dan Hardy,” said
Mr. Harrison firmly.
“But you’re not a lawyer. You’re only a blacksmith.”
“I know it, Squire Perkfell, but one does not need to be a lawyer to
represent a person in the court of a justice of the peace. Your law
books will tell you that.”
Perhaps they would, but the Squire did not know where to look for
the information. He was half inclined to dispute the word of the
blacksmith, but he thought better of it.
Perhaps Mr. Harrison was right, and he was entitled to represent
Dan. The Squire knew enough of law to realize that a prisoner ought
to be represented by some one. He thought it ought to be a lawyer,
but if the blacksmith insisted, perhaps it would not be wise to
disagree with him.
“Very well,” announced the Justice, after a moment’s thought, “I will
allow you to represent the prisoner,—temporarily, however, only
temporarily. I may change my decision later, as the case develops.”
Mr. Harrison smiled.
“I now demand the right to have a few minutes private conversation
with my—my client,” said the blacksmith.
Squire Perkfell did not know what to do. This was something new in
his practice.
“Don’t do it!” exclaimed Constable Wolff. “Don’t allow it, your Honor.
It’s a plot t’ let him escape!”
“Silence!” cried the Squire. “I am in charge of this court!”
He dimly remembered once being at a trial where a lawyer made
such a demand, and the judge granted it. Squire Perkfell prided
himself on knowing law, and he wanted to do what was right, so he
said:
“Very well, your request is granted. But you must talk to the prisoner
in this room. You may withdraw to a corner.”
“That will do,” assented Mr. Harrison, and he led Dan to a part of the
room where he could converse with him quietly. The two constables
watched him narrowly. Dan told his friend all the events of the night
ride, including the finding of the spoon, and the actions of the
mysterious men. Then he led the boy back to his seat, and spoke to
the Squire.
“We are ready to proceed,” he said.
“Who is the first witness?” asked the justice, who, in the meanwhile,
had been asking Constable Wolff more about the case.
“Si Martin,” answered Jacob Wolff, who had assumed the role of
prosecutor. “He discovered the robbery.”
“Silas Martin, step forward,” called the Squire, and the doctor’s hired
man, blushing like a girl, shambled to the desk.
“Now tell the Court what you know.”
“I don’t know nothin’ about it. I didn’t see Dan steal anythin’. I don’t
believe he done it. Neither does Dr. Maxwell, an’ he told me t’ say
so. He’s comin’ here as soon as he can.”
“The court can not await the convenience of any one,” said the
justice with dignity. “Nor does it want you to express your opinion as
to the guilt or innocence of a prisoner. Just tell what you know of the
robbery.”
Thereupon Silas related what we already know, of how he
discovered that the house had been entered, and the silver and
other things taken. Next he told of his visit to the constables, and
what Mr. Lee had said regarding Dan’s midnight ride.
The storekeeper was called and gave his evidence. It began to look
black for Dan, especially when the constables added their story of
him being up the tree, and of the finding of the spoon in his pocket.
“That seems to be the case for the prosecution,” remarked the
Squire. “Is the defense ready to proceed?” And he looked at Mr.
Harrison.
“We are,” replied the blacksmith. “I want to ask some questions of
the witnesses. I did not interrupt them while they were testifying, as I
wanted to hear the whole story. First I would like to call Mr. Lee back
to the stand.”
“I ain’t got no time to bother with this case any more,” replied the
storekeeper. “I told all I know. I’ve got to go back and wait on some
customers.”
“Take the stand!” exclaimed the justice. “You are a material witness
in this case, and, until you are excused by the court, you must
remain. I will commit you for contempt if you go away.”
Mr. Lee scowled. He was angry at the justice, and he privately
resolved to raise his rent as soon as the case was over, for he
owned the office where the Squire held court.
CHAPTER XV
HELD IN BAIL
The blacksmith, who had made several notes when Dan told him the
story, looked at the paper in his hand. He had often seen court-
martial trials in the army and knew how to proceed.
“Mr. Lee,” he said, “you have testified to seeing the defendant, some
time early this morning, riding on a horse, and carrying a bundle. Is
that correct?”
“I seen Dan Hardy, if that’s who you mean.”
“Yes, he is the defendant in this case. Now will you state to the court
just how large this bundle was?”
“Wa’al, it wasn’t very big.”
“As big as a bushel basket?”
“No, of course not. He had it in his pocket, and I’d like to see any one
carry a bushel basket there and ride a horse.”
“Well, how big was it?”
“How do I know?”
“You said you saw it, and have so testified under oath.”
Mr. Lee squirmed in his seat.
“Wa’al,” he said at length, “I didn’t see it very plain. It was dark at the
time.”
“Yet you have stated to the court under oath that you saw Dan Hardy
very plainly when you got up to get something to stop your
toothache. You have testified that you saw him have a bundle. Now I
want you to state to the court the size of that bundle.”
The room was very still now. Clearly something was coming, and the
crowd did not want to miss it.
“Wa’al, I guess it was about as big as a quart measure,” said Mr. Lee
at length.
“You swear to that?”
“I s’pose so.”
“That will do.”
There was a murmur of surprise at the sudden ending of the
storekeeper’s testimony.
“Is that all?” asked Mr. Lee, apparently much relieved.
“Yes. Call Silas Martin.”
The hired man, still blushing, returned to the witness stand.
“Silas,” began the blacksmith in a kindly tone, “can you swear as to
how much stuff was taken away from Dr. Maxwell’s house?”
“Pretty near, Mr. Harrison.”
“What was it?”
“Wa’al, there was a lot of spoons, forks, knives, a big silver water
pitcher, a silver sugar bowl, a silver coffee pot, a silver coffee urn and
—”
“In fact there was quite a bulky lot of stuff, was there not?”
“Yes, sir.”
“About how large a bundle would it make?”
Once more the crowd gave a sort of gasp. They began to see to
what end Mr. Harrison was asking questions.
“Wa’al, I used t’ clean th’ pitchers, urns an’ sugar bowl once a week,”
testified Silas, “an’ I used t’ put ’em all in a basket t’ carry ’em out t’
th’ harness room t’ polish ’em.”
“How big a basket did you put them in, Silas?”
“Wa’al, by careful managin’ I could git th’ water pitcher, th’ milk
pitcher, th’ sugar bowl, th’ coffee pot an’ th’ tea pot in a bushel
basket.”
“Was there room for anything more?”
“Not a bit.”
“Then the things stolen from Dr. Maxwell’s house would more than fill
a bushel basket?”
“They’d pretty near fill two.”
“That is all, Silas.”
“Ye don’t want me no more?”
“No, I do not, but perhaps some of these other gentlemen might like
to question you,” and Mr. Harrison motioned to the two constables.
“No, I don’t want to,” said Mr. Wolff, and Mr. Walker also indicated
that he desired to take no part in the matter.
“Then I think you may go, Silas,” said Mr. Harrison.
“Before I go I want t’ say I don’t believe Dan Hardy robbed th’
house!” exclaimed Silas.
“Silence!” cried the justice, who, for the last few minutes had felt that
he was being ignored. “If you say that again I shall commit you for
contempt of court.”
“Wa’al, I said it all I want t’,” murmured Silas, as he went back to his
place in the rear of the room.
“Squire Perkfell,” began the blacksmith, “I think I have brought out
enough evidence to prove that Dan had no part in this robbery. Mr.
Lee has testified that the bundle Dan had was the size of a quart
measure. The doctor’s hired man, who is in a position to know,
swears that the booty taken from the house would more than fill a
bushel basket. I therefore submit that the bundle Dan had was not
stolen property, and I shall prove it.”
Mr. Savage was next called, and, though he was rather an unwilling
witness in behalf of Dan, he told of sending the lad to Mrs. Randall’s
house with the medicine, which was brought back. He thus
accounted for Dan’s night trip, and for the package the boy carried.
“Dan Hardy, take the stand,” called Mr. Harrison, and Dan, with firm
tread, and head held erect, walked forward to give his evidence. He
told of his night ride, and of seeing the mysterious men, also of his
intention to slip to the village and inform the constables without
bothering to tell Mr. Savage.
“What about th’ spoon we found in his pocket?” asked Constable
Wolff triumphantly.
“Explain that, Dan,” said Mr. Harrison, and Dan did so, telling how he
had found the article.
There was a murmur in the courtroom at this. It was plain that many
persons, if they did not believe Dan guilty, did think he was in league
with the robbers. There were sneering whispers.
“In view of what had been testified, and from the lack of any positive
evidence that my client was involved in this robbery, I respectfully
ask his discharge,” said Mr. Harrison.
“Don’t let him go free! He’s guilty!” exclaimed Constable Walker, who
hated to see his prisoner set at liberty.
“Silence!” cried the justice. “I shall commit you for contempt.”
He glared around in a menacing manner.
“Ahem!” he went on portentously. “I have carefully listened to all the
evidence in this case. The prisoner seems able to prove a fairly good
alibi—”
“What’s that. I wonder,” whispered Constable Walker to Constable
Wolff.
“Sh! That means he was somewhere else when he done th’ crime.”
“But how could he be somewhere’s else?—”
“Silence!” cried the justice, glaring at the two officers. Then he went
on:
“In spite of the seeming alibi, and the testimony about the size of the
bundle he had, the discovery of the spoon in his pocket is very
damaging. I shall express no opinion in the matter, but I feel obliged
to hold the prisoner in one thousand dollars bail to await the action of
the Grand Jury.
“If he can not furnish the bail, or a satisfactory bondsman, who owns
property worth at least twice the amount of the bail, I shall have to
commit the prisoner to jail. Court is adjourned.”
CHAPTER XVI
A FRIEND IN NEED
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.
ebooknice.com