This repository has been archived on 2025-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
Servers-Under-Maintenance-G.../classes/GameObject.js

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();
}
}
}