57 lines
941 B
JavaScript
57 lines
941 B
JavaScript
class GameObject {
|
|
static gameObjects = [];
|
|
|
|
constructor(x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.clickable = false;
|
|
GameObject.gameObjects.push(this);
|
|
}
|
|
|
|
update() {
|
|
|
|
}
|
|
|
|
click() {
|
|
|
|
}
|
|
|
|
mouseUp() {
|
|
|
|
}
|
|
|
|
draw() {
|
|
Game.c.fillStyle = "red";
|
|
Game.c.fillRect(this.x, this.y, Game.TILESIZE, Game.TILESIZE);
|
|
}
|
|
|
|
|
|
distance(o) {
|
|
return Math.sqrt(Math.pow(this.x - o.x, 2) + Math.pow(this.y - o.y, 2));
|
|
}
|
|
|
|
delete() {
|
|
if (this.hitbox != undefined) {
|
|
this.hitbox.delete()
|
|
}
|
|
for (let i = 0; i < GameObject.gameObjects.length; i++) {
|
|
if (GameObject.gameObjects[i] == this) {
|
|
GameObject.gameObjects.splice(i, 1);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static updateAll() {
|
|
for (let o in GameObject.gameObjects) {
|
|
GameObject.gameObjects[o].update();
|
|
}
|
|
}
|
|
|
|
static drawAll() {
|
|
GameObject.gameObjects.sort((a, b) => (a.y > b.y ? 1 : -1));
|
|
for (let o in GameObject.gameObjects) {
|
|
GameObject.gameObjects[o].draw();
|
|
}
|
|
}
|
|
} |