Open the
untangle.data.js
file in the text editor.Add the following
circle
object definition code in the JavaScript file:untangleGame.Circle = function(x,y,radius){ this.x = x; this.y = y; this.radius = radius; }
Now we need an array to store the circles' positions. Add a new array to the
untangleGame
object:untangleGame.circles = [];
While drawing every circle in the Canvas, we save the position of the circle in the
circles
array. Add the following line before calling thedrawCircle
function, inside thecreateRandomCircles
function:untangleGame.circles.push(new untangleGame.Circle(x,y,circleRadius));
After the steps, we should have the following code in the
untangle.data.js
file:if (untangleGame === undefined) { var untangleGame = {}; } untangleGame.circles = []; untangleGame.Circle = function(x,y,radius){ this.x = x; this.y = y; this.radius = radius; }; untangleGame.createRandomCircles = function(width, height) { // randomly...
HTML5 Game Development by Example: Beginner's Guide
By :
HTML5 Game Development by Example: Beginner's Guide
By:
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
Free Chapter
Introducing HTML5 Games
Getting Started with DOM-based Game Development
Building a Card-matching Game in CSS3
Building the Untangle Game with Canvas and the Drawing API
Building a Canvas Game's Masterclass
Adding Sound Effects to Your Games
Saving the Game's Progress
Building a Multiplayer Draw-and-Guess Game with WebSockets
Building a Physics Car Game with Box2D and Canvas
Deploying HTML5 Games
Pop Quiz Answers
Index
Customer Reviews