Games programming is what got me into computers some 15 years ago. If you're at all like me, then the magic, brightly colored animation radiating out of computer games attracts you like a moth to light. But being fascinated by computer games (and their internals) and being able to program them are two different things altogether. I had to learn the trade the hard way -- by staring at games for hours until you could see how they worked. These days you can cheat and take a short-cut: Pick up a book and just "mind meld" with the experienced programmer who disgorges all his experience, tips, and tricks.
Bearing in mind that some Java books (see the Laura Lemay book listed below in the Resources section) these days want to lead you up different paths altogether, you could do worse things than trust an ex-(commercial)games programmer to review the currently available Java game programming books.
Four titles landed on my doorstep for this review:
Black Art of Java Game Programming, by Joel Fan, Eric Ries, and Calin Tenitchi (Waite Group Press)
Cutting-Edge Java Game Programming, by Neil Bartlett, Steve Simkin, and Chris Stranc (Coriolis Group Books)
Developing Java Entertainment Applets, by John Withers (Wiley)
- Teach Yourself Internet Game Programming with Java, by Michael Morrison (Sams.net)
Before I review the books in detail, let's start with a table that gives you a bird's-eye view of their main characteristics:
Table 1: Java Game Programming Books Overview.
|Title (Publisher)||Price(US$)||Pages||Chapters (Appendices)||CD- ROM?||Authors||Object- Orientation||Networked Multi-User Focus||Game Framework Focus|
|Black Art of Java Game Programming (Waite)||49.99||933||20 (5)||Yes||3++|
|Cutting-Edge Java Game Programming (Coriolis)||39.99||523||21 (2)||Yes||3|
|Developing Java Entertainment Applets (Wiley)||29.95||392||10 (0)||No||1||Poor||Poor||Average|
|Teach Yourself Internet Game Programming with Java (Sams.net)||39.99||416||21 (3)||Yes||1||Average||Good||None|
To describe the table headings, the Object-Orientation column highlights to what extent the author(s) of the respective book used Java the way it is meant to be used: in an object-oriented way. Good Java books, whatever their focus, enforce good object-oriented practices. Inferior books use Java as if it was C or Pascal -- that is, in a procedural way. Games are very good candidate applications that benefit from being designed and implemented using object-orientation, so a good Java games book better be strong on OOA/OOD/OOP (OO Analysis, Design, Programming).
The Networked Multi-User Focus column highlights how much the book focuses on Java's strongest game programming potential: networked, multi-user games.
The Game Framework Focus column highlights to what extent the book relies on a game framework to explain and develop games programming. Game frameworks are state-of-the-art game APIs that eliminate many of the standard tasks that all games have to perform (sprite management, screen repainting, score keeping, and so on).
Now, a look at the books in detail.
Black Art of Java Game Programming
Black Art of Java Game Programming is one of those Bible-type books -- all 933 pages of it. The book is logically structured into three parts:
- "Fundamentals of Java Game Development"
- "Advanced Game and Graphics Techniques"
- "Game Gallery"
Part 1, which is written entirely by the book's main author (Joel Fan), expertly weaves the three subject threads of Java, object-orientation, and game programming fundamentals into one clear, refreshing, and coherent whole.
Part 2 focuses on networking and 3D techniques. One chapter develops a server-side high score management system while another develops an entire chat-room system. Both these systems entail client-side and server-side programs (applets and servers, in other words). The only two chapters dealing with 3D read like a book within a book: In over 110 pages Calin Tenitchi crunches through all the classic 3D basics and, in his second chapter, analyzes the use of a large but very well-designed 3D game framework called App3DCore. With the official Java 3D API on the horizon, this part of the book will soon be partially obsolete, although much of the framework deals with higher-level aspects than Java 3D so this is not a problem for the book. At any rate, having the insides of such a 3D framework explained is very enlightening.
Part 3, the Game Gallery, contains eight chapters, each of which develops an entire game. The games vary in sophistication, which gave me the impression that this part of the book was rather hastily put together. The individual design and implementation of the games is (overall) of the same high quality as the rest of the book, though. There's a vector-based Asteroids clone, Othello, a Web-based Mahjong, a horizontally-scrolling, word-shooting edutainment game, two different magic-square games, and an incarnation of the classic Worm (or Snake, if you prefer) game.
Although the book is not without its share of glitches, errors, and so on (for example, one page contains a code listing that is mangled beyond belief), I liked it a lot. The book has many strengths and few weaknesses. It is strong on good program analysis and design. (Ah! you thought you could skip those stages just because they're games? Wrong.) The book uses various types of diagrams very effectively (object diagrams, class diagrams, flowcharts, state machine diagrams, screen prototype diagrams, and so on), and most of the code listings are very readable. (This aspect, like the writing style, does fluctuate from author to author. This is the inevitable flip-side of books written by several authors.)
Cutting-Edge Java Game Programming
I'm usually very skeptical of titles starting with "Advanced," "Cutting-Edge," and the like, simply because, usually they aren't! In the case of Cutting-Edge Java Game Programming, Coriolis's marketing department didn't hype anything up: The book definitely is not for beginners or intermediate-level Java programmers. In fact, all but the first and last chapters of the book are devoted to an in-depth, no-nonsense analysis of the design and implementation of two game frameworks. The first framework caters to single-user (stand-alone) games while the second is geared toward Internet-based, multi-user games.
Chapter 2 packs the complete implementation of an entire Asteroids clone that's playable, flicker-free, and uses smooth animation and sound. And that in just 250 odd lines of code -- or just 18 book pages! This chapter, therefore, ought to convince anyone that using game frameworks, and frameworks in general, is one of the best ways to achieve high levels of programming productivity by accentuating design reuse, rather than code reuse (but in the process also reusing mountains of code).
If Chapter 2 is a clear, promising sign of the high quality of this book, then Chapter 3 reinforces that impression by introducing us to the core theme of the book: the in-depth exploration of a (very) well-designed game framework. In passing, the author explains what CRC (Class/Responsibilities/Collaborators) cards are, the essence of Booch class diagrams, and object message interaction diagrams. By the way, this is not as page filling because the rest of the book uses these powerful software engineering tools to enhance the text!
The single-user game framework, called GameWorks, is based on the tried-and-tested game programming metaphor of a stage populated by actors. Using this intuitive abstraction, you can implement any type of game -- from classic board games to fast, action-packed arcade games. I was slightly disappointed that the authors picked card games as an example game style (I prefer something that gets the adrenaline flowing), although they nevertheless manage to weave in all the standard issues and techniques, and expertly so (among others: image processing, input management, sprites, optimized screen refresh, audio, randomness, artificial intelligence).
Although the book isn't structured around parts, it should have been. There is a clear switch of focus from chapter 15 onwards. Chapter 15, "Network Game Programming," represents a definite shift to a higher gear, with a new author doing the writing. After introducing the main issues surrounding network-based games (connection topologies, latency, game state synchronization), the book develops a clone of Risk, the classic strategy board game (called Domination in the book). Domination is only an excuse to develop a new game framework addressing the generic class of network-enabled multi-user games. These last five chapters are tough going, and I strongly suspect readers without some data communication background will not feel comfortable with the more technical arguments. But there's no way you can skip these chapters: They contain a very thorough treatment of the critical issues of game state de-synchronization and latency problems, as well as a number of increasingly sophisticated solutions.
The book winds down with a chapter on code optimization and an interesting chapter on the design of FRED, a "Doom" clone written in Java! FRED uses ray casting (yes, in Java) to achieve that classic "Doom" feel, and this core technique is explained in detail.
To summarize, Cutting-Edge Java Game Programming is excellent. The writing is lucid and to-the-point. The software that the authors develop is of very high quality. The listings are clear and readable, and I don't know about you, but after reading other people's programs for 15 years, I don't regard source-code readability as a luxury).
Developing Java Entertainment Applets
Developing Java Entertainment Applets is a very disappointing book. If a publisher gave you 400 pages in which to cram everything you know about programming games in Java (okay, okay, "Java En-ter-tain-ment App-lets"), then you do not start with a chapter that reiterates, ad nauseam, the history of Java. Or continue with "Java Fundamentals" (Chapter 4), a totally superfluous rehashing of language basics (variables, Unicode, expressions, comments, control flow, objects, classes, packages -- you name it!). The author still doesn't suspect that he might be focusing on the wrong subject entirely, so in Chapter 5, "More Advanced Techniques," he drones on with arrays, vectors, strings, exceptions, multithreading, applets. Getting ever so slightly hotter is Chapter 6, "Graphics, Sound and Events." But you'll be hard-pressed to find any references to game programming here, either. Instead, precious page real estate is devoted to bringing you no less than 13 half-page screenshots of the trivial results of
drawArc() and the like!
Half-way through the book (Chapter 7, page 219) we have the first appearance of some Java game code, in this case, an attempt at the Solitaire card game (decidedly, card games must be in season). The design of the game, the implementation of the game, and the readability of the listings are all so inferior compared to the same aspects of the other books in this review that it's clear Developing Java Entertainment Applets has problems.
Some remarkable statements made by the author, and a general sloppiness or misuse of terms that have crystal-clear meaning, only helps to sink this book before it has a chance to sail. AWT's layout management mechanism is criticized as follows: "The way layout is handled is pretty botched up. Not that it doesn't make sense and isn't for a good reason, but it is still botched up." Java's networking API also is not to the author's liking: "The way that Java hooks up to other locations on the Net is broken, and while it isn't totally unusable, it sure isn't very functional in its current state." Strange, I would have sworn that others and myself manage to create pretty exciting things with that same API (Web crawler, DAMPP -- see Resources below for references to my previous JavaWorld articles on these topics). That last quote comes out of Chapter 8, "Multiplayer Gaming," where we are nevertheless shown "a stupid little example" (to quote the book) in the form of a chat application. (Other examples of language that I find hard to swallow in this book are "to cement it in your head" (p. 283), "and spitting things over a socket" (p. 284), to quote just two.)
Isn't there anything good to say about this book? Actually, there is: Chapter 2, "The Principles of Game Design," is an interesting analysis of what makes a good game good. Here the author shines by identifying several aspects that all good games have, like a well-designed game interface, veracity (level of realism), customizability, AI, and so on. The next chapter, "Game Design in Action," analyzes some real games and highlights their use of good game design elements. Then there is one large chapter (Chapter 9) devoted to a study and use of the Gamelet Toolkit (a public domain game framework, written by Mark Tacchi, that received a JavaCup International prize). These three chapters are the only parts of the book that are worth the paper they're printed on, I'm afraid.
Teach Yourself Internet Game Programming with Java
Comparative reviews are tough because rarely are two (or more) books in exactly the same category. Teach Yourself Internet Game Programming with Java, according to its back cover, addresses users in the "new" to "casual" categories. Beginners, in other words.