HTML5 Game Programming with enchant.js gives first-time programmers of all ages the tools to turn their video game ideas into reality. A step-by-step guide to the free, open-source HTML5 and JavaScript engine enchant.js, it is ideally suited for game fans who have always wanted to make their own game but didn’t know how. It begins with the foundations of game programming and goes on to introduce advanced topics like 3D.
We live in an age where smartphones and tablets have made games more ubiquitous than ever. Based around HTML5, enchant.js is ideally suited for aspiring game programmers who have always been intimidated by code. Games written using enchant.js take only a few hours to write, and can be played in a browser, iOS, and Android devices, removing the stress of programming to focus on the fun. Discover the joy of game development with enchant.js.
- Provides a comprehensive, easy guide to game programming through enchant.js
- Gives aspiring game developers a tool to realize their ideas
- Introduces readers to the basics of HTML5 and JavaScript programming
What you’ll learn
- Master the basics of HTML5 and JavaScript programming
- Create a game that can be played on a desktop, iOS, or Android
- Upload your game to 9leap.net, where you can share it easily
- Program your own 3D games
- Grasp the essential concepts of making a compelling and popular game
Who this book is for
HTML5 Game Programming with enchant.js is for aspiring game developers of all ages who have wanted to make their own games but didn’t know how. It’s for programmers interested in learning the potential of HTML5 through designing games.
Table of Contents
- Beginning enchant.js Development
- JavaScript Basics
- Basic Features of enchant.js
- Advanced Features of enchant.js
- Game Design
- Creating an Arcade Shooter
- Creating a Stand-Alone 3-D Game
- Class Appendix
HTML5 GameProgramming withenchant.js......Page 195
Contents at a Glance......Page 3
Contents......Page 198
About the Authors......Page 205
About the Technical Reviewer......Page 207
Acknowledgments......Page 208
Visit the enchant.js Web Sites......Page 5
enchantjs.com......Page 6
9leap.net......Page 7
Compatibility and Releases......Page 8
Object-Oriented Programming......Page 9
Plug-in Extensibility......Page 10
HTML and HTML5......Page 11
Making “Hello World!” Appear on the Screen......Page 13
Get started with your application......Page 14
Import the enchant.js Library......Page 19
Edit the Source Code......Page 20
Preview Your Results......Page 24
Source Code Viewing Screen......Page 26
Execute on Devices......Page 27
Submitting to 9leap.net......Page 29
Conclusion......Page 34
Summary List......Page 35
Naming Variables......Page 36
Assign a Value to a Variable......Page 37
Check the Value of a Variable......Page 38
Data Types......Page 39
Compound Assignment Operators......Page 40
Manipulate a Variable Using Incrementation......Page 41
See How Similar Two Values Can Be......Page 42
Implement Logic with the If Statement......Page 43
Create an Object......Page 44
Work Smarter with the While and For Loop Statements......Page 47
Interrupt a Loop with Break......Page 48
Generate Random Numbers......Page 49
Define Scenarios with Switch......Page 50
Store Numbered Data in an Array......Page 51
Store Non-Numbered Data in an Associative Array......Page 52
See Where Variables Live......Page 53
Make Object Blueprints with Prototypes......Page 54
Conclusion......Page 55
Inheritance......Page 56
Seeing Elements of a Game......Page 57
Making the Core Object and Starting the Game......Page 58
Adding the Label to the rootScene......Page 59
Formatting Color......Page 60
Creating a Function to Create Labels for Us......Page 61
Creating a Random Number Function......Page 62
Automating Label Creation with the ENTER_FRAME Event Listener and Periodic Processing......Page 63
Slowing Down Processing with Frame and Modulo......Page 64
Making Labels Move......Page 65
Setting Up a Game for Sprites......Page 66
Specifying the Frame of a Sprite......Page 67
Animating a Sprite......Page 68
Moving a Sprite......Page 69
Drawing a Map with a Surface......Page 70
Creating Containers for a Map......Page 71
Populating the Map with Tiles......Page 72
Creating a Character......Page 73
Processing Movement from Touch......Page 75
Creating a D-Pad......Page 77
Processing Movement with the D-Pad......Page 79
Conclusion......Page 80
Transitioning Between Scenes......Page 81
Scene Properties and Methods......Page 82
Carrying Out Scene Transitions......Page 83
Creating a Game with Screens, Time Limits, and Scores......Page 86
Setting Up a Sample Game......Page 87
Adding Required Plug-Ins......Page 89
Methods for Collision Detection......Page 90
Creating an Interactive Map......Page 91
Creating a Map Object......Page 92
Populating Tiles and Setting Collision......Page 94
Using Collision Detection for Movement......Page 96
Scrolling the Map......Page 97
Using Collision Detection for a Goal......Page 98
Implementing Sound......Page 99
Setting Up the Game......Page 100
Playing Sounds......Page 102
Conclusion......Page 103
Don’t Try to Make an Epic Game......Page 104
Don’t Get Caught Up in What’s Missing......Page 105
Game Development Process......Page 106
Pick a Theme......Page 107
Creating the Simplest Version......Page 109
Making the Droid Appear......Page 111
Adjusting the Animation Speed......Page 113
Making a Droid Appear Randomly......Page 114
Implementing Droid Whacking......Page 115
Preventing Continuous Droid Whacking......Page 117
Duplicating the Hole......Page 119
Randomly Lining Up Holes......Page 120
Playing, Repeating, Completing......Page 121
Displaying a Score......Page 122
Limiting Droid Appearances......Page 123
Conclusion......Page 127
Building the Arcade Shooter......Page 128
Setting the Groundwork of the Game......Page 129
Creating the Player’s Ship......Page 130
Creating the Shoot Class......Page 132
Controlling Direction with Cos and Sin......Page 133
Creating the PlayerShoot Class and Making the Ship Shoot......Page 135
Creating Enemies......Page 136
Creating the enemyShoot Class and Making Enemies Shoot......Page 139
Making Enemies Move in an Arc......Page 140
Beefing Up the Game......Page 141
Explosions......Page 142
Adding a Scrolling Background......Page 145
Adding a Life Gauge......Page 148
Conclusion......Page 151
Same Origin Policy......Page 152
Setup......Page 153
3-D Games......Page 154
Creating a 3-D Whack-A-Droid Game......Page 155
Creating a Scene3D and Lights......Page 157
Creating a Camera3D......Page 158
Creating a Sprite3D......Page 160
Droid Interactivity......Page 161
Droid Appearance Behavior......Page 163
Planes: The Signboards and More of gl.enchant.js......Page 166
Replicating the Droid and Finishing the Game......Page 169
Panning Camera Effect......Page 170
Conclusion......Page 172
Appendix A: Class Appendix......Page 173
Common Properties......Page 174
Common Properties......Page 175
Common Events......Page 176
Game......Page 177
Label......Page 178
Common Properties......Page 179
Extends......Page 180
Sprite......Page 181
Common Methods......Page 182
Common Methods......Page 183
Extends......Page 184
Common Methods......Page 185
Common Methods......Page 186
Common Properties......Page 187
Common Properties......Page 188
Common Methods......Page 189
Index......Page 190