- ホーム
- > 洋書
- > 英文書
- > Computer / General
Full Description
Game programming offers a wealth of creative and business opportunities, and it's never been more accessible. In Core HTML5 2D Game Programming, best-selling author David Geary shows you how to use freely available browser tools and open source resources to create video games that run in desktop browsers and on mobile devices.Geary walks you step by step through every aspect of implementing a sophisticated arcade-style game entirely from scratch, without using proprietary game frameworks. Packed with code, this full-color tutorial gives you the in-depth understanding you need to design and build any kind of HTML5 2D game on your own, whether you use a framework or not.A clearly written, accessible, and exhaustive guide to implementing games, this book leaves no stone unturned, showing you how toCreate smooth, flicker-free animations Implement motion that's unaffected by your game's underlying animation frame rate Animate sprites (graphical objects) to make them sparkle, explode, etc. Layer multi-channel sound effects on top of a soundtrack Warp time to create nonlinear effects, such as jumping or bouncing Control the flow of time through your game with a time system Implement particle systems that simulate natural phenomena Efficiently detect collisions between sprites Create a developer backdoor containing special features Use Node.js and socket.io to transfer real-time metrics to a server Employ a heads-up display to show high scores stored on a server Understand the nuances of implementing HTML5 games for mobile devicesThrough expertly written code that's easy to understand, and prose that cuts to the chase, Geary illuminates every corner of game development. Everyone from novice game programmers to professional game developers will find this book invaluable as both a tutorial and a reference. All of the book's source code, including chapter-specific versions of the game discussed in the book, are available at corehtml5games.com.
Contents
Preface xvAcknowledgments xxiAbout the Author xxiiiChapter 1: Introduction 11.1 Snail Bait 31.2 HTML5 Game Development Best Practices 101.3 Special Features 161.4 Snail Bait's HTML and CSS 181.5 Snail Bait's Humble Beginning 251.6 The Use of JavaScript in This Book 281.7 Conclusion 311.8 Exercises 31Chapter 2: Raw Materials and Development Environment 332.1 Use Developer Tools 352.2 Obtain Assets 502.3 Use CSS Backgrounds 542.4 Generate Favicons 562.5 Shorten the Coding Cycle 582.6 Conclusion 592.7 Exercises 60Chapter 3: Graphics and Animation 613.1 Draw Graphics and Images with the HTML5 canvas Element 643.2 Implement Smooth HTML5 Animations 703.3 Implement a Game Loop 753.4 Calculate Frame Rates 773.5 Scroll the Background 783.6 Create Time-Based Motion 853.7 Reverse Scroll Direction 863.8 Draw Animation Frames 863.9 Use Parallax to Create the Illusion of Depth 873.10 Conclusion 903.11 Exercises 90Chapter 4: Infrastructure 934.1 Encapsulate Game Functions in a JavaScript Object 954.2 Understand JavaScript's Persnickety this Reference 1004.3 Handle Keyboard Input 1034.4 Pause or Resume the Game When the Player Presses the p Key 1054.5 Freeze the Game to Ensure It Resumes Exactly Where It Left Off 1074.6 Pause the Game When the Window Loses Focus 1084.7 Resume a Paused Game with an Animated Countdown 1104.8 Conclusion 1154.9 Exercises 116Chapter 5: Loading Screens 1175.1 Define Snail Bait's Chrome 1205.2 Fade Elements In and Out with CSS Transitions 1235.3 Fade Any Element In or Out That Has a CSS Transition Associated with Its Opacity 1325.4 Implement the Loading Screen 1355.5 Reveal the Game 1405.6 Conclusion 1445.7 Exercises 144Chapter 6: Sprites 1476.1 Sprite Objects 1496.2 Incorporate Sprites into a Game Loop 1566.3 Implement Sprite Artists 1606.4 Create and Initialize a Game's Sprites 1676.5 Define Sprites with Metadata 1716.6 Scroll Sprites 1746.7 Conclusion 1766.8 Exercises 177Chapter 7: Sprite Behaviors 1797.1 Behavior Fundamentals 1827.2 Runner Behaviors 1847.3 The Runner's Run Behavior 1877.4 Flyweight Behaviors 1907.5 Game-Independent Behaviors 1937.6 Combine Behaviors 1997.7 Conclusion 2057.8 Exercises 206Chapter 8: Time, Part I: Finite Behaviors and Linear Motion 2078.1 Implement an Initial Jump Algorithm 2098.2 Shift Responsibility for Jumping to the Runner 2108.3 Implement the Jump Behavior 2138.4 Time Animations with Stopwatches 2148.5 Refine the Jump Behavior 2178.6 Implement Linear Motion 2208.7 Pause Behaviors 2258.8 Conclusion 2278.9 Exercises 227Chapter 9: Time, Part II: Nonlinear Motion 2299.1 Understand Time and Its Derivatives 2309.2 Use Animation Timers and Easing Functions to Implement Nonlinear Jumping 2319.3 Implement Animation Timers 2339.4 Implement Easing Functions 2359.5 Fine-tune Easing Functions 2399.6 Implement a Realistic Bounce Behavior 2419.7 Randomize Behaviors 2459.8 Implement Nonlinear Color Changes with Animation Timers and Easing Functions 2479.9 Conclusion 2519.10 Exercises 251Chapter 10: Time, Part III: Time Systems 25310.1 Snail Bait's Time System 25510.2 Create and Start the Time System 25710.3 Incorporate the Time System into Snail Bait 25810.4 Redefine the Current Time for Stopwatches and Animation Timers 26410.5 Implement the Time System 26810.6 Conclusion 27010.7 Exercises 270Chapter 11: Collision Detection 27311.1 The Collision Detection Process 27511.2 Collision Detection Techniques 27511.3 Snail Bait's Collision Detection 27711.4 Select Candidates for Collision Detection 28111.5 Detect Collisions Between the Runner and Another Sprite 28211.6 Process Collisions 28411.7 Optimize Collision Detection 28611.8 Monitor Collision Detection Performance 28911.9 Implement Collision Detection Edge Cases 29111.10 Conclusion 29511.11 Exercises 296Chapter 12: Gravity 29712.1 Equip the Runner for Falling 29812.2 Incorporate Gravity 30012.3 Collision Detection, Redux 30812.4 Conclusion 31012.5 Exercises 311Chapter 13: Sprite Animations and Special Effects 31313.1 Implement Sprite Animations 31413.2 Create Special Effects 32013.3 Choreograph Effects 32913.4 Conclusion 33513.5 Exercises 336Chapter 14: Sound and Music 33714.1 Create Sound and Music Files 33914.2 Load Music and Sound Effects 34014.3 Specify Sound and Music Controls 34214.4 Play Music 34314.5 Play Music in a Loop 34414.6 Play Sound Effects 34714.7 Turn Sound On and Off 36114.8 Conclusion 36214.9 Exercises 362Chapter 15: Mobile Devices 36315.1 Run Snail Bait on Mobile Devices 36615.2 Detect Mobile Devices 36815.3 Scale Games to Fit Mobile Devices 36915.4 Change Instructions Underneath the Game's Canvas 38115.5 Change the Welcome Screen 38315.6 Incorporate Touch Events 39615.7 Work Around Sound Idiosyncrasies on Mobile Devices 40015.8 Add an Icon to the Home Screen and Run without Browser Chrome 40215.9 Conclusion 40315.10 Exercises 404Chapter 16: Particle Systems 40516.1 Smoking Holes 40616.2 Use Smoking Holes 41116.3 Implement Smoking Holes 41416.4 Pause Smoking Holes 43416.5 Conclusion 43516.6 Exercises 436Chapter 17: User Interface 43717.1 Keep Score 43817.2 Add a Lives Indicator 44217.3 Display Credits 44817.4 Tweet Player Scores 45517.5 Warn Players When the Game Runs Slowly 45817.6 Implement a Winning Animation 46717.7 Conclusion 47217.8 Exercises 472Chapter 18: Developer Backdoor 47518.1 Snail Bait's Developer Backdoor 47718.2 The Developer Backdoor's HTML and CSS 47918.3 Reveal and Hide the Developer Backdoor 48118.4 Update the Developer Backdoor's Elements 48318.5 Implement the Developer Backdoor's Checkboxes 48418.6 Incorporate the Developer Backdoor Sliders 49218.7 Implement the Backdoor's Ruler 50218.8 Conclusion 51318.9 Exercises 513Chapter 19: On the Server: In-game Metrics, High Scores, and Deployment 51519.1 Node.js and socket.io 51719.2 Include socket.io JavaScript in Snail Bait 51819.3 Create a Simple Server 52019.4 Create a Socket on the Server 52019.5 Start the Server 52119.6 Create a Socket on the Client and Connect to the Server 52219.7 Record In-game Metrics 52319.8 Manage High Scores 52619.9 Deploy Snail Bait 54019.10 Upload Files to a Server 54219.11 Conclusion 54319.12 Exercises 544Chapter 20: Epilogue: Bodega's Revenge 54520.1 Design the User Interface 54720.2 Create the Sprite Sheet 55120.3 Instantiate the Game 55220.4 Implement Sprites 55320.5 Implement Sprite Behaviors 56320.6 Draw the Bullet Canvas 58020.7 Implement Touch-Based Controls for Mobile Devices 58220.8 Conclusion 58520.9 Exercises 585Glossary 587Index 595