You are here today reading this book because you want to make video games. You wish to build your own video game, which can be run both in people's browsers as well as on their smartphones and tablets. All of this is possible today, though it has not been for the longest time. The reason you can now build your own game with relative ease is two fold: HTML5 and ImpactJS.
HTML5 is the latest version of our World Wide Web Hyper Text Markup Language and is the universal language for web pages. HTML has been around since the beginning of the 1990s when a CERN (the European organization for nuclear research) employee by the name of Tim Berners-Lee first introduced it. New versions were released quite rapidly: Version 2 in 1995, Version 3 in 1997, and Version 4 later that year. We had been using roughly the same version of HTML for over a decade until finally HTML5 saw the light in 2008. With the growing need for multimedia implementation, companies had been building browser plugins to play music, show movies, and so on. The Flash player is probably one of the best known plugins on this front. As a game developer you can still opt for using Flash and ActionScript, but we don't know how long Flash still has until (if ever) it will be fully replaced by HTML5. What will happen to Flash games remains hard to predict but one thing is pretty certain: the future of HTML5 based games looks bright. Since HTML5 emerged, browsers have been slowly increasing compatibility for it. HTML5 is a huge step forward as it introduces new elements to allow playing music and videos on the web pages themselves.
However, the most important new feature for us is the introduction of the <canvas>
element. The <canvas>
element is basically a placeholder for your graphical elements to appear on. Together with the use of JavaScript, it became possible to build browser games outside of Flash players. However, JavaScript in itself is not geared towards building games. In its raw form, you would be able to use it to build a game but it would prove dauntingly difficult. Thus, the last necessary ingredient is a JavaScript library with the sole purpose of game development. This is where ImpactJS comes into play.
ImpactJS is in essence a library of JavaScript code capable of making your life as a game developer a lot easier. ImpactJS was developed by Dominic Szablewski, a German genius, to say the least. The ImpactJS game engine has the advantage of enabling you to build a game very quickly with only a basic knowledge of JavaScript and HTML. This allows even a newbie programmer to focus on what they love: building the actual game. ImpactJS also comes with a very intuitive level editor and debug system, which we will also get into during the course of this book. ImpactJS is designed to build tile-based two-dimensional games. For instance, if you like to build a side-scrolling game such as Mario or a top-down game such as Zelda, you will want to go with ImpactJS. Now without much further ado, let's dive into the action by moving on to Chapter 1, Firing Up Your First Impact Game, where we will prepare ourselves for game development by gathering the necessary resources for it.
Chapter 1, Firing Up Your First Impact Game helps us to set up our development environment, get our first game up and running, and take a look at a few useful tools for the HTML5 game developer.
Chapter 2, Introducing ImpactJS dives into the basics of ImpactJS by exploring some of its key concepts using a premade game.
Chapter 3, Let's Build a Role Playing Game is a guide to building a top-down game from the ground up.
Chapter 4, Let's Build a Side-Scroller Game helps us build a side-scroller game from scratch, making use of the Box2D physics engine.
Chapter 5, Adding Some Advanced Features to Your Game teaches us to add some advanced features such as advanced artificial intelligence and data storage to the RPG game that we built in Chapter 3, Let's Build a Role Playing Game.
Chapter 6, Music and Sound Effects takes us deeper into how to use music and sound effects in ImpactJS, where to buy them, and how to make a basic tune with FL Studio.
Chapter 7, Graphics teaches us to create both vector and Photoshop graphics and explore the option of buying them from artists and specialized websites. Making your own graphics or buying them elsewhere is an important trade-off.
Chapter 8, Adapting Your HTML5 Game to the Distribution Channels helps us take a look at a few of the options for deploying your game to the different devices out there and how it can be done technically. This is the final step of the game development process.
Chapter 9, Making Money with Your Game takes a look at a few of the options to make money as a game developer, from taking care of your own sales and marketing, to selling your distribution rights.
Following are the software requirements for executing the code given in the book:
Server (example: XAMPP). Free to download.
JavaScript code editor (example: Komodo edit). Free to download.
ImpactJS game engine. Buy at www.impactjs.com.
Google Chrome browser. Free to download.
Firefox browser and Firebug plugin. Free to download.
FL Studio. Not free but only relevant for Chapter 6, Music and Sound Effects.
Photoshop. Not free but only relevant for Chapter 7, Graphics.
Inkscape. Free to download.
This book is for anyone with at least a basic knowledge of JavaScript, CSS, and HTML. If you have the desire to build your own game for your website or an app store but have no idea how and where to begin, this book is for you.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Open your browser and type localhost
in the address bar."
A block of code is set as follows:
EntityPlayer = ig.Entity.extend({ size: {x:20,y:40}, offset:{x:6,y:4}, vel: {x:0,y:0}, maxVel:{x:200,y:200}, health: 400,
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
.defines(function(){ GameInfo = new function(){ this.score = 0; },
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Clicking the Next button moves you to the next screen".
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>
, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.