3D Game Programming for Kids
Create Interactive Worlds with JavaScript
by Chris Strom
Version: P1.0 (September, 2013)
Copyright 2013 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
For Greta, so that she knows she can do anything.
Table of Contents
Playing with the Console and Finding Whats Broken |
Copyright 2013, The Pragmatic Bookshelf.
Early praise for 3D Game Programming for Kids
I was thrilled how much my son got into programming as a result of this book. He spent hours with it and was often surprised when his screen time was over because the time just flew by. Although the book doesnt delve into the fundamentals of software programming (how computers store and retrieve data), kids get to see the results of their programming right awaythe pictures and animations that they createdand are hooked into wanting to learn more.
Mark Musante, professional software designer |
I would recommend this book to anyone my age that is interested in coding or technology. It was very helpful and insightful about the basic (and the more complex) parts of standard coding. This book would be great for anyone looking to jump head-first into coding.
This is the best book a beginning programmer could get. It teaches programming concepts in fun and entertaining ways. This book is a great start in learning to program!
It has been great fun reading this book. It takes me back to when I fell in love with programming. After having spent the past twenty years programming solutions on the server side, I find this 3D book a welcome diversion that offers new concepts and ideas with instant visual feedback! I hope the book finds its way into the hands of an inquisitive child who gets hooked on computer programming like I did.
Darren Hunt, director of Algorithmic Solutions Limited |
Acknowledgments
I am nothing without my lovely wife, Robin. Not only does she put up with me disappearing for days on end to write, but she also helps in ways innumerable. She was the primary proofreader for the early versions of the book. She helps to run the kid hackathons (OK, she runs them) that aided in development of this book. And oh, yeahshes an awesome wife and mother.
Also a big thanks to my son Luke for being the primary guinea pig for the early versions of the book. His no-nonsense feedback made this a better product. Thanks also to my daughter Elora for chiming in with her insights.
And, of course, huge thanks to my technical reviewers. It is a tough task to review a book from a kids perspective, but my reviewers were more than up to the task. In no particular order, they are Alec M., Hana B., Dave S., Thad K., Maik Schmidt, Silvia Domenech, and Mark Musante.
Special thanks to Sophie H., who provided the inspiration for the game that eventually became Chapter 11, .
This book would not exist without the great work of Ricardo Cabello Miguel, affectionately known as Mr.doob. Ricardo is the primary programmer behind Three.js, the 3D JavaScript library that we use in this book. He also wrote the original implementation of the ICE Code Editor that we use. This book would be significantly less without his amazing talents. Thanks also to Chandler Prall for his work on the Physijs physics engine, of which we make extensive use. Chandler was also wonderful about answering my many, many questions while I was learning.
Last, but not least, many thanks to the folks at The Pragmatic Programmers for believing in the book and helping me realize its full potential. Special thanks to my editor, Fahmida, for keeping me honest and focused.
Copyright 2013, The Pragmatic Bookshelf.
Introduction
Welcome to the world of programming!
I wont lie; it can be a frustrating world sometimes (it makes me cry at least once a week). But its totally worth the pain. You get to make this world do whatever you want. You can share your world with others. You can build things that really make a difference.
This book that you hold in your eager hands is a great way to get started programming. It is chock-full of clear and understandable explanations. Best of all, we get to make some pretty cool games.This is going to be a blast.
How I Learned to Program
When I was a kid, I copied computer-program games out of books. This was a long time ago, so I bought books with nothing but programs, and typed them into computers.
When I first started doing it, I had no idea what I was doing. Eventually, I started to recognize certain things that were done over and over, and I almost understood them.
I started to change thingslittle things at firstto see what happened. Then I started making bigger changes. Eventually I got pretty good at it. And after a long time, I could write my own programs.I hope that this book will let you do the same, but with one important difference: Ill explain whats going on so you wont have to guess quite as much.
What You Need for This Book
Not all web browsers can generate the cool 3D-gaming objects that well build in this book. To get the most out of the book, you should install the Google Chrome ( https://www.google.com/chrome/ ) web browser on your computer. Other web browsers will work, but some of the exercises in this book rely on features available only in Google Chrome. One browser that will definitely not work with the exercises is Microsoft Internet Explorer.
For most of the exercises in the book, any computer with Google Chrome installed will be sufficient. Later exercises that make use of interesting lighting, shadows, and 3D materials will require a computer that supports WebGL. You can test your computers capabilities by visiting the Get WebGL site ( http://get.webgl.org/ ). Dont worry much about WebGL; youll be able to do a ton of programming even if your computer cant handle the advanced 3D graphics.
What Is JavaScript?
There are many, many programming languages. Some programmers enjoy arguing over which is the best , but the truth is that all languages offer unique and worthwhile things.