Game Development Reference
In-Depth Information
};
this.move = move;
this.getSkin = function() { return skin; };
this.setDead = function(isDead) { isAlive =
!isDead; };
this.isAlive = function() { return isAlive;
};
this.getBody = function() { return body; };
this.getHead = function() { return {x:
body[0], y: body[1]}; };
this.grow = function() { if (size * 2 <
body.length) return size++; };
// Check if the snake is at a certain
position on the grid
this.isAt = function(x, y, includeHead) {
var offset = includeHead ? 0 : 2;
for (var i = 2, len = body.length; i <
len; i += 2) {
if (body[i] == x && body[i + 1] == y)
return true;
}
return false;
};
this.reset = function(x, y) {
for (var i = 0, len = body.length; i <
len; i++)
body[i] = -1;
body[0] = x;
body[1] = y;
size = 0;
isAlive = true;
dir[keys.UP] = false;
dir[keys.DOWN] = false;
dir[keys.LEFT] = false;
dir[keys.RIGHT] = false;
};
};
Search WWH ::




Custom Search