1. Trang chủ
  2. » Công Nghệ Thông Tin

Killer Game Programming in Java pptx

998 10,3K 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 998
Dung lượng 7,22 MB

Nội dung

www.it-ebooks.info www.it-ebooks.info Killer Game Programming in Java ™ www.it-ebooks.info Other Java ™ resources from O’Reilly Related titles Head First Java ™ Hardcore Java ™ J2ME in a Nutshell Java ™ in a Nutshell QuickTime for Java ™ : A Developer’s Notebook Physics for Game Developers Gaming Hacks AI for Game Developers Java ™ 2D Graphics Java Books Resource Center java.oreilly.com is a complete catalog of O’Reilly’s books on Java and related technologies, including sample chapters and code examples. OnJava.com is a one-stop resource for enterprise Java develop- ers, featuring news, code recipes, interviews, weblogs, and more. Conferences O’Reilly brings diverse innovators together to nurture the ideas that spark revolutionary industries. We specialize in document- ing the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches. Visit con- ferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online refer- ence library for programmers and IT professionals. Conduct searches across more than 1,000 books. Subscribers can zero in on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today with a free trial. www.it-ebooks.info Killer Game Programming in Java ™ Andrew Davison Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo www.it-ebooks.info Killer Game Programming in Java ™ by Andrew Davison Copyright © 2005 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/insti- tutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Brett McLaughlin Production Editor: Matt Hutchinson Production Services: GEX, Inc. Cover Designer: Emma Colby Interior Designer: David Futato Printing History: May 2005: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Killer Game Programming in Java, the image of a jungle cat, and related trade dress are trademarks of O’Reilly Media, Inc. Java ™ and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries. O’Reilly Media, Inc., is independent of Sun Microsystems. 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 O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-0-596-00730-0 [M] [4/09] www.it-ebooks.info v Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv 1. Why Java for Games Programming? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Java Is Too Slow for Games Programming 2 Java Has Memory Leaks 3 Java Is Too High-level 4 Java Application Installation Is a Nightmare 5 Java Isn’t Supported on Games Consoles 5 No One Uses Java to Write Real Games 7 Sun Microsystems Isn’t Interested in Supporting Java Gaming 10 2. An Animation Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Animation as a Threaded Canvas 14 Adding User Interaction 20 Converting to Active Rendering 21 FPS and Sleeping for Varying Times 22 Sleeping Better 31 FPS and UPS 34 Pausing and Resuming 37 Other Animation Approaches 39 3. Worms in Windows and Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Preliminary Considerations 47 Class Diagrams for the WormChase Application 48 The Worm-Chasing Application 48 The Game Panel 50 Storing Worm Information 59 www.it-ebooks.info vi | Table of Contents Worm Obstacles 67 Application Timing Results 68 WormChase as an Applet 70 Compilation in J2SE 5.0 73 4. Full-Screen Worms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 An Almost Full-Screen (AFS) Worm 77 An Undecorated Full-Screen (UFS) Worm 82 A Full-Screen Exclusive Mode (FSEM) Worm 89 Timings at 80 to 85 FPS 103 5. An Introduction to Java Imaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Image Formats 105 The AWT Imaging Model 106 An Overview of Java 2D 110 Buffering an Image 113 Managed Images 120 VolatileImage 121 Java 2D Speed 122 Portability and Java 2D 122 JAI 123 6. Image Loading, Visual Effects, and Animation . . . . . . . . . . . . . . . . . . . . . . . . 124 Loading Images 126 Applying Image Effects 134 Displaying Image Sequences 144 Visual Effects for ‘o’ Images 147 Packaging the Application as a JAR 175 7. Introducing Java Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Applet Playing 178 The AudioClip Class 179 The Sound Player 182 The Java Sound API 185 Sampled Audio 185 MIDI 197 Java Sound API Compared with JMF and JOAL 202 Java Sound API Resources 202 Audio Resources 204 www.it-ebooks.info Table of Contents | vii 8. Loading and Playing Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Loader Design and Implementation Issues 207 Testing the Loaders 209 The Sounds Panel 213 The Clips Loader 214 Storing Clip Information 216 The Midi Sequences Loader 219 Storing Midi Information 223 LoadersTests as a JAR File 225 9. Audio Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Audio Effects on Sampled Audio 226 Audio Effects on MIDI Sequences 236 10. Audio Synthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Sampled Audio Synthesis 249 MIDI Synthesis 255 Audio Synthesis Libraries 268 11. Sprites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 Bats, Balls, and Sprites 270 Class Diagrams for BugRunner 272 The Bug Starts Running 273 The Animation Framework 274 Defining a Sprite 279 Coding a Sprite 280 Specifying a Sprite with a Statechart 284 The Ball Sprite 287 Defining the Bat 293 12. A Side-Scroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 JumpingJack in Layers 299 Class Diagrams for JumpingJack 300 Start Jack Jumping 303 The Animation Framework 303 Managing the Ribbons 313 Wraparound Ribbons 314 Managing the Bricks 320 Storing Brick Information 333 www.it-ebooks.info viii | Table of Contents The Fireball 334 The Jumping Sprite 336 Other Side-Scroller Examples 343 Tiling Software 344 13. An Isometric Tile Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 Isometric Tiles 346 Class Diagrams for AlienTiles 350 The Animation Framework 352 Managing the World 356 Managing WorldItems 363 The Tile Occupier 366 A Sprite on a Tile 368 The Player Sprite 370 The Alien Sprite 373 The Quadrant-Based Alien Sprite 376 The A*-Based Alien Sprite 378 Storing Tile Details 383 Further Reading 384 14. Introducing Java 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 Java 3D 387 Java 3D Strengths 392 Criticisms of Java 3D for Games Programming 394 Alternatives to Java 3D 402 15. A 3D Checkerboard: Checkers3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Class Diagrams for Checkers3D 408 Integrating Java 3D and Swing 409 Scene Graph Creation 410 Floating Spheres 413 The Floor 415 Viewer Positioning 419 Viewer Movement 420 Viewing the Scene Graph 421 16. Loading and Manipulating External Models . . . . . . . . . . . . . . . . . . . . . . . . . . 424 An Overview of LoaderInfo3D 426 Loaders in Java 3D 428 www.it-ebooks.info [...]... abstraction, information hiding, and reuse That translates into building games with existing libraries/classes/tools What This Book Is About This book describes modern (i.e., fast and efficient) Java programming techniques for writing a broad range of games, including 2D arcade-style, isometric (2.5D), 3D, and network games, with a strong emphasis on 3D programming using Java 3D The 3D topics include loading... Java: • Java is too slow for games programmingJava has memory leaks • Java is too high-level • Java application installation is a nightmare • Java isn’t supported on games consoles • No one uses Java to write real games • Sun Microsystems isn’t interested in supporting Java gaming It’s worth saying that I think almost all of these objections are substantially wrong Java is roughly the same speed... slouching (Don’t you just love this assertive writing style?) You’re a programmer who wants to apply your abilities to 2D, 3D, and network games programming, for entertainment or as the first step in becoming a games programming professional You want to write a game that uses the latest Java technology, not an applet showing a penguin waving its flipper You’ve done an introductory course on Java, so... Why Java for Games Programming? This is the Title of the Book, eMatter Edition www.it-ebooks.info cards, RAM, and Internet connections—and can offer more exciting game play There are many more PC games, particularly in the area of multiplayer online games It’s estimated that 40 percent of all gamers will start playing online in 2005 Revenues may reach $1.1 billion by 2008 Another rapidly expanding... applications, such as games Statement 2 comes into play for game peripherals, e.g., joysticks and game pads; machine independence seems to suggest that nonstandard I/O devices won’t be useable Java games requiring these types of devices can utilize the Java Native Interface (JNI) to link to C or C++ and, therefore, to the hardware There’s also JInput, a new game controller API An interesting historical observation... Java for Games Programming? This is the Title of the Book, eMatter Edition www.it-ebooks.info Java Application Installation Is a Nightmare The naysayers claim that the user needs to be a Java expert to install and execute a Java application, whereas most game players want to point and click on a few dialog boxes to get a game up and running More specific comments include the following: 1 Java (specifically,... burgeoning and have produced a plethora of useful tools, online help, and code examples The games forums dedicated to Java barely existed 2 to 3 years ago Java is a great language for games programming, as I hope this book demonstrates Now, back to the criticisms Java Is Too Slow for Games Programming This is better rephrased as Java is slow compared to C and C++, the dominant languages for games programming. ”... ruthless.com (1998) mixed Java and C/C++ A good source for nontechnical lists of Java games, both commercial and freeware/shareware, can be found on the Java games pages at java. com (http://www java. com/en/games/) The pages divide games into several categories: action, adventure, strategy, puzzle, cards, sports, and so on Freeware/Shareware Games Many Java games are out on the Web, but finding a game that’s written... grouped inside dotted, rounded gray squares 2D Programming Figure P-1 shows the 2D -programming chapters Preface | This is the Title of the Book, eMatter Edition www.it-ebooks.info Copyright © 2009 O’Reilly & Associates, Inc All rights reserved xvii 1 Imaging Why Java? Sound 5 Imaging Introduction 7 Sound Introduction 10 Audio Synthesis 6 Image Loading, Effects, Animation 8 Sound Loading and Playing 9... C++), and increased programmer productivity Rather than explain each of these again, I will take a different approach and discuss Java s suitability for games programming in terms of the typical misconceptions and complaints wheeled out by people who think that games must be implemented in C, C++, assembler, or whatever (just so long as it’s not Java) Here’s the list of objections to Java: • Java is . www.it-ebooks.info www.it-ebooks.info Killer Game Programming in Java ™ www.it-ebooks.info Other Java ™ resources from O’Reilly Related titles Head First Java ™ Hardcore. trial. www.it-ebooks.info Killer Game Programming in Java ™ Andrew Davison Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo www.it-ebooks.info Killer Game

Ngày đăng: 15/03/2014, 10:20

TỪ KHÓA LIÊN QUAN