HTML and CSS Reference
In-Depth Information
// logic of RectShape constructor goes here
// inherit via prototype
RectShape.prototype = Object.create(createjs.Container.prototype);
RectShape.prototype.newMethod = function(){
// instance method definition goes here.
Random position
We drop the newly generated boxes from the top edge in a random x posiion. The default
reference point (0, 0) is at the top-left corner of the box. When we generate the box, the x
posiion ranges from 0 to the game width-box width . Otherwise, a generated box may be
out of the visible area and the player will not be able to eliminate it. The following figure
shows the relaionship between the game width, box width, and the random range:
game width
game width-box width
The built-in JavaScript's random funcion returns a random loaing number between 0 and
1. However, what we want is a random integer between two integers. This can be done by
using the following formula:
// Random number between A (inclusive) and B (exclusive)
X * (B-A+1) + A where X is the random result
Its implementaion is as follows:
function randomInt(min, max) {
return Math.floor(Math.random() * (max-min+1) + min);
Search WWH ::

Custom Search