Beginning Java SE 6 Game Programming 3rd Edition Jonathan S. Harbour instant download
Beginning Java SE 6 Game Programming 3rd Edition Jonathan S. Harbour instant download
https://ebookfinal.com/download/beginning-java-se-6-game-
programming-3rd-edition-jonathan-s-harbour/
https://ebookfinal.com/download/beginning-game-programming-1st-
edition-jonathan-s-harbour/
https://ebookfinal.com/download/microsoft-visual-basic-game-
programming-for-teens-2nd-edition-jonathan-s-jonathan-s-harbour-
harbour/
https://ebookfinal.com/download/more-python-programming-for-the-
absolute-beginner-1st-edition-jonathan-s-harbour/
https://ebookfinal.com/download/microsoft-visual-basic-net-
programming-for-the-absolute-beginner-1st-edition-jonathan-s-harbour/
Beginning EJB 3 Java EE 7 edition Jonathan Wetherbee
https://ebookfinal.com/download/beginning-ejb-3-java-ee-7-edition-
jonathan-wetherbee/
https://ebookfinal.com/download/beginning-opengl-game-programming-1st-
edition-dave-astle/
https://ebookfinal.com/download/beginning-opengl-game-programming-1st-
edition-dave-astle-2/
https://ebookfinal.com/download/beginning-directx-11-game-
programming-1st-edition-allen-sherrod/
https://ebookfinal.com/download/beginning-c-through-game-
programming-4th-edition-michael-dawson/
Beginning Java SE 6 Game Programming 3rd Edition
Jonathan S. Harbour Digital Instant Download
Author(s): Jonathan S. Harbour
ISBN(s): 9781435458086, 1435458087
Edition: 3
File Details: PDF, 4.12 MB
Year: 2011
Language: english
R
Beginning Java
SE 6 Game
Programming,
Third Edition
Jonathan S. Harbour
Australia . Brazil . Japan . Korea . Mexico . Singapore . Spain . United Kingdom . United States
Beginning Java SE 6 © 2012 Course Technology, a part of Cengage Learning.
R
Game Programming, Third Edition ALL RIGHTS RESERVED. No part of this work covered by the copyright
Jonathan S. Harbour herein may be reproduced, transmitted, stored, or used in any form or
Publisher and General Manager, by any means graphic, electronic, or mechanical, including but not
Course Technology PTR: Stacy L. Hiquet limited to photocopying, recording, scanning, digitizing, taping, Web
distribution, information networks, or information storage and retrieval
Associate Director of Marketing:
systems, except as permitted under Section 107 or 108 of the 1976
Sarah Panella
United States Copyright Act, without the prior written permission of the
Manager of Editorial Services: publisher.
Heather Talbot
Marketing Manager: Jordan Castellani
For product information and technology assistance, contact us at
Senior Acquisitions Editor: Emi Smith Cengage Learning Customer & Sales Support, 1-800-354-9706
Project Editor: Jenny Davidson
For permission to use material from this text or product,
Technical Reviewer: Dustin Clingman submit all requests online at www.cengage.com/permissions
Interior Layout Tech: MPS Limited, a Macmillan Further permissions questions can be emailed to
Company permissionrequest@cengage.com
Cover Designer: Mike Tanamachi
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Indexer: Larry Sweazy
All other trademarks are the property of their respective owners.
Proofreader: Michael Beady
All images © Cengage Learning unless otherwise noted.
ISBN-13: 978-1-4354-5808-6
ISBN-10: 1-4354-5808-7
eISBN-10: 1-4354-5809-5
Jonathan S. Harbour has been programming video games since the 1980s. His
first video game system was an Atari 2600 that he disassembled on the floor of his
room at age 9. He has written on languages and subjects that include Cþþ, C#,
Basic, Java, DirectX, Allegro, Lua, DarkBasic, XNA Game Studio, Pocket PC,
Nintendo GBA, and game console hacking. He is the author of Visual Basic Game
Programming for Teens, Third Edition; Visual C# Game Programming for Teens;
Beginning Game Programming, Third Edition; Multi-Threaded Game Engine
Design; and XNA Game Studio 4.0 for Xbox 360 Developers. Visit his blog and
forum at www.jharbour.com.
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
vi
Contents vii
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Introduction
This book will teach you how to create games with the awesome Java language.
Previous editions emphasized the casual game market with chapter projects
designed to run in AppletViewer or in a web browser. While still relevant, the
code in this new edition is a bit simpler, using a JFrame more often instead of an
applet, so that examples can be run as a Java application. Some chapters still
feature applet projects, while many others are now JFrame-based applications.
The final Galactic War project in Part III is still an applet, since a focus of the book
is an emphasis on the casual game market. Game programming is a challenging
subject, and it can be difficult to figure out how to get started. This book takes
away some of the mystery of game programming by explaining how to create a
game in Java. I assume that you have a little Java programming experience, but if
you have never used Java before you should be able to keep up. Chapter 2 provides
a quick summary of the language.
This book takes the approach that we can have fun while learning how to program
games. Typing in long source code listings out of a book is not fun, so I don’t ask
you to do that very much. Instead, you will learn to write short programs that
demonstrate the major topics, and over time you will get the hang of it. There is
no memorization required here, as I’m a firm believer that repetition and practice
is the best way to learn, not theory and memorization.
xiii
xiv Introduction
Definition
Java is a programming language, invented by Sun Microsystems, now owned by Oracle, and
largely maintained as a loosely constrained community project. The primary design goal of Java
was to build runtime binary files that will run on any computer system in the world without being
recompiled. This “compile one, run many” philosophy works! The Java compiler creates a
bytecode binary file containing virtual machine instructions that the JRE (Java Runtime Envir-
onment) can execute on any computer system on which it is installed.
You will learn how to write a simple Java program in the first chapter. From there,
you will learn the details of how to write games that will run in a web browser or as
an application. We cover source code at a pace that will not leave you behind. By
the end of this book, you will have learned to create a complete game called
Galactic War, and will be able to deploy it to your website in a Java Archive (JAR)
file. I’m not talking about some half-baked simulation posing as a game. I’m
talking about a high-quality game, suitable for publishing in the casual game
market. There are thousands of casual gamers who are paying to download games
of this type from the many casual game sites on the web today—such as Real
Arcade (now www.GameHouse.com). By learning how to create a casual game,
you may even be preparing for a career in the game industry, developing games
for Microsoft Xbox Live Arcade and other commercial endeavors.
Definition
Web-based games are video games that are installed on a website and run in a web browser, so
that the end-users do not need to install the game. Some games are able to store high-score lists
and player data on the web server. The most popular type of web game is a “Casual Game” such
as Farmville on Facebook.
While we’re on the subject of casual games, you can even program your own Xbox
360 games, distributed on Xbox Live Arcade, using Microsoft’s free XNA Game
Studio Express software. Although this subject is beyond the scope of this book, I
bring it up because Microsoft’s C# language is unabashedly similar to Java. I have
another book on this subject titled XNA Game Studio 4.0 for Xbox 360 Developers
that you might want to check out.
It all begins here! Are you serious about this subject and willing to learn? As a
course developer and instructor of game development, I am scrutinized daily by
students who eat, drink, and breathe video games. I cannot create something that
stinks or I’ll never hear the end of it! So I am as motivated to teach you cutting-
edge game development techniques here as I am in a real classroom setting, by
Introduction xv
students who are paying a lot more than the retail cost of this book to learn these
concepts. I have used this book in several Java courses already, so you are guar-
anteed high-quality material in these pages that will not be a waste of your time. In
other words, this book has already been through the flames of scrutiny twice
before, so you are guaranteed a solid read and good, working code.
Figure 1
You will learn how to create this game from scratch!
xvi Introduction
You will then learn new techniques in each chapter, such as how to load a bitmap
file and render it on the 2D applet window using Java 2D classes like Graphics2D.
You will eventually put the handful of game-related classes together in an event-
driven game engine. As you can see from this screenshot, the final game uses some
attractive artwork and is chock full of small details! You will learn about simple
bitmaps and then sprites before getting into animation. Along the way, you will
learn how to use Java’s advanced 2D library to rotate and scale sprites, and I’ll
show you some interesting code that moves bullets, power-ups, asteroids, and
other game objects on the screen smoothly and realistically. The end result is a
professional sprite-based game engine that packs a serious punch! By learning
how to create this retail-quality casual game, you will have learned enough to
create your own games, suitable for sale in the casual game market (where games
are played over the web).
Definition
An applet is a limited type of Java program designed to run in a web browser. Due to security
restrictions, an applet is not able to access the file system on a user’s PC like a Java application,
which is installed like any other application software.
Since this book is dedicated to teaching the basics of game programming, it will
cover a lot of subjects very quickly, so you’ll need to read the chapters of this book
sequentially for best results. I use a casual writing style to make the subjects easy to
understand and use repetition rather than memorization to nail the points home.
You will learn by practice and will not need to struggle with any one subject,
because you will use them several times throughout the book. Each chapter builds
on the one before. The Galactic War game developed in Part III refers back to
previous chapters, so I recommend reading one chapter at a time, in order, to fully
understand everything that is going on. I tend to just use code after explaining
how it works the first time, and often do not explain something over and over
again because the book moves along at a brisk pace. We have a lot to cover in a
limited amount of space, so I recommend reading the book from start to finish.
starters, you can pick up Java Programming for the Absolute Beginner, by Joseph
P. Russell (Cengage Learning). We do not utilize any advanced features of Java SE 6,
even though this is the latest version of Java, so if you are new to the language you
should be able to make the best of it by following along.
While covering some of the basics over the first three chapters, you’ll have created
a complete casual game in Java that runs in a web browser, which will be a
milestone as well as a measure of your own skill level at that point. As I men-
tioned, this book is not a primer on the Java language, but rather, makes use of this
very capable, high-level language to create games. You will find the code in this
book much easier to understand if you have at least read a primer on the subject.
We discuss game programming, not basic Java programming.
All of the projects in this book will compile with the Java SE 6 development kit.
While later versions (such as Java SE 7) will compile the code, older versions of
Java may complain about classes or methods that are not recognized.
Definition
Cross-platform development is the ability to compile and run the same code on many different
computer systems. Java code and executable files are supported on many platforms. You do not
need to recompile your Java code for every system, as the same .class file will run on all of them!
Tip
You will be using Java SE 6 (i.e. “Java Standard Edition 6”), which is the lightweight version of
Java best suited for creating standalone and web-based games. Our text editor of choice is
TextPad 5.0, which can compile your Java source code files with a macro key.
TextPad is a small, easy-to-use source code editor that recognizes the Java
Development Kit and is able to compile your Java code with a simple macro
(Ctrlþ1). By using TextPad as our “IDE”, you’ll be working directly with the file
system on your hard drive rather than a virtual project manager (such as the one
in NetBeans). In TextPad, you’ll see the actual files on your drive, and there is no
concept of “adding” files to a “project” because you are working with your source
Introduction xix
Note
This is what a note looks like. Notes are additional information related to the text.
Tip
This is what a tip looks like. Tips give you pointers in the current tutorial being covered.
Caution
This is what a caution looks like. Cautions provide you with guidance and what to do or not do in
a given situation.
Definition
This is what a definition looks like. Definitions will explain the meaning behind a technical concept
or word.
L’ANALYSE CHIMIQUE
DU DERNIER SOUPIR
«Utile dulci.»
Flaccus.
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.
ebookfinal.com