forked from microsoft/microcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.ts
74 lines (65 loc) · 1.89 KB
/
sprite.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace microcode {
export class Sprite implements IComponent, IPlaceable, ISizable {
private xfrm_: Affine
image: Image
invisible: boolean
public get xfrm() {
return this.xfrm_
}
public get width() {
return this.image.width
}
public get height() {
return this.image.height
}
public get hitbox() {
return Bounds.FromSprite(this)
}
public get bounds() {
let b = new Bounds({
left: 0,
top: 0,
width: this.width,
height: this.height,
})
return b.translate(
new Vec2(-(this.width >> 1), -(this.height >> 1))
)
}
constructor(opts: { parent?: IPlaceable; img: Image }) {
this.xfrm_ = new Affine()
this.xfrm_.parent = opts.parent && opts.parent.xfrm
this.image = opts.img
}
update() { }
public setImage(img: Image) {
this.image = img
}
public bindXfrm(xfrm: Affine) {
this.xfrm_ = xfrm
}
public occlusions(bounds: Bounds) {
return Occlusions.FromSprite(this, bounds)
}
public isOffScreenX(): boolean {
const p = this.xfrm.worldPos
return (
p.x + (this.width >> 1) < Screen.LEFT_EDGE ||
p.x - (this.width >> 1) > Screen.RIGHT_EDGE
)
}
draw() {
control.enablePerfCounter()
if (this.invisible) {
return
}
Screen.drawTransparentImageXfrm(
this.xfrm,
this.image,
-(this.image.width >> 1),
-(this.image.height >> 1)
)
}
}
const _pos: Vec2 = new Vec2(0, 0)
}