// entity.js (function() { window.game = {}; window.game.entity = { distanceTo: function(x, y) { return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2)); }, move: function(x, y) { this.x = x; this.y = y; }, damage: function(amount) { this.hp -= amount; } } }()); // player.js (function() { function Player(hp, x, y) { this.hp = hp; this.x = x; this.y = y; } Player.prototype = window.game.entity; window.game.player = new Player(10, 5, 10); }()); // enemy.js (function() { function Enemy(hp, x, y) { this.hp = hp; this.x = x; this.y = y; } Enemy.prototype = window.game.entity; window.game.enemy = new Enemy(3, 5, 20); }()); // crate.js (function() { function Crate(hp, x, y) { this.hp = hp; this.x = x; this.y = y; } Crate.prototype = window.game.entity; window.game.crate = new Crate(100, 5, 5); }());