29 lines
599 B
JavaScript
29 lines
599 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
|
|
}
|
|
|
|
onClick() {}
|
|
|
|
// 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
|
|
}
|
|
}
|