O'Reilly logo

HTML5 Game Development by Example : Beginner's Guide - Second Edition by Makzan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – distinguishing the intersected lines

Let's increase the thickness of those intersected lines so we can distinguish them in the Canvas

  1. Open the untangle.drawing.js file in the text editor.
  2. We have the thinLineThickness variable as the default line thickness. We add the following code to define a thickness for bold lines:
    untangleGame.boldLineThickness = 5;
  3. Open the untangle.data.js file. We create a function to check whether the given two lines intersect. Add the following functions to the end of the JavaScript file:
    untangleGame.isIntersect = function(line1, line2) { // convert line1 to general form of line: Ax+By = C var a1 = line1.endPoint.y - line1.startPoint.y; var b1 = line1. startPoint.x - line1.endPoint.x; var c1 = a1 * line1.startPoint.x ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required