var EHDI = EHDI || Object.create(null); EHDI.GAME = EHDI.GAME || Object.create(null); EHDI.GAME.components = EHDI.GAME.components || Object.create(null); //should not be instantiated EHDI.GAME.components.GameObject = function(texture) { EHDI.aka.Sprite.call(this, texture); } EHDI.GAME.components.GameObject.prototype = Object.create(EHDI.aka.Sprite.prototype); EHDI.GAME.components.GameObject.prototype.update = function() { } EHDI.GAME.components.GameObject.prototype.setRandomPosition = function(xBoundFrom, xBoundTo, yBoundFrom, yBoundTo) { this.position.x = EHDI.GAME.utils.randomInt(xBoundFrom, xBoundTo); this.position.y = EHDI.GAME.utils.randomInt(yBoundFrom, yBoundTo); } EHDI.GAME.components.GameObject.prototype.checkCollision = function(obj) { var combinedHalfWidths, combinedHalfHeights, vx, vy; if(obj == null) return false; if(obj.anchor && obj.anchor.x == 1) { obj.x -= obj.width; } if(obj.anchor && obj.anchor.y == 1) { obj.y -= obj.height; } this.centerX = this.x + this.width / 2; this.centerY = this.y + this.height / 2; obj.centerX = obj.x + obj.width / 2; obj.centerY = obj.y + obj.height / 2; this.halfWidth = this.width / 2; this.halfHeight = this.height / 2; obj.halfWidth = obj.width / 2; obj.halfHeight = obj.height / 2; vx = this.centerX - obj.centerX; vy = this.centerY - obj.centerY; combinedHalfWidths = this.halfWidth + obj.halfWidth; combinedHalfHeights = this.halfHeight + obj.halfHeight; if (Math.abs(vx) < combinedHalfWidths) if (Math.abs(vy) < combinedHalfHeights) return true; return false; };