blob: 2b3ab7179758857c91dd1990bd3b9d2a670832a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { Vector } from "../engine/vector.js"
import { Engine } from "../engine.js"
import { entities, boshy } from "../main.js"
export class Entity {
rotation = 0
constructor({
size,
hitbox = size,
sprite,
position = new Vector(0,0),
pixelated = false,
degrees = 0,
}) {
this.size = size
this.hitbox = hitbox
this.position = position
this.rotation = degrees
this.span = document.createElement("img")
this.span.src = sprite
Engine.screen.append(this.span)
entities.list.push(this)
if (pixelated) this.span.className = "pixelated"
}
update() {}
draw() {
Engine.screen.draw(this.span, this.position, this.size, this.rotation)
}
remove() {
this.span.remove()
entities.remove(this)
}
updateAsHazard() {
if (Engine.collision.collidingWithBoshy(this.position, this.hitbox)) {
boshy.die()
}
}
checkBounds() {
if (Engine.screen.isOffLimits(this.position, this.size)) {
this.remove()
}
}
}
|