Addison wesley Micro Java™ Game Development

pdf
Số trang Addison wesley Micro Java™ Game Development 418 Cỡ tệp Addison wesley Micro Java™ Game Development 3 MB Lượt tải Addison wesley Micro Java™ Game Development 0 Lượt đọc Addison wesley Micro Java™ Game Development 1
Đánh giá Addison wesley Micro Java™ Game Development
4.6 ( 18 lượt)
Nhấn vào bên dưới để tải tài liệu
Đang xem trước 10 trên tổng 418 trang, để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

Micro Java™ Game Development By David Fox, Roman Verhosek Publisher : Addison Wesley Pub Date : April 18, 2002 Table of Contents ISBN : 0-672-32342-7 Pages : 576 Wireless games are always on and always with you, and can reach a more massive audience than any other gaming platform in history. No programming language is as suited for micro games as Java 2 Micro Edition (J2ME). Micro Java Game Development is your step-by-step guide to creating games for devices that support J2ME/MIDP. The material covers a full range of topics, from a tour of all available micro devices (PDAs, cell phones, and pagers) to a discussion of software standards that support J2ME (WAP, SMS, i-mode, and wireless enhancements such as Bluetooth) to an overview of J2ME extensions (Siemens Game API, NTT DoCoMo IAppli). Chapter by chapter, this book will guide you through the development of Micro Racer, a professional-level game. Brought to you by ownSky!! Table of Content Table of Content .................................................................................................................. i Copyright............................................................................................................................... i Trademarks ...................................................................................................................... i Warning and Disclaimer ................................................................................................. i Credits.............................................................................................................................. ii Dedication ...................................................................................................................... iii About the Author................................................................................................................ iii Acknowledgments ............................................................................................................. iii Chapter 1. Introduction (or Everything I Wanted to Know About Micro Java Gaming But Was Afraid to Ask)....................................................................................................... 1 A New Era of Gaming.................................................................................................... 1 This Book's Mission ....................................................................................................... 3 A Bit About Game Design............................................................................................. 6 Show Me the Money: Micro Game Business Models............................................. 16 Summary ....................................................................................................................... 18 Part I: Small Devices ................................................................................................19 Chapter 2. The Mobile World.......................................................................................... 20 A New Era of Gaming.................................................................................................. 20 High-End Java Devices: Set-Top Boxes, Phones, Consoles................................ 22 Personal Digital Assistants (PDAs) ........................................................................... 24 Mobile Phones and Pagers ........................................................................................ 31 Low-End Java Devices: Smart Cards and Embedded Chips................................ 40 Summary ....................................................................................................................... 41 Chapter 3. Big Games, Small Screens ......................................................................... 42 Your Competition ......................................................................................................... 42 WAP Games ................................................................................................................. 43 i-mode Games .............................................................................................................. 54 SMS Games.................................................................................................................. 55 J2ME MIDP Games ..................................................................................................... 57 J2ME Palm Games...................................................................................................... 65 iAppli Games................................................................................................................. 67 What Are You Waiting For?........................................................................................ 74 Part II: Before, Between, and Beyond J2ME ........................................................75 Chapter 4. Wireless Standards: How Data Goes To And Fro................................... 76 Wireless Networks ....................................................................................................... 76 The Wireless Application Protocol (WAP)................................................................ 78 Server-Side WAP ......................................................................................................... 95 Handheld Device Markup Language (HDML)........................................................ 102 WAP 2.0 and xHTML Basic ...................................................................................... 105 Summary ..................................................................................................................... 106 Chapter 5. Let's Talk: Instant Wireless Messaging ................................................... 107 Messaging And Gaming............................................................................................ 107 Short Message Service (SMS)................................................................................. 108 Actually Sending SMS Messages............................................................................ 112 SMS and J2ME........................................................................................................... 113 Multimedia Messaging Service (MMS) ................................................................... 115 Summary ..................................................................................................................... 117 Chapter 6. Wireless in Asia: i-mode and cHTML ...................................................... 118 Using i-mode............................................................................................................... 118 Compact HTML (cHTML).......................................................................................... 119 Development Tools.................................................................................................... 125 Testing and Emulators .............................................................................................. 125 ii Summary ..................................................................................................................... 128 Chapter 7. The Wireless Landscape ........................................................................... 129 Bluetooth ..................................................................................................................... 129 Mobile Positioning ...................................................................................................... 131 m-Commerce .............................................................................................................. 135 Voice and Telephony................................................................................................. 137 Unified Messaging (UM)............................................................................................ 138 Summary ..................................................................................................................... 138 Part III: The Java 2 Micro Edition..........................................................................140 Chapter 8. J2ME Overview ........................................................................................... 141 The Trinity of Java Platforms.................................................................................... 141 It's a Small World After All ........................................................................................ 142 Profiles and Configurations ...................................................................................... 143 Connected in a Limited Way: The CLDC ............................................................... 147 The Mobile Profile ...................................................................................................... 148 Summary ..................................................................................................................... 149 Chapter 9. Creating a MIDlet........................................................................................ 150 Command-Line MIDlet Development...................................................................... 150 Development Environments ..................................................................................... 152 Lifecycle of a MIDlet .................................................................................................. 156 Displaying Stuff........................................................................................................... 157 Menus and Commands ............................................................................................. 161 Creating Help and About Alert Screens.................................................................. 164 Global Properties ....................................................................................................... 168 Summary ..................................................................................................................... 169 Chapter 10. Making the Most of Limited Resources................................................. 171 The Limitations ........................................................................................................... 171 Memory Limitations.................................................................................................... 172 Displays ....................................................................................................................... 174 Breaking Through the Limitations............................................................................ 175 Summary ..................................................................................................................... 176 Chapter 11. Making the Most of It: Optimizations ..................................................... 177 A Limited World .......................................................................................................... 177 Making Code Optimal................................................................................................ 177 Code Size Reductions............................................................................................... 178 Speeding Up the Code.............................................................................................. 182 Using Less Memory ................................................................................................... 185 Power Consumption .................................................................................................. 187 Summary ..................................................................................................................... 187 Chapter 12. Multithreaded Game Programming........................................................ 188 Threads........................................................................................................................ 188 Extending the Thread Object.................................................................................. 189 Implementing the Runnable Interface................................................................... 190 Thread Priorities ......................................................................................................... 192 Thread States ............................................................................................................. 192 Synchronizations and Deadlocks ............................................................................ 192 wait() and notify()............................................................................................ 193 Timers .......................................................................................................................... 194 Making Threads Better .............................................................................................. 195 Summary ..................................................................................................................... 196 Part IV: Let the Games Begin! ..............................................................................198 Chapter 13. High-Level Graphical User Interfaces ................................................... 199 The Screen Class..................................................................................................... 199 Forms and Alerts........................................................................................................ 200 iii Lists .............................................................................................................................. 200 Text Boxes .................................................................................................................. 204 Items............................................................................................................................. 205 Tickers ......................................................................................................................... 212 Additional Libraries .................................................................................................... 212 Summary ..................................................................................................................... 213 Chapter 14. Working with Graphics: Low-Level Graphical User Interfaces .......... 214 The Canvas Class..................................................................................................... 214 Painting on the Screen.............................................................................................. 217 Drawing Images ......................................................................................................... 223 Summary ..................................................................................................................... 226 Chapter 15. Entering the Land of Sprites ................................................................... 227 Sprites.......................................................................................................................... 227 Image Files.................................................................................................................. 231 Collision Detection ..................................................................................................... 233 Creating Child Sprites ............................................................................................... 235 Image Transparency.................................................................................................. 236 Summary ..................................................................................................................... 239 Chapter 16. Managing Your Sprites ............................................................................ 240 Networked Game Components................................................................................ 240 Advanced Collision Detection .................................................................................. 242 The Sprite Manager ................................................................................................... 245 Summary ..................................................................................................................... 248 Chapter 17. Sprite Movement....................................................................................... 249 Floating-Point in J2ME .............................................................................................. 249 Game Initialization ..................................................................................................... 255 Movement.................................................................................................................... 256 Piecing It All Together ............................................................................................... 258 Summary ..................................................................................................................... 261 Chapter 18. J2ME Audio Basics .................................................................................. 262 Sounds Are (Barely) Possible! ................................................................................. 262 Summary ..................................................................................................................... 263 Chapter 19. Be Persistent: MIDP Data Storage ........................................................ 265 RecordStore Overview .......................................................................................... 265 RecordStore in Practice ........................................................................................ 266 More RecordStore Joy .......................................................................................... 273 Summary ..................................................................................................................... 278 Chapter 20. Connecting Out: Wireless Networking .................................................. 279 J2ME Networking Overview ..................................................................................... 279 MIDP Networking ....................................................................................................... 281 Setting Up Your Game Server ................................................................................. 285 Data Format ................................................................................................................ 286 Making a Multiplayer Car Racing Game................................................................. 289 Summary ..................................................................................................................... 315 Part V: J2ME Extensions .......................................................................................316 Chapter 21. PersonalJava, Connected Device Configuration, and Other Micro Java Blends .............................................................................................................................. 317 Connected Device Configuration (CDC) ................................................................ 317 PersonalJava .............................................................................................................. 318 PDA Profile.................................................................................................................. 323 Java Game Profile ..................................................................................................... 324 The J2ME Multimedia Profile ................................................................................... 324 Summary ..................................................................................................................... 325 Chapter 22. iAppli: Micro Java with a Twist................................................................ 326 iv The Architecture of It All............................................................................................ 326 iAppli: Like MIDP, But Not Quite.............................................................................. 330 Developing iApplis ..................................................................................................... 341 Summary ..................................................................................................................... 343 Chapter 23. Siemens Game API.................................................................................. 345 Getting Set Up ............................................................................................................ 345 The Game SDK Overview ........................................................................................ 348 Images and Sprites.................................................................................................... 348 Graphic Objects.......................................................................................................... 350 Sprites.......................................................................................................................... 350 TiledBackground .................................................................................................. 353 Flashing ....................................................................................................................... 356 Good Vibrations.......................................................................................................... 357 Music, Sweet Music ................................................................................................... 357 GSM Functions........................................................................................................... 360 Input Output ................................................................................................................ 361 Summary ..................................................................................................................... 362 Part VI: Micro Racer................................................................................................364 Chapter 24. Micro Racer: Putting It All Together....................................................... 365 The Bad News ............................................................................................................ 365 The Good News ......................................................................................................... 366 Putting Together the Pieces ..................................................................................... 366 One Game Running Everywhere............................................................................. 383 Summary ..................................................................................................................... 385 Part VII: Appendixes ...............................................................................................386 Appendix A. Low-Level GUI Classes .......................................................................... 387 Game Classes ............................................................................................................ 387 javax.microedition.lcdui.AlertType ..................................................... 388 javax.microedition.lcdui.Command.......................................................... 389 javax.microedition.lcdui.Display.......................................................... 389 javax.microedition.lcdui.Displayable ................................................ 389 javax.microedition.lcdui.Canvas ............................................................ 389 javax.microedition.lcdui.Screen ............................................................ 390 javax.microedition.lcdui.Alert............................................................... 390 javax.microedition.lcdui.Form................................................................. 390 javax.microedition.lcdui.List................................................................. 390 javax.microedition.lcdui.TextBox.......................................................... 391 javax.microedition.lcdui.Font................................................................. 391 javax.microedition.lcdui.Graphics ....................................................... 392 javax.microedition.lcdui.Image............................................................... 392 javax.microedition.lcdui.Item................................................................. 393 javax.microedition.lcdui.ChoiceGroup ................................................ 393 javax.microedition.lcdui.DateField ..................................................... 393 javax.microedition.lcdui.Gauge............................................................... 393 javax.microedition.lcdui.ImageItem ..................................................... 394 javax.microedition.lcdui.StringItem................................................... 394 javax.microedition.lcdui.TextField ..................................................... 394 javax.microedition.lcdui.Ticker ............................................................ 394 Appendix B. MIDP 1.1 ................................................................................................... 395 Main Packages ........................................................................................................... 395 java.io Class Hierarchy ...................................................................................... 395 java.io Interface Hierarchy ................................................................................ 396 java.lang Class Hierarchy ................................................................................. 396 v java.lang Interface Hierarchy............................................................................ 397 java.util Class Hierarchy ................................................................................. 397 java.util Interface Hierarchy............................................................................ 397 javax.microedition.io Class Hierarchy..................................................... 397 javax.microedition.io Interface Hierarchy............................................... 397 javax.microedition.lcdui Class Hierarchy.............................................. 398 javax.microedition.lcdui Interface Hierarchy........................................ 398 javax.microedition.midlet Class Hierarchy ........................................... 398 javax.microedition.rms Class Hierarchy .................................................. 398 javax.microedition.rms Interface Hierarchy ............................................ 398 Appendix C. Siemens Game API................................................................................. 400 Game Classes ............................................................................................................ 400 Siemens GSM Classes ............................................................................................. 402 Input/Output Classes ................................................................................................. 402 Appendix D. The iAppli API........................................................................................... 404 Packages..................................................................................................................... 404 com.nttdocomo.io Interfaces ............................................................................ 404 com.nttdocomo.io Interfaces ............................................................................ 404 com.nttdocomo.lang ........................................................................................... 405 com.nttdocomo.net.............................................................................................. 405 com.nttdocomo.ui ................................................................................................ 405 com.nttdocomo.ui Interfaces ............................................................................ 406 com.nttdocomo.util ........................................................................................... 407 com.nttdocomo.util Interfaces ....................................................................... 407 IApplication.......................................................................................................... 408 vi Copyright 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 Addison-Wesley was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for special sales. For more information, please contact: Pearson Education Corporate Sales Division 201 W. 103rd Street Indianapolis, IN 46290 (800) 428-5331 corpsales@pearsoned.com Visit AW on the Web: www.awl.com/cseng/ Copyright © 2002 by Pearson Education All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or other-wise, without the prior consent of the publisher. Printed in the United States of America. Published simultaneously in Canada. 05 04 03 02 4 3 2 1 First printing, April 2002 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Addison-Wesley cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. i Credits Associate Publisher Rochelle J. Kronzek Acquisitions Editor Carol Ackerman Development Editor Bryan Morgan Managing Editor Matt Purcell Project Editor George E. Nedeff Copy Editor Seth Kerney Indexers Ginny Bess Sharon Shock Proofreader Harvey Stanbrough Technical Editor Bryan Morgan Team Coordinator Denni Bannister Interior Designer Anne Jones Cover Designer Aren Howell Page Layout ii Michelle Mitchell Dedication To Charlotte, This Future is Yours —David To Lina, the princess of my heart, and Dixie, the silly cat —Roman About the Author David Fox works for Next Game, Inc., creating Web and wireless multiplayer games. Prior to that, his design and development credits include Michael Crichton's "Westworld 2000," Fox Interactive's "X-Files: Unauthorized Access," and PlayLink's real-time strategy "Citizen 01." He is the author of several best-selling books about Internet technologies, and his writing frequently appears in publications such as Salon.com, Gamasutra, and Developer.com. David has presented topics in Java gaming at Sun Microsytem's JavaOne conference for the past three years, and has been the winner of the Motorola-Nextel Developer Challenge for the past two years. Roman Verhovsek is CEO and co-founder of Cocoasoft Ltd., where he is leading a team of J2ME developers. He holds a bachelor's degree in electrical engineering from the University of Ljubljana, and is working on his master's degree of computer science. Since early 1996, he has focused primarily on Java technologies, and for last two years in particular on Java-enabled small devices. In 2001 he held a lecture on J2ME game development at the JavaOne conference. In his other life, Roman enjoys cooking, mountaineering, jogging, and traveling with his girlfriend, Lina. Acknowledgments Writing a book is like a little saga—lots of comedy, some moments of tragedy, and a veritable revolving door of plot turns. The Pearson Technology Group folks are among the most professional and resourceful I've had the privilege of working with, and ultimately responsible for this saga's success. Thanks to Shelly Kronzek for launching things off, Carol Ackerman for fearlessly navigating through muddy and rocky waters, Bryan Morgan for truly excellent advice and insight, Seth Kerney for kicking things into fighting shape, and George Nedeff for actually caring. Andy Langton, as he is wont to do, lent a surefire hand when one was desperately needed. And apologies to Louise for typing myself into oblivion all those unexpected weekends— especially the sunny ones. —David iii
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.