Book Image

HTML5 Games Development by Example: Beginner's Guide

By : Makzan
Book Image

HTML5 Games Development by Example: Beginner's Guide

By: Makzan

Overview of this book

<p>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!</p> <p>The book will show you how to use latest HTML5 and CSS3 web standards to build card games, drawing games, physics games and even multiplayer games over the network. With the book you will build 6 example games with clear step-by-step tutorials.</p> <p>HTML5, CSS3 and related JavaScript API is the latest hot topic 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.</p> <p>The book divides into 9 chapters with each one focusing on one topic. We will create 6 games in the book and specifically learn how we draw game objects, animate them, adding audio, connecting players and building physics game with Box2D physics engine.</p>
Table of Contents (16 chapters)
HTML5 Games Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action Checking a collision between the car and the destination body


Carry out the following steps:

  1. 1. Again, we start from our game logic. Open the html5games.box2dcargame.js JavaScript file in a text editor.

  2. 2. We setup a destination ground in the ground creation code and assign it to our gamewinWall reference inside the carGame global object instance as follows:

    carGame.gamewinWall = createGround(1200, 215, 15, 25, 0);
    
  3. 3. Next, we move on to the step function. In each step, we get the complete contact list from the world and check whether any two colliding objects are car and the destination ground:

    function step() {
    carGame.world.Step(1.0/60, 1);
    ctx.clearRect(0, 0, canvasWidth, canvasHeight);
    drawWorld(carGame.world, ctx);
    setTimeout(step, 10);
    //loop all contact list to check if the car hits the winning wall
    for (var cn = carGame.world.GetContactList(); cn != null; cn = cn.GetNext()) {
    var body1 = cn.GetShape1().GetBody();
    var body2 = cn.GetShape2().GetBody();
    if ((body1 == carGame...