100% found this document useful (1 vote)
50 views

Download ebooks file Building a 2D Game Physics Engine Using HTML5 and JavaScript Tanaya all chapters

Building

Uploaded by

bollihobelxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
50 views

Download ebooks file Building a 2D Game Physics Engine Using HTML5 and JavaScript Tanaya all chapters

Building

Uploaded by

bollihobelxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Building a 2D Game Physics Engine Using HTML5 and


JavaScript Tanaya

https://textbookfull.com/product/building-a-2d-game-physics-
engine-using-html5-and-javascript-tanaya/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

MonoGame Mastery: Build a Multi-Platform 2D Game and


Reusable Game Engine Jarred Capellman

https://textbookfull.com/product/monogame-mastery-build-a-multi-
platform-2d-game-and-reusable-game-engine-jarred-capellman/

textboxfull.com

Introducing JavaScript Game Development : Build a 2D Game


from the Ground Up 1st Edition Graeme Stuart

https://textbookfull.com/product/introducing-javascript-game-
development-build-a-2d-game-from-the-ground-up-1st-edition-graeme-
stuart/
textboxfull.com

Introducing JavaScript Game Development Build a 2D Game


from the Ground Up 1st Edition Graeme Stuart

https://textbookfull.com/product/introducing-javascript-game-
development-build-a-2d-game-from-the-ground-up-1st-edition-graeme-
stuart-2/
textboxfull.com

Pro HTML5 Games. Learn to build your own Games using HTML5
and JavaScript Aditya Ravi Shankar

https://textbookfull.com/product/pro-html5-games-learn-to-build-your-
own-games-using-html5-and-javascript-aditya-ravi-shankar/

textboxfull.com
Learn PHP 8: Using MySQL, JavaScript, CSS3, and HTML5
Second Edition Steve Prettyman

https://textbookfull.com/product/learn-php-8-using-mysql-javascript-
css3-and-html5-second-edition-steve-prettyman/

textboxfull.com

Building a Game with Unity and Blender Learn how to build


a complete 3D game using the industry leading Unity game
development engine and Blender the graphics software that
gives life to your ideas 1st Edition Lee Zhi Eng
https://textbookfull.com/product/building-a-game-with-unity-and-
blender-learn-how-to-build-a-complete-3d-game-using-the-industry-
leading-unity-game-development-engine-and-blender-the-graphics-
software-that-gives-life-to-your-ideas-1s/
textboxfull.com

Game Engine Architecture Jason Gregory

https://textbookfull.com/product/game-engine-architecture-jason-
gregory/

textboxfull.com

Unreal Engine 4 AI Programming Essentials Create


responsive and intelligent game AI using Blueprints in
Unreal Engine 4 1st Edition Peter L. Newton
https://textbookfull.com/product/unreal-engine-4-ai-programming-
essentials-create-responsive-and-intelligent-game-ai-using-blueprints-
in-unreal-engine-4-1st-edition-peter-l-newton/
textboxfull.com

New Perspectives on HTML5, CSS3, and JavaScript 6th


Edition Patric Carey

https://textbookfull.com/product/new-perspectives-on-html5-css3-and-
javascript-6th-edition-patric-carey/

textboxfull.com
Building a 2D Game
Physics Engine
Using HTML5 and JavaScript

Michael Tanaya
Huaming Chen
Jebediah Pavleas
Kelvin Sung
Building a 2D Game
Physics Engine
Using HTML5 and JavaScript

Michael Tanaya
Huaming Chen
Jebediah Pavleas
Kelvin Sung
Building a 2D Game Physics Engine: Using HTML5 and JavaScript
Michael Tanaya Huaming Chen
Bothell, Washington, USA Bothell, Washington, USA
Jebediah Pavleas Kelvin Sung
Kenmore, Washington, USA Woodinville, Washington, USA
ISBN-13 (pbk): 978-1-4842-2582-0 ISBN-13 (electronic): 978-1-4842-2583-7
DOI 10.1007/978-1-4842-2583-7
Library of Congress Control Number: 2017930129
Copyright © 2017 by Michael Tanaya, Huaming Chen, Jebediah Pavleas and Kelvin Sung
This work is subject to copyright. All rights are reserved 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.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image, we use the names, logos, and images only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of
the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject
to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Cover image designed by Freepik
Managing Director: Welmoed Spahr
Lead Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Jason Sturges
Coordinating Editor: Mark Powers
Copy Editor: Larissa Shmailo
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/us/
services/rights-permission.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Print and eBook Bulk
Sales web page at http://www.apress.com/us/services/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers for download via the book's product page, located at www.apress.com/9781484225820.
For more detailed information, please visit http://www.apress.com/us/services/source-code.
Printed on acid-free paper
To my love, Josephine Janice, for her companionship through many long
nights of writing, and my parents, Hendi and Ros,
for their support, advice, and love.
—Michael Tanaya

