IntroductionIntroduction
So I'm sitting in the dentist's chair waiting for the Novocain to set in and allow me to numbly enjoy my root canal when it occurs to me that I could be spending my time so much better than this. Although the confines of a dentist's chair and the goofy drool bib certainly limit my activities to some degree, they don't stop me from playing a wireless, online, multiplayer adventure game with a few hundred of my closest friends and enemies. Quickly I slip my Java-powered mobile phone out of my pocket and fire up a quick game so that I can momentarily divert my uneasy mind from the inevitable onslaught of medieval dental tools. And this, my friends, is what mobile gaming is all about!
I know, you've been hearing talk about the "wireless revolution" for several years now, and you've chalked it up to techno hype. I don't blame you. Up until recently I was skeptical myself of what could realistically be done on a device that I frequently pick up off the ground and pray that it still works. Let's face it: Mobile phones are not what most of us think of when we contemplate the future of digital interactive entertainment. But we can't afford to maintain this attitude much longer. The reality is that mobile phones have arrived as game machines, and if you're reading this book you are obviously interested in "getting in the game."
Although it's perfectly legitimate to group together mobile phones with other kinds of handheld entertainment devices such as Palm Pilots, Pocket PCs, and Game Boys (to name a few) this book takes a narrower look at mobile game programming by focusing solely on games as they apply to mobile phones. It's not that I'm against any of the other devices, but none of those devices have anywhere near the same reach as mobile phones in terms of users. Think of five of the least technical people you know, and count how many own a mobile phone. If the answer is less than four or five, just give them a couple of years. Whether or not my informal poll convinces you, mobile phones represent the broadest installation of computers the world has ever seen, and it's growing at a staggering rate.
So you have all these people toting personal communicators (mobile phones), and primarily using them to talk to each other. And then technologies arrive that make it possible to extend those communicators beyond simple voice communications. Technologies such as Java empower mobile phones with roughly the same capabilities as desktop computers. Couple this with the wireless networking support common to all mobile phones and you have quite a unique device on your hands: rugged, compact, portable, networked, programmable...a game programmer's dream.
I'd be lying if I said that mobile game programming wasn't still in its infancy. The technologies are new and the phones that support them are even newer. But as you may know about technology, the only way to keep up with it is to stay as far ahead of the curve as possible. By learning how to design and build mobile games as the industry unfolds, you'll be better prepared to take advantage of opportunities as they arise. Whether it's a mobile game just to share with family and friends, or a full-blown commercial endeavor to fund your early retirement and cement your place in the mobile game hall of fame, this book will provide you with everything you need to get started with game programming for mobile phones. Check out Figure 1 for an example of one of the games you design and build in this book.
Figure 1
The Henway game is somewhat of a take-off on the classic Frogger arcade game.
The Henway game shown in Figure 1 is loosely based on the classic Frogger arcade game. If getting a chicken across the road isn't to your liking, then maybe the High Seas game in Figure 2 will get your attention.
Figure 2
The High Seas game takes advantage of a scrolling background and "intelligent" computer enemies.
The High Seas game is a pirate game where you cruise around a nautical map rescuing lost pirates while avoiding roaming squids, floating mines, and a large enemy pirate ship. These are just two of the five complete mobile games you build throughout the book. I'll let the others remain a surprise!
Java is the programming language of choice used throughout this book to develop mobile games, and there is a good reason for it. I go into more details on this choice in Chapter 1, "Games on the Go," but the quick reason is simply that Java is the dominant game development technology for mobile phones now and into the foreseeable future. A bonus Java tutorial, "Java Programming Primer," is included on the CD-ROM, just in case you aren't a Java whiz. Regardless of your views on Java as you go into this book, I think you'll agree by the end that Java is an ideal technology for mobile game development.
People often ask me what kind of phone I use to tinker with mobile game programming, and I always tell them the huge one sitting on my desk. I'm talking about my desktop PC, which I use the vast majority of the time during mobile game development as a mobile phone emulator. There are so many phones on the market and new models are released so frequently, it would be impossible for me to endorse a particular phone without outdating this book instantly. So I recommend using the Java emulator built into the J2ME Wireless Toolkit, which is included on the accompanying CD-ROM. Of course, you'll certainly want to test your games on a real phone throughout the development process, but you'd be surprised how handy an emulator can be.
Like game programming for desktop computers and console systems, mobile game programming isn't easy. You'll be called upon to master and combine a wide range of software development skills, not to mention a good dose of creative and artistic sensibilities. This unique blend of art and technical skill is likely what makes game programming so alluring. Add the sizzle of doing all of this on a tiny device with a wireless network connection, and you have the recipe for some serious techie fun.
How This Book Is Structured
This book is organized into five parts, each of which tackles a different facet of game programming:
Part I, "Getting Started with Mobile Game Programming"In this part, you learn the basics of mobile game development and what goes into creating a mobile game with Java and the J2ME Wireless Toolkit. You construct a mobile game skeleton that serves as a template for future games throughout the book, and test the game with a Java mobile phone emulator.
Part II, "Mobile Game Programming Essentials"In this part, you learn how to draw graphics for mobile games, including images. You also learn the ropes of sprite animation, which is the cornerstone of two-dimensional game programming. You also develop a couple of complete games, including Henway and Cat Catcher. There's admittedly a bit of an animal theme going on here, but don't worry; you get into pirates and aliens later in the book.
Part III, "Virtual Worlds and Mobile Game Intelligence"In this part, you learn about game layers and how they are used to construct games as overlapping visual pieces. You also explore the fundamentals of artificial intelligence (AI), and why it is important to games. AI can be a daunting topic, so I focus on some basic AI techniques that are easy to understand and apply in your own games. This part of the book also includes the development of another complete game, High Seas, which is a pirate game where you sail around a large sea map battling other pirates and sea monsters.
Part IV, "Taking Advantage of the Wireless Network"In this part, you find out how to make the most of the killer feature of mobile phones: the wireless network. After learning the basics of network programming for mobile games, you develop a game called NetConnect4, which is a mobile networked version of the classic Connect4 game. You then design and build a n...