Time for action – checking a collision between the car and the destination body

Carry out the following steps to handle collision:

  1. Again, we start from our game logic. Open the box2dcargame.js JavaScript file in a text editor.
  2. We set up 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. 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 the car and the destination ground:
    function checkCollision() { // loop all contact list // to check if the car hits the winning wall. for (var cn = carGame.world.GetContactList(); ...

Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.