var catbug = {}; catbug.x = 45; catbug.y = 90; catbug.vX = 0; catbug.vY = 0; catbug.frame = 0; catbug.HP = 3; catbug.maxHP = 3; catbug.move = function() { this.x += this.vX; this.y += this.vY; if (this.x <= 0 || this.x >= 320) { this.x -= this.vX; } if (this.y <= 0 || this.y >= 180) { this.y -= this.vY; } } catbug.isInRect = function(box) { if (this.x >= box.x && this.x <= box.x + box.w && this.y >= box.y && this.y <= box.y + box.h) { return true; } return false; }