To my parents, Chen Yaoqing and Tang Hua,


for their encouragements and love.
—Huaming Chen

To my Mother, Diana, for the love and support she has given me
throughout my life.
—Jebediah Pavleas

To my wife, Clover, and our girls, Jean and Ruth, for completing my life.
—Kelvin Sung
Contents at a Glance

About the Authors����������������������������������������������������������������������������� xi


About the Technical Reviewer�������������������������������������������������������� xiii
Acknowledgements������������������������������������������������������������������������� xv
Introduction����������������������������������������������������������������������������������� xvii

■■Chapter 1: Introduction to 2D Game Physics


Engine Development����������������������������������������������������������������������� 1

■Chapter 2: Implementing the 2D Physics Engine Core����������������� 15

■Chapter 3: Incorporating Collision Detection������������������������������� 37
■■Chapter 4: Completing the Physics Engine and
Rigid Shape Component��������������������������������������������������������������� 71

■Chapter 5: Summarizing the Physics Engine����������������������������� 105

Index���������������������������������������������������������������������������������������������� 113

v
Contents

About the Authors����������������������������������������������������������������������������� xi


About the Technical Reviewer�������������������������������������������������������� xiii
Acknowledgements������������������������������������������������������������������������� xv
Introduction����������������������������������������������������������������������������������� xvii

■■Chapter 1: Introduction to 2D Game Physics


Engine Development������������������������������������������������������������������������������ 1
Setting Up Your Development Environment��������������������������������������������� 2
Downloading and Installing JavaScript Syntax Checker������������������������� 3
Working in the NetBeans Development Environment������������������������������ 3
Creating an HTML5 Project in NetBeans������������������������������������������������������������������� 4
The Relationship Between the Project Files and the File System ��������������������������� 8

HTML5 Canvas Project���������������������������������������������������������������������������� 8


Drawing Core������������������������������������������������������������������������������������������� 9
Creating the HTML Canvas������������������������������������������������������������������������������������� 10
Creating the Core Script����������������������������������������������������������������������������������������� 10

User Control������������������������������������������������������������������������������������������� 12
Creating User Control Script����������������������������������������������������������������������������������� 12
Using the User Control Script��������������������������������������������������������������������������������� 13

Summary����������������������������������������������������������������������������������������������� 14

vii
■ CONTENTS


■Chapter 2: Implementing the 2D Physics Engine Core����������������� 15
Vector Calculation Library��������������������������������������������������������������������� 16
Creating the Library������������������������������������������������������������������������������������������������ 16

Physics Engine and Rigid Shapes��������������������������������������������������������� 17


The Rigid Shape Project����������������������������������������������������������������������������������������� 18
Observation������������������������������������������������������������������������������������������������������������ 27
The Core Engine Loop��������������������������������������������������������������������������� 27
Engine Loop Implementations�������������������������������������������������������������������������������� 28
The Core Engine Loop Project��������������������������������������������������������������������������������� 29
Observation������������������������������������������������������������������������������������������������������������ 35

Summary����������������������������������������������������������������������������������������������� 36

■Chapter 3: Incorporating Collision Detection������������������������������� 37
Interpenetration of Colliding Objects����������������������������������������������������� 38
Collision Detection��������������������������������������������������������������������������������� 40
Broad Phase Method����������������������������������������������������������������������������� 40
The Broad Phase Method Project��������������������������������������������������������������������������� 40
Observation������������������������������������������������������������������������������������������������������������ 45

Collision Information����������������������������������������������������������������������������� 45
The Circle Collision Detection Project��������������������������������������������������������������������� 46
Observation������������������������������������������������������������������������������������������������������������ 52

Separating Axis Theorem ��������������������������������������������������������������������� 52


A Simple SAT-based Algorithm������������������������������������������������������������������������������� 54
An Efficient SAT Algorithm: The Support Points������������������������������������������������������ 56
The Rectangle Collision Project������������������������������������������������������������������������������ 58
Observation������������������������������������������������������������������������������������������������������������ 62

viii
CONTENTS ■

Collision Between Rectangles and Circles�������������������������������������������� 62


The Rectangle Circle Collision Project�������������������������������������������������������������������� 63
Observation������������������������������������������������������������������������������������������������������������ 69

