Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

Preface

HTML5 promises to be the hot new platform for online games. HTML5 games work on computers, smartphones, tablets, 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 topic in the Web. These standards bring us the new game market of HTML5 games. With the new power from them, we can design games with HTML5 elements, CSS3 properties, and JavaScript to play in browsers.

The book is divided into 10 chapters with each one focusing on one topic. While building the six games in the book, you will learn how to draw game objects, animate them, add audio, connect players, and build physics game with the Box2D physics engine.

What this book covers

Chapter 1, Introducing HTML5 Games, introduces the new features of HTML5, CSS3, and the related JavaScript API. It demonstrates what games we can make with these features and their benefits.

Chapter 2, Getting Started with DOM-based Game Development, kickstarts the game development journey by creating a traditional Ping Pong game in DOM and jQuery.

Chapter 3, Building a Card-matching Game in CSS3, walks you through the new features of CSS3 and discusses how we can create a memory card-matching game in DOM and CSS3.

Chapter 4, Building the Untangle Game with Canvas and the Drawing API, introduces a new way to draw things and interact with them in a web page with the new canvas element. This also demonstrates how to handle dragging on touch devices.

Chapter 5, Building a Canvas Game's Masterclass, extends the Untangle game to show how we can draw gradients and images in the Canvas. It also discusses sprite sheet animations and multilayer management.

Chapter 6, Adding Sound 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, Saving the Game's Progress, extends the CSS3 memory-matching game to demonstrate how we can use the Local Storage API to store and resume game progress and records the best scores.

Chapter 8, Building a Multiplayer Draw-and-Guess Game with WebSockets, discusses the WebSockets API that allows browsers to establish 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 the chapter.

Chapter 9, Building a Physics Car Game with Box2D and Canvas, teaches you 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 car game.

Chapter 10, Deploying HTML5 Games, shares the different ways in which we can publish our games. It discusses wrapping the web into a native app for Apple's App Store.

Appendix, Pop Quiz Answers, gives the answers to the pop quiz questions in each of the chapters.

What you need for this book

You need the latest modern web browsers, a good text editor, and a basic knowledge of HTML, CSS, and JavaScript. In Chapter 8, Building a Multiplayer Draw-and-Guess Game with WebSockets, we need the Node.js server, which we will help you to install in that chapter.

Who this book is for

This book is for web designers who have a basic knowledge of HTML, CSS, and JavaScript and want to create Canvas or DOM-based games that run on browsers.

Sections

In this book, you will find several headings that appear frequently (Time for action, What just happened?, Pop quiz, and Have a go hero).

To give clear instructions on how to complete a procedure or task, we use these sections as follows:

Time for action – heading

  1. Action 1

  2. Action 2

  3. Action 3

Instructions often need some extra explanation to ensure they make sense, so they are followed with these sections:

What just happened?

This section explains the working of the tasks or instructions that you have just completed.

You will also find some other learning aids in the book, for example:

Pop quiz – heading

These are short multiple-choice questions intended to help you test your own understanding.

Have a go hero – heading

These are practical challenges that give you ideas to experiment with what you have learned.

Conventions

You will also find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Open the index.html file in the code editor."

A block of code is set as follows:

var matchingGame = {};
matchingGame.deck = [
  'cardAK', 'cardAK',
  'cardAQ', 'cardAQ',
  'cardAJ', 'cardAJ',
  'cardBK', 'cardBK',
  'cardBQ', 'cardBQ',
  'cardBJ', 'cardBJ',
];

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(){
  matchingGame.deck.sort(shuffle);

  for(var i=0;i<11;i++){
    $(".card:first-child").clone().appendTo("#cards");
  }

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: "In MAC, click on the Get the code tab and you will see the following screenshot; this shows a guide on how to embed this font into our web page."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at www.packtpub.com/authors.

Customer support

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.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/7770OS_ColoredImages.pdf.

Errata

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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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 with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to