Created
April 24, 2013 02:20
-
-
Save AlphaGit/5449101 to your computer and use it in GitHub Desktop.
Arkanoid Ball -- taken from https://github.com/AlphaGit/random-javascript/blob/20c746aaa822ab66bf23dd6f249c7f19ee1546cc/arkanoid-canvas/arkanoid.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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