Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Created April 24, 2013 02:20
Show Gist options
  • Save AlphaGit/5449101 to your computer and use it in GitHub Desktop.
Save AlphaGit/5449101 to your computer and use it in GitHub Desktop.
Ball.prototype = Object.create(DrawableCircle.prototype);
Ball.prototype.constructor = DrawableCircle;
function Ball(drawingContext, color, radius, stageHeight, stageWidth) {
var self = this;
self.centerBall = function() {
self.centerX = (stageWidth - radius*2) / 2;
self.centerY = (stageHeight - radius*2) / 2;
}
self.centerBall();
DrawableCircle.call(this, drawingContext, color, radius, self.centerX, self.centerY);
var move = function(dX, dY) {
self.centerX += dX;
self.centerY += dY;
};
var hitsBottom = function() {
return stageHeight - radius <= self.centerY;
};
var hitsTop = function() {
return self.centerY <= radius;
};
var hitsLeft = function() {
return self.centerX <= radius;
};
var hitsRight = function() {
return stageWidth - radius <= self.centerX;
};
return {
centerBall: self.centerBall,
draw: self.draw,
move: move,
hitsBottom: hitsBottom,
hitsTop: hitsTop,
hitsLeft: hitsLeft,
hitsRight: hitsRight
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment