HTML5 promises to be the hot new platform for online games. HTML5 games work on computers, smartphones, and tablets, including iPhones and iPads. Be one of the first developers to build HTML5 games today and be ready for tomorrow!
This book will show you how to use the latest HTML5 and CSS3 web standards to build card games, drawing games, physics games, and even multiplayer games over the network. With this book, you will build six example games with clear systematic tutorials.
HTML5, CSS3, and the related JavaScript API are the latest hot topics in web. These standards bring us the new game market, HTML5 Games. With the new power from them, we can design games with HTML5 elements, CSS3 properties, and JavaScript to play in browsers.
This book is divided into nine chapters with each one focusing on one topic. We will create six games and specifically learn how we draw game objects, animate them, add audio, connect players, and build a physics game with a Box2D physics engine.
Chapter 1, Introducing HTML5 Games, introduces the new features from HTML5, CSS3, and related JavaScript API. It also demonstrates what games we can make with these features and its benefits.
Chapter 2, Getting Started with DOM-based Game Development, kick-starts the game development journey by creating a traditional Ping Pong game in DOM and jQuery.
Chapter 3, Building Memory Matching Game in CSS3, walks through the new features from CSS3 and discusses how we can create a memory card matching game in DOM and CSS3.
Chapter 4, Building Untangle Game with Canvas and Drawing API, introduces a new way to draw games and interact with them in a web page with the new Canvas element. It also demonstrates how to build a puzzle solving game with Canvas.
Chapter 5, Building a Canvas Game Masterclass, extends the untangle game to show how we can draw gradients and images using Canvas. It also discusses sprite sheet animations and multi-layer management.
Chapter 6, Adding Sounds Effects to Your Games, adds sound effects and background music to the game by using the Audio
element. It discusses the audio format capability among web browsers and creates a keyboard-driven music game by the end of the chapter.
Chapter 7, Using Local Storage to Store Game Data, extends the CSS3 memory matching game to demonstrate how we can use the new Local Storage API to store and resume game progress and best records.
Chapter 8, Building a Multiplayer Draw-and-Guess Game with WebSockets, discusses the new WebSockets API which allows browsers to establish a persistent connection with the socket server. This allows multiple players to play the game together in real time. A draw-and-guess game is created at the end of chapter.
Chapter 9, Building a Physics Car Game with Box2D and Canvas, teaches how to integrate a famous physics engine, Box2D, into our Canvas games. It discusses how to create physics bodies, apply force, connect them together, associate graphics with the physics, and finally create a platform card game.
You need the latest modern web browsers, a good text editor, and a basic HTML, CSS, and JavaScript knowledge.
This book is for game designers who have a basic understanding of HTML, CSS, and JavaScript and want to create Canvas or DOM-based games that run on browsers.
In this book, you will find several headings appearing frequently.
To give clear instructions of how to complete a procedure or task, we use:
1. Action 1
2. Action 2
3. Action 3
Instructions often need some extra explanation so that they make sense, so they are followed with:
This heading explains the working of tasks or instructions that you have just completed.
You will also find some other learning aids in the book, including:
These are short multiple choice questions intended to help you test your own understanding.
These set practical challenges and give you ideas for experimenting with what you have learned.
You will also 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: "We will start our HTML5 game development journey from index.html."
A block of code is set as follows:
// starting game var date = new Date(); audiogame.startingTime = date.getTime(); // some time later var date = new Date(); var elapsedTime = (date.getTime() - audiogame.startingTime)/1000;
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
function setupLevelData() { var notes = audiogame.leveldata.split(";"); // store the total number of dots audiogame.totalDotsCount = notes.length; for(var i in notes) { var note = notes[i].split(","); var time = parseFloat(note[0]); var line = parseInt(note[1]); var musicNote = new MusicNote(time,line); audiogame.musicNotes.push(musicNote); } }
Any command-line input or output is written as follows:
$ ./configure $ sudo make install
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: "You will get an introduction page of the multiuser sketchpad. Right click on the Launch Experiment option and choose Open link in new window".
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 book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail< [email protected]>
.
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/support, 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.