Summary����������������������������������������������������������������������������������������������� 69
■■Chapter 4: Completing the Physics Engine and Rigid Shape
Component����������������������������������������������������������������������������������� 71
Movement��������������������������������������������������������������������������������������������� 72
Explicit Euler Integration���������������������������������������������������������������������������������������� 73
Symplectic Euler Integration���������������������������������������������������������������������������������� 74

Implementing Symplectic Euler Integration and Defining Attributes to


Support Collision Response������������������������������������������������������������������� 74
The Rigid Shape Movement Project������������������������������������������������������������������������ 74
Observation������������������������������������������������������������������������������������������������������������ 82

Resolving Interpenetrations������������������������������������������������������������������ 83
The Positional Correction Project��������������������������������������������������������������������������� 84
Observation������������������������������������������������������������������������������������������������������������ 87

Resolving Collisions������������������������������������������������������������������������������ 87
Formulating the Impulse Method��������������������������������������������������������������������������� 88
The Steps for Resolving Collisions������������������������������������������������������������������������� 92
The Collision Impulse Project��������������������������������������������������������������������������������� 93
Observation������������������������������������������������������������������������������������������������������������ 96
Supporting Rotation in Collision Response������������������������������������������� 96
Integrating Newtonian Mechanics for Rotation������������������������������������������������������ 97
Formulating Impulse Method with Rotation����������������������������������������������������������� 97
The Angular Impulse Project��������������������������������������������������������������������������������� 100
Observation���������������������������������������������������������������������������������������������������������� 102

Summary��������������������������������������������������������������������������������������������� 103

ix
■ CONTENTS


■Chapter 5: Summarizing the Physics Engine����������������������������� 105
The Concepts and Theories ���������������������������������������������������������������� 105
The Engine Source Code��������������������������������������������������������������������� 106
The Cool Demo Project������������������������������������������������������������������������ 108
Modifying Simulation Scene��������������������������������������������������������������������������������� 108
Observation���������������������������������������������������������������������������������������������������������� 109

Further Exploration and Related Topics����������������������������������������������� 110


Physics Topics������������������������������������������������������������������������������������������������������ 110
Collision Detection Topics������������������������������������������������������������������������������������� 111

Reference�������������������������������������������������������������������������������������������� 112

Index���������������������������������������������������������������������������������������������� 113

x
About the Authors

Michael Tanaya is an international graduate student from Indonesia in the Computer


Science and Software Engineering program at the University of Washington Bothell
(UWB). He received his Bachelor of Computer Science in 2014 from the University of
Minnesota at Twin Cities. During his time as an undergraduate, he took interests in
computer games and web application development. In his free time, he enjoys playing
competitive video games, designing and developing video games with Unity™ and
Cocos2D™. Currently Michael is working with Professor Kelvin Sung on developing a
system that integrates Virtual and Augmented Reality technologies in creating a
learning multimedia environment for active hands-on learning. He will be graduating
in Spring 2017.

Huaming Chen is an international graduate student from China in the Computer Science
and Software Engineering program at the University of Washington Bothell (UWB). He
received dual undergraduate degrees, in Computer Science and Economics, from Xiamen
University in 2015. During his time as an undergraduate, he was interested in data mining
and videogame design. His project includes a structure of website groups that related to
each other and a software system that recommends useful information based on the
website groups. He also developed a mobile game based on Unity3D. Currently, Huaming
is working on a project that focuses on designing videogames that simplify vision therapy
for children. He will be graduating in Spring 2017.

Jebediah Pavleas is a software engineer who received his Master of Science in


Computer Science and Software Engineering from the University of Washington
Bothell (UWB) in 2016 as well as a Bachelor of Science in 2012, where he was the
recipient of the Chancellor’s Medal for his class. In 2015 he interned at Microsoft
Research, where he worked on improving the safety and usability of an eye gaze
wheelchair. During his time as a student, he took a great interest in both computer
graphics and games. His projects included an interactive math application that
utilizes Microsoft’s Kinect sensor to teach algebra and a 2D role-playing game
designed to teach students introductory programming concepts. Relating to these
projects, he co-authored publications in IEEE Computers and The Journal of
Computing Sciences in Colleges. He enjoys designing, building, and playing games of
all kinds, as well as adapting technology for improved accessibility. Jebediah is also
the primary author of Learn 2D Game Development with C# (APress, December 2013)
and co-author of Build Your Own 2D Game Engine and Create Great Web Games
(Apress, October 2015).

xi
■ ABOUT THE AUTHORS

