Annotation Learning the fundamentals of 2D game programming is the key to quickly building your game-development expertise. Understanding the elements of the 2D environment will provide a solid foundation in game creation, whether you stick with 2D or move on. FUNDAMENTAL 2D GAME PROGRAMMING WITH JAVA teaches you the basics using Java, including application programming, full-screen games, input handling, matrix transformations, basic physics, intersection testing, collision detection, and much more. The book's three parts cover: The Foundations (building a simple prototype game), the Polish (fine-tuning to create a satisfying gaming experience), and The Complete Game (creating an entire game from start to finish). Author and game developer Timothy Wright shares his toolkit of code and expertise to help you speed up the process of game programming in Java. Sharpen your Java skills and have a great time creating games with FUNDAMENTAL 2D GAME PROGRAMMING WITH JAVA Cover 1 Contents 7 Introduction 13 PART I: THE FOUNDATIONS 18 Chapter 1 Hello World 20 Using the FrameRate Class 20 Creating the Hello World Application 21 Using Active Rendering 24 Creating a Custom Rendering Thread 27 Creating an Active Rendered Window 29 Changing the Display Mode 32 Active Rendering in Full-Screen Display Mode 37 Resources and Further Reading 40 Chapter 2 Input 42 Handling Keyboard Input 43 Keyboard Improvements 47 Handling Mouse Input 50 Relative Mouse Movement 58 Resources and Further Reading 68 Chapter 3 Transformations 70 Using the Vector2f Class 71 Using Polar Coordinates 80 Understanding Points and Vectors 87 Using Matrix Transformations 89 Row-Major vs Column-Major Matrices 90 Understanding the Matrix3x3f Class 92 Affine Transformation 105 Resources and Further Reading 107 Chapter 4 Time and Space 108 Calculating Time Delta 108 Screen Mapping 115 Adjusting the Viewport Ratio 124 Cannon Physics 131 Resources and Further Reading 139 Chapter 5 Simple Game Framework 140 Screen-to-World Conversion 140 Understanding the Simple Framework 142 Using the Simple Framework Template 149 Resources and Further Reading 151 Chapter 6 Vector2f Updates 152 inv( ) 152 add( ) 153 sub( ) 153 mul( ) 154 div( ) 154 len( ) and lenSqr( ) 154 norm( ) 155 perp( ) 156 dot( ) 156 angle( ) 158 polar( ) 158 toString( ) 159 Resources and Further Reading 161 Chapter 7 Intersection Testing 162 Point in Polygon Testing 162 Using an Axis Aligned Bounding Box (AABB) for Intersection Testing 172 Using Circles for Intersections 173 Using the Separating Axis Method 183 Using the Line-Line Overlap Method 186 Using the Rectangle-Rectangle Overlap Method 190 Optimizing Your Tests 195 Resources and Further Reading 196 Chapter 8 Game Prototype 198 Creating a Polygon Wrapper Class 198 Making a Prototype Asteroid 208 Creating a Prototype Editor 213 Making Rocks with a Prototype Asteroid Factory 218 Prototype Bullet Class 224 Prototype Ship Class 226 Coding the Prototype Game 232 Resources and Further Reading 240 PART II: THE POLISH 242 Chapter 9 Files and Resources 244 Understanding How Java Handles Files and Directories 244 Understanding Input/Output Streams 248 Creating the Resourcesjar File for Testing 253 Putting Resources on the Classpath 254 Making a Resource Loader Utility 258 Exploring Java Properties 261 An Overview of XML Files 266 Resources and Further Reading 275 Chapter 10 Images 276 Learning About Colors in Java 276 Exploring Different Image Types 277 Performing Color Interpolation 284 Using Volatile Images for Speed 290 Creating Transparent Images 295 Using the Alpha Composite Rules 298 Drawing Sprites 306 Exploring Different Scaling Algorithms 316 Resources and Further Reading 334 Chapter 11 Text 336 Understanding Java Fonts 336 Making a Draw String Utility 342 Using Text Metrics for Layout 346 Enabling Thread-Safe Keyboard Input 358 Resources and Further Reading 365 Chapter 12 Threads 366 Using the Callable Task with Threads 367 Using Threads to Load Files 369 Using the FakeHardware Class for Testing 373 Using the Wait/Notify Methods 377 Using Threads in the Game Loop 379 Using a State Machine 388 The OneShotEvent Class 389 The LoopEvent Class 392 The RestartEvent Class 395 The Multi-Thread Event Example 398 Resources and Further Reading 400 Chapter 13 Sound 402 Working with Sound Files 405 Problems with the Sound Library 406 Developing Blocking Audio Classes 411 Using the Blocking Clip Class 413 Using the AudioDataLine Class 417 Creating the BlockingDataLine Class 424 Creating a SoundEvent Class 427 Using the OneShotEvent Class 428 Using the LoopEvent Class 430 Using the RestartEvent Class 431 Adding Sound Controls 437 Resources and Further Reading 447 Chapter 14 Deployment with ANT 448 Installing the ANT Software 448 Understanding the Format of a Build Script 449 Learning Common ANT Tasks 452 Building an Extendable Build Script 454 Resources and Further Reading 461 Chapter 15 Collision Detection 462 Bouncing Balls with Collision Detection 462 Using the Parametric Line Equation 468 Finding a Line-Rectangle Intersection 470 Finding a Circle-Line Intersection 480 Finding a Line-Line Intersection 487 Calculating a Reflection Vector 495 Bouncing a Point Inside a Polygon 500 Resources and Further Reading 510 PART III: THE COMPLETE GAME 512 Chapter 16 Tools 514 Creating a Game Framework 514 Updating the Polygon Editor 527 Drawing a Sprite 543 Creating a Simple Particle Engine 547 Resources and Further Reading 553 Chapter 17 Space Rocks 554 The Bullet Class 555 The PolygonWrapper Class 556 The Particle Class 560 The Asteroid Class 561 The AsteroidFactory Class 565 The AsteroidExplosion Class 568 The Ship Class 569 The ShipFactory Class 575 The ShipExplosion Class 577 Adding Game Constants 579 The Acme Class 579 The GameState Class 580 The Score Class 581 The QuickLooper Class 582 The QuickRestart Class 584 The HighScoreMgr Class 585 Managing the State 589 The StateController Class 590 The CompleteGame Class 592 The GameLoading State 595 The AttractState Class 601 The PressSpaceToPlay Mode 604 The HighScore State 605 The GameInformationState Class 606 The LevelStarting State 608 The LevelPlaying State 610 The GameOver State 617 The EnterHighScoreName State 618 Creating a Build Script 624 Resources and Further Reading 625 Chapter 18 Conclusion 626 Chapter 1—“Hello World” 627 Chapter 2—“Input” 627 Chapter 3—“Transformations” 627 Chapter 4—“Time and Space” 628 Chapter 5—“Simple Game Framework” 628 Chapter 6—“Vector2f Updates” 628 Chapter 7—“Intersection Testing” 629 Chapter 8—“Game Prototype” 629 Chapter 9—“Files and Resources” 629 Chapter 10—“Images” 630 Chapter 11—“Text” 630 Chapter 12—“Threads” 631 Chapter 13—“Sound” 631 Chapter 14—“Deployment with ANT” 632 Chapter 15—“Collision Detection” 632 Chapter 16—“Tools” 632 Chapter 17—“Space Rocks” 633 Resources and Further Reading 634 Index 636 A 636 B 636 C 637 D 640 E 640 F 641 G 641 H 642 I 642 J 643 K 643 L 643 M 644 N 647 O 648 P 648 Q–R 649 S 650 T 652 U 653 V 653 W–Z 654 Learning the fundamentals of 2D game programming is the key to quickly building game-development expertise. Understanding the elements of the 2D environment will provide a solid foundation in game creation, whether you stick with 2D or move on. This book teaches you the basics using Java, including application programming, full-screen games, input handling, matrix transformations, basic physics, intersection testing, collision detection, and much more. The book's three parts cover: The Foundations (building a simple prototype game), the Polish (fine-tuning to create a satisfying gaming experience), and The Complete Game (creating an entire game from start to finish). Author and game developer Timothy Wright shares his toolkit of code and expertise to help you speed up the process of game programming in Java. -- Edited summary from book