JSFiddle - React, Tailwind, and code Playground
JavaScript
// player.js
(function() {
window.game = {};
window.game.player = {
x: 5,
y: 10,
distanceTo: function(x, y) {
return Math.sqrt(Math.pow(x - this.x, 2) +
Math.pow(y - this.y, 2));
}
};
}());
// enemy.js
(function() {
window.game.enemy = {
x: 5,
y: 20,
move: function(x, y) {
this.x = x;
this.y = y;
}
};
}());
// crate.js
(function() {
window.game.crate = {
hp: 30,
damage: function(amount) {
this.hp -= amount;
}
};
}());