Kelvin Sung is a professor with the Computing and Software Systems division at
University of Washington Bothell (UWB). He received his Ph.D. in Computer Science
from the University of Illinois at Urbana-Champaign. Kelvin's background is in computer
graphics, hardware, and machine architecture. He came to UWB from Alias|Wavefront
(now part of Autodesk), where he played a key role in designing and implementing the
Maya Renderer, an Academy Award-winning image generation system. Funded by
Microsoft Research and the National Science Foundation, Kelvin’s recent work focused
on the intersection of video game mechanics, solutions to real-world problems, and
mobile technologies. Together with his students, Kelvin has co-authored three recent
books: one in computer graphics (Essentials of Interactive Computer Graphics: Concepts
and Implementations, A.K. Peters, 2008), and the others in 2D game engines (Learn 2D
Game Development with C#, APress, December 2013; and Build Your Own 2D Game
Engine and Create Great Web Games, Apress, October 2015).

xii
About the Technical
Reviewer
Jason Sturges is a cutting edge technologist focused on ubiquitous delivery of immersive
user experiences. Coming from a visualization background, he’s always pushing the
boundaries of computer graphics to the widest reach across platforms while maintaining
natural and intuitive usability per device. From interactivity, motion, and animation to
creative design, he has worked with numerous creative agencies on projects from kiosks
to video walls to Microsoft Kinect games. Most recently, the core of his work has been
mobile apps. Committed to the open source community, he is also a frequent contributor
at GitHub and Stack Overflow as a community resource leveraging modern standards,
solid design patterns, and best practices in multiple developer tool chains for web,
mobile, desktop, and beyond.

xiii
Acknowledgments

