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

Installing the Box2D JavaScript library


Now, suppose that we want to create a car game. We apply force to the car to make it move forward. The car moves on a ramp and then flies through the air. Afterwards, the car falls on the destination ramp and the game finishes. Every collision in every part of the physics world counts on this movement. If we have to make this game from scratch, then we have to calculate at least the velocity and angle of each part. Luckily, the physics library helps us to handle all these physical problems. All we have to do is to create the physics model and present it in the canvas. The engine we use is Box2D.

Box2D is a 2D physics simulation engine. The original Box2D was written in C by Erin Catto. It was later ported to Flash ActionScript. Later on, its 2.1a version was ported to JavaScript. You can find the JavaScript version of Box2D 2.1a in their Google Code project at https://code.google.com/p/box2dweb/.

Note

At the time of writing this book, Google Code announced...