Files
nathannlu-ComfyUI-Pets/js/game/core.js
T
2024-03-10 18:27:57 -07:00

28 lines
593 B
JavaScript

import { generateId } from '../utils.js';
export class GameObject {
constructor(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.id = generateId();
this.isActive = true;
}
// Check if this object is touching another object
isTouching(otherObject) {
return (
this.x < otherObject.x + otherObject.width &&
this.x + this.width > otherObject.x &&
this.y < otherObject.y + otherObject.height &&
this.y + this.height > otherObject.y
);
}
delete() {
this.isActive = false;
}
}