This and our prior books on Games and Game Engine development are the direct result
of the authors learning from building games for the Game-Themed CS1/2: Empowering
the Faculty project, funded by the Transforming Undergraduate Education in Science
Technology, Engineering, and Mathematics (TUES) Program, National Science
Foundation (NSF) (award number DUE-1140410). We would like to thank NSF officers
Suzanne Westbrook for believing in our project and Jane Prey, Valerie Bar, and Paul
Tymann for their encouragement.
The invaluable collaboration between the technical team in the Game-Themed
Research Group (https://depts.washington.edu/cmmr/GTCS/) and the design team
in the Digital Future Lab (http://www.bothell.washington.edu/digitalfuture) at
the University of Washington Bothell (where much of our learning occurred during
the production of the many casual games for teaching introductory programming
concepts) formed the foundation that allowed the development of this book. Thank
you to all the participants of this research undertaking. The authors would also like
to thank the students at the University of Washington Bothell for the games they built
from the course CSS385: Introduction to Game Development (see http://courses.
washington.edu/css385). Their interest and passion for games has provided us with the
ideal deployment vehicle and are a source of continuous inspiration. They have tested,
retested, contributed to, and assisted in the formation and organization of the contents of
this book.
Jebediah Pavleas would like to thank the Computing and Software Systems Division
at the University of Washington Bothell for the generous tuition scholarships that funded
his education throughout his participation with this book project.
Thanks to Clover Wai, for once again helping us with the figures and illustrations in
this book.
We also want to thank Steve Anglin at Apress for believing in this project, to our
editor Mark Powers for his patience and toleration with our constantly behind-schedule
frenzy. Finally, we would like to thank Jason Sturges for his insightful technical feedback.
All opinions, findings, conclusions, and recommendations in this work are those of
the authors and do not necessarily reflect the views of the sponsors.

xv
Introduction

Welcome to Building a 2D Game Physics Engine: Using HTML5 and JavaScript. Because you
have picked up this book, you are likely interested in the details of a game physics engine
and the creation of your own games to be played over the Internet. This book teaches
you how to build a 2D game physics engine by covering the involved technical concepts,
and providing detailed implementations for you to follow. The source code in this book
is provided in HTML5 and JavaScript, which are technologies that are freely available and
supported by virtually all web browsers. After reading this book, the game physics engine
you develop will be playable through a web browser from anywhere on the Internet.
This book focuses only on the relevant concepts and implementation details for
building a 2D game physics engine. The presentations are tightly integrated with the
analysis and development of source code. Much of the book guides you in implementing
related concepts and building blocks while the actual functioning engine only becomes
available towards the end. Some of the algorithms and mathematics can be challenging.
Be patient. It will all pay off by the end of Chapter 4. By Chapter 5, you will be familiar
with the concepts and technical details of 2D game physics engines, and feel competent
in implementing the associated functionality.

Who Should Read This Book


This book is targeted toward programmers who are familiar with basic object-oriented
programming concepts and have a basic to intermediate knowledge of an object-oriented
programming language such as Java or C#. For example, if you are a student who has
taken a few introductory programming courses, an experienced developer who is new to
games and graphics programming, or a self-taught programming enthusiast, you will be
able to follow the concepts and code presented in this book with little trouble. If you’re
new to programming in general, it is suggested that you first become comfortable with
the JavaScript programming language and concepts in object-oriented programming
before tackling the content provided in this book.

Assumptions
You should have some basic background in Newtonian Mechanics and be experienced
with programming in an object-oriented programming language, such as Java or C#.
Knowledge and expertise in JavaScript would be a plus but is not necessary. The examples
in this book were created with the assumption that you understand data encapsulation
and inheritance. In addition, you should be familiar with basic data structures such as
linked lists and dictionaries, and be comfortable working with the fundamentals of algebra
and geometry, particularly linear equations and coordinate systems.

xvii
■ INTRODUCTION

Who Should Not Read This Book


This book is not designed to teach readers how to program, the formal mathematics of
physics, nor does it attempt to explain the intricate details of HTML5 or JavaScript. If you
have no prior experience developing software with an object-oriented programming
language, you will probably find the examples in this book difficult to follow.
On the other hand, if you have an extensive background in game physics engine
development based on other platforms, the content in this book will be too basic; this is a
book intended for developers without 2D game physics engine development experience.

Organization of This Book


This book teaches how to develop a game physics engine by describing the foundational
infrastructure, collision detection algorithms, information that should be gathered during
a collision, and approaches to resolving and computing responses after a collision.
Chapter 2 introduces the foundational infrastructure, including the mathematics library,
and supporting framework for game loop, user input, and basic drawing. Chapter 3 focuses on
how to detect collisions covering efficiency, generality, and vital information to record during
a collision. Chapter 4 integrates the building blocks from the previous two chapters and
presents the details on simulating motions and computing responses after a collision.
Chapter 5 summarizes the book with a demonstration program and references for further
readings.

Code Samples
Every chapter in this book includes examples that let you interactively experiment with
and learn the new materials. You can download the source code for all the projects,
including the associated assets (images, audio clips, or fonts), from the following page:
www.apress.com/9781484225820.
Follow the instructions to download the 9781484225820.zip file. To install the code
samples, unzip the 9781484225820.zip file. You should see a folder structure that is
organized by chapter numbers. Within each folder are subfolders containing NetBeans
projects that correspond to sections of this book.

xviii
CHAPTER 1

Introduction to 2D Game
Physics Engine Development

Physics engines play an important part in many types of games. A believable physics
interaction between game objects has become a key element of most modern PC and
console games as well as, more recently, browser and smartphone games. The range of
topics within physics for games is broad and includes, but is not limited to, areas such
as rigid body, fluid dynamics, soft-body, vehicle physics, and particle physics. This book
will cover the fundamental topics needed for you to get started in understanding and
building a general purpose, rigid body physics engine in two dimensions. The book also
aims to provide you with a reusable game physics engine, which can be used for your
own games, by guiding you through the process of building a physics engine step-by-step
from scratch. This way you will gain a foundational understanding of the concepts and
components required for a typical 2D rigid body system.
While you can just download a physics engine library and continue on with your
game or engine development, building your own game engine from scratch has its own
advantages. Besides giving you an underlying understanding of how the physics engine
operates, it gives you more control over the flexibility, performance, functionality, and
usability of the engine itself.
As stated, this book will cover the foundation of 2D rigid body physics. The topics will
include properties and behavior of rigid bodies, collision detection, collision information
encoding, and collision response. The goal is to obtain a fundamental understanding of
these concepts which are required to build a usable physics engine.
The book approaches physics engine development from three important avenues:
practicality, approachability, and reusability. While reading the book, we want you to get
involved and experience the process of building the game engine. The step-by-step guide
should facilitate the practicality of this book. The theories and practices introduced in this
book are based on research and investigation from many sources which cover the topics in
varying detail. The information is presented in a way that is approachable, by allowing you
to follow along as each code snippet is explained in parallel to the overall concepts behind

Electronic supplementary material The online version of this chapter


(doi:10.1007/978-1-4842-2583-7_1) contains supplementary material, which is available
to authorized users.

© Michael Tanaya, Huaming Chen, Jebediah Pavleas and Kelvin Sung 2017 1
M. Tanaya et al., Building a 2D Game Physics Engine, DOI 10.1007/978-1-4842-2583-7_1
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

each component of the engine. After following along and creating your own engine, you
will be able to extend and reuse the finished product by adding your own features.
This chapter describes the implementation technology and organization of the
book. The discussion then leads you through the steps of downloading, installing, and
setting up the development environment; guides you through building your first HTML5
application; and extends this first application with the JavaScript programming language
to run your first simulation.

Setting Up Your Development Environment


The physics engine you are going to build will be accessible through web browsers that
could be running on any operating system (OS). The development environment you are
about to set up is also OS agnostic. For simplicity, the following instructions are based on
a Windows 7/8/10 OS. You should be able to reproduce a similar environment with minor
modifications in a Unix-based environment like the Apple macOS or Ubuntu.
Your development process includes an integrated development environment (IDE)
and a runtime web browser that is capable of hosting the running game engine. The most
convenient systems we have found are the NetBeans IDE with the Google Chrome web
browser as the runtime environment. Here are the details:
• IDE: All projects in this book are based on the NetBeans IDE. You
can download and install the bundle for HTML5 and PHP from
https://netbeans.org/downloads.
• Runtime environment: You will execute your projects in the
Google Chrome web browser. You can download and install this
browser from https://www.google.com/chrome/browser/.
• Connector Google Chrome plug-in: This is a Google Chrome
extension that connects the web browser to the NetBeans IDE to
support HTML5 development. You can download and install this
extension from https://chrome.google.com/webstore/detail/
netbeans-connector/hafdlehgocfcodbgjnpecfajgkeejnaa.
The download will automatically install the plug-in to Google
Chrome. You may have to restart your computer to complete the
installation.
Notice that there are no specific system requirements to support the JavaScript
programming language or HTML5. All these technologies are embedded in the web
browser runtime environment.

■■Note As mentioned, we chose a NetBeans-based development environment because


we found it to be the most convenient. There are many other alternatives that are also free,
including and not limited to IntelliJ IDEA, Eclipse, Sublime, Microsoft’s Visual Studio Code,
and Adobe Brackets.

2
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Downloading and Installing JavaScript


Syntax Checker
We have found JSLint to be an effective tool in detecting potential JavaScript source code
errors. You can download and install JSLint as a plug-in to the NetBeans IDE with the
following steps:
• Download it from http://plugins.netbeans.org/
plugin/40893/jslint. Make sure to take note of the
location of the downloaded file.
• Start NetBeans, select Tools ➤ Plugins, and go to the
Downloaded tab.
• Click the Add Plugins button and search for the downloaded file
from step 1. Double-click this file to install the plug-in.
The following are some useful references for working with JSLint:
• For instructions on how to work with JSLint, see
http://www.jslint.com/help.html.
• For details on how JSLint works, see
http://plugins.netbeans.org/plugin/40893/jslint.

Working in the NetBeans Development


Environment
The NetBeans IDE is easy to work with, and the projects in this book require only the
editor and debugger. To open a project, select File ➤ Open Projects. Once a project
is open, you need to become familiarized with three basic windows, as illustrated in
Figure 1-1.
• Projects window: This window displays the source code files of the
project.
• Editor window: This window displays and allows you to edit the
source code of your project. You can select the source code file to
work with by double-clicking the corresponding file name in the
Projects window.
• Action Items window: This window displays the error message
output from the JSLint checker.

3
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Figure 1-1. The NetBeans IDE

■■Note If you cannot see a window in the IDE, you can click the Window menu and select
the name of the missing window to cause it to appear. For example, if you cannot see the
Projects window in the IDE, you can select Window ➤ Projects to open it.

Creating an HTML5 Project in NetBeans


You are now ready to create your first HTML5 project.
1. Start NetBeans. Select File ➤ New Project (or press
Ctrl+Shift+N), as shown in Figure 1-2. A New Project
window will appear.

4
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Figure 1-2. Creating a new project

2. In the New Project window, select HTML5 in the Categories


section, and select HTML5 Application from the Projects
section, as shown in Figure 1-3. Click the Next button to bring
up the project configuration window.

Figure 1-3. Selecting the HTML5 project

3. As shown in Figure 1-4, enter the name and location of the


project, and click the Finish button to create your first HTML5
project.

5
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Figure 1-4. Naming the project

NetBeans will generate the template of a simple and complete HTML5 application
project for you. Your IDE should look similar to Figure 1-5.

Figure 1-5. The HTML5 application project

6
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

By selecting and double-clicking the index.html file in the Projects window, you
can open it in the Editor window and observe the content of the file. The contents are as
follows:

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
</head>
<body>
<div>TODO write content</div>
</body>
</html>

The first line declares the file to be an HTML file. The block that follows within the
<!-- and --> tags is a comment block. The complementary <html></html> tags contain
all the HTML code. In this case, the template defines the head and body sections. The
head sets the title of the web page, and the body is where all the content for the web page
will be located.
You can run this project by selecting Run ➤ Run Project or by pressing the F6 key.
Figure 1-6 shows an example of what the default project looks like when you run it.

Figure 1-6. Running the simple HTML5 project

To stop the program, either close the web page or click the Cancel button in the
browser to stop NetBeans from tracking the web page. You have successfully run your first
HTML5 project. You can use this project to understand the IDE environment.

7
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

The Relationship Between the Project Files and


the File System
Navigate to the HTML5Application project location on your file system, for example with
the Explorer OS utility in Windows. You can observe that in the project folder, NetBeans
has generated the nbProject, public_html, and test folders. Table 1-1 summarizes the
purpose of these folders and the index.html file.

Table 1-1. Folders and files in a NetBeans HTML5 project

NetBeans HTML5 project: folder/file Purpose


nbProject/ This folder contains the IDE configuration files.
You will not modify any of the files in this folder.
public_html/ This is the root folder of your project. Source
code and assets from your project will be
created in this folder.
public_html/index.html This is the default entry point for your web site.
This file will be modified to load JavaScript
source code files.
test/ This is the default folder for unit testing source
code files. This folder is not used in this book
and has been removed from all the projects.

HTML5 Canvas Project


This project demonstrates how to set up the core drawing functionality for the engine as
well as define a user control script. Figure 1-7 shows an example of running this project,
which is defined in the project folder.

8
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Figure 1-7. Running the HTML5 project with drawing core and user control

The goals of the project are as follows:


• To learn how to set up the HTML canvas element
• To learn how to retrieve the canvas element from an HTML
document for use in JavaScript
• To learn how to create a reference context to an HTML canvas,
and use it to manipulate the canvas
• To get familiar with basic user control scripting

Drawing Core
This engine will use simple drawing code for the sole purpose of simulating the physics
engine code. After all, the only thing the simulation needs to show is how simple objects
interact after the physics engine code is implemented. Thus, advanced graphical
functionalities such as illumination, texturing, or shadow rendering will only serve to
further complicate the code base. For that reason, a simple HTML5 canvas with primitive
drawing support will serve the purpose of rendering the physics simulation during
creation and debugging.

9
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Creating the HTML Canvas


In this step, you will create an empty HTML5 canvas for the drawing of all the objects.
1. Open the index.html file in the editor by double-clicking
the project name in the project view, then open the Site Root
folder, and double-click the index.html file.
2. To create your HTML canvas for drawing, add the following
line in the index.html file within the body element

<table style="padding: 2px">


<tr>
<td>
<div>
<canvas id="canvas"></canvas>
</div>
</td>
</tr>
</table>

The code defines a canvas element with an id of canvas. An id is the name of the
element and can be used to retrieve the corresponding element when the web page is
loaded. Notice that no width and height is specified in the code. This is because you will
specify those attributes in the next step. You will use the canvas id to retrieve the reference
to the actual canvas drawing area where you will draw into.

Creating the Core Script


This section details the steps needed to create your first script, the drawing canvas
initialization. This script will evolve to contain more core functionalities for the physics
engine. For this step, you will only write the initialization code for the drawing canvas.
1. Create a new folder named EngineCore inside the SiteRoot
(or public_html) folder by right-clicking and creating a
new folder.
2. Create a new JavaScript file within the EngineCore folder by
right-clicking the EngineCore folder. Name the file Core.js.
3. Open the new Core.js file for editing.
4. Create a static reference to gEngine by adding the following
code.
var gEngine = gEngine || {};
gEngine.Core = (function () {
}());

gEngine.Core is where all the physics engine core


functionality will reside.

10
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

■■Note All global variable names begin with a “g” and are followed by a capital letter, as
in gEngine.

5. Inside the gEngine.Core you want to access and define the


width and height of the canvas element. To do this you will
create a variable mCanvas, and reference it to the canvas
element of index.html such that you could set and modify the
canvas attributes. You also need the variable mContext, which
will keep a reference to all the methods and properties needed
to draw into the canvas. Add the following code to accomplish
these.

var mCanvas, mContext, mWidth = 800, mHeight = 450;


mCanvas = document.getElementById('canvas');
mContext = mCanvas.getContext('2d');
mCanvas.height = mHeight;
mCanvas.width = mWidth;

■■Note All instance variable names begin with an “m” and are followed by a capital letter,
as in mCanvas.

6. Create an object variable mPublic, because you need to make


some of the engine core variables and functions accessible by
other scripts later in the development of the engine. For now,
mPublic will only need to keep three variables accessible, that
is, the width and height of canvas, and the mContext to draw
into the canvas.

var mPublic = {
mWidth: mWidth,
mHeight: mHeight,
mContext: mContext
};
return mPublic;

7. Finally, for the Core.js to be included in the simulation, you


need to add it into the index.html file. To do this, simply add
the following code inside the body element.

<script type="text/javascript" src="EngineCore/Core.js"></script>

11
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

User Control
In this section, you will be introduced to basic user control event handlers using
JavaScript. This is to enable you to test your implementation in every step of the physics
engine’s incremental development. For this chapter, the user control script will be used
to test if you have correctly initialized the canvas and implemented drawing functionality
properly.

Creating User Control Script


Let’s get started:
1. Create a new JavaScript File within the SiteRoot folder by
right-clicking the SiteRoot (or public_html) folder. Name the
file UserControl.js.
2. Open the new UserControl.js file for editing
3. Here you want to create a function that will handle all the
keyboard input. Let’s name the function userControl. This
function will have a variable called keycode that will keep
track of the user keyboard input. To do this, add the following
code inside the UserControl.js.

function userControl(event) {
var keycode;
}

4. Since some browsers handle input events differently, you


want to know in which type of browser the simulation will
run. Add the following code within the control function
to distinguish between an IE key event handler and other
browser key event handler.

if (window.event) { // IE
keycode = event.keyCode;
}
else if (event.which) { // Netscape/Firefox/Opera
keycode = event.which;
}

This script will enable you to handle keyboard input events from the browser as well
as process the input and response accordingly. In this case, you want to test the canvas
you just created in the last section. This testing can be achieved by drawing rectangles
and circles when keyboard inputs are received, as detailed in the next section.

12
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

Using the User Control Script


In this section, you will complete the UserControl.js file for this chapter by adding some
user input responses to draw a rectangle or a circle in random positions on the canvas
when F or G keys are pressed.
The control script will be triggered by the HTML onkeydown event. It is important to
recognize that in the browser, each keyboard key is associated with a unique key code.
For example, “a” is associated with a keycode of 65, “b” is 66, and so on.

■■Note The UserControl.js will evolve over the development to handle more keyboard
inputs and more complex responses.

1. Open the UserControl.js file for edit.


2. You need to access the width and height of canvas, and the
context to draw into the canvas. Add the following lines of
code inside the control function.

var width = gEngine.Core.mWidth;


var height = gEngine.Core.mHeight;
var context = gEngine.Core.mContext;

3. Create a rectangle at a random position if the “F” key (with


key code value of 70) is pressed, and a circle if the “G” key
(with key code value of 71) is pressed. Add the following lines
to accomplish this task.

if (keycode === 70) { //f


//create new Rectangle at random position
context.strokeRect(Math.random() * width * 0.8,
// x position of center
Math.random() * height * 0.8,
// y position of center
Math.random() * 30 + 10, Math.random() * 30 + 10);
// width and height location
}
if (keycode === 71) { //g
//create new Circle at random position
context.beginPath();
//draw a circle
context.arc(Math.random() * width * 0.8,
// x position of center
Math.random() * height * 0.8,
// y position of center
Math.random() * 30 + 10, 0, Math.PI * 2, true);

13
Chapter 1 ■ Introduction to 2D Game Physics Engine Development

// radius
context.closePath();
context.stroke();
}

4. Next, for the UserControl.js to be included in the simulation,


you need to add it into the index.html file. To do this, simply
add the following code inside the body element.

<script type="text/javascript" src="EngineCore/Control.js">


</script>

5. Finally, you want HTML to handle the key pressing event.


Open the index.html file to edit and add the onkeydown
attribute to the body tag to call your JavaScript function
control. Modify your index.html file so the body tag will look
like the following.

<body onkeydown="return userControl(event);" >

Now if you run the project and press the key F or G, the simulation will draw either
a circle or rectangle at a random position with random sizes as shown in Figure 1-7 above.

Summary
By this point the physics engine’s basic drawing function has been initialized, and
should be able to draw a rectangle and a circle onto the canvas with basic input required
from the user. In this chapter, you have structured the source code that supports future
increase in complexity with a simple way to draw rigid bodies. You are now ready to
extend the functionalities and features of your project into a physics engine. The next
chapter will focus on the core functionalities needed for any game or physics engine
(engine loops, vector calculation), as well as evolving rectangles and circles into rigid
body object-oriented objects to encapsulate their drawing and behaviors.

14
Another Random Scribd Document
with Unrelated Content
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
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.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
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!

textbookfull.com

You might also like