blob: eb7552aee591b63bcb1c2b4af8cee42aae778afc (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import { Vector } from "../engine/vector.js"
import { Engine } from "../engine.js"
import { Entity } from "./entity.js"
import { HELLO_KITTY } from "../assets.js"
import { setEnemy, boshy } from "../main.js"
export class HelloKitty extends Entity {
max_hp = 500
hp = this.max_hp
previous = 0
moveInterval = 30
justGotHit = false
turningRight = false
constructor() {
super({
size: new Vector(200, 200),
hitbox: new Vector(100, 200),
position: new Vector(325, 140),
sprite: HELLO_KITTY.MAIN[0],
pixelated: true,
})
this.span.style.zIndex = 1
setEnemy(this)
}
update() {
this.move()
if (Engine.collision.collidingWithBoshy(this.position, this.hitbox)) {
boshy.die()
}
}
move() {
/* get position */
let localscale = Math.sin((Engine.frame - this.previous) / this.moveInterval)
let viewport = Engine.screen.viewport
let newPos = (viewport.x / 2) + (localscale * viewport.x / 2) * 0.6
this.turningRight = this.position.x < newPos
this.position.x = newPos
// this.position.x += this.speed
// if (this.position.x > 325) this.speed -= this.acceleration
// else this.speed += this.acceleration
}
draw() {
/* hit effect */
if (this.justGotHit) {
this.span.style.filter = "brightness(500%)"
this.justGotHit = false
} else {
this.span.style.filter = "brightness(100%)"
}
if (this.turningRight) this.span.style.transform = "scaleX(-1)"
else this.span.style.transform = "scaleX(1)"
/* frame */
this.span.src = (Math.floor(Engine.frame / 10 % 2) == 0) ?
HELLO_KITTY.MAIN[0] :
HELLO_KITTY.MAIN[1]
/* draw */
super.draw()
}
hit() {
this.hp--
if (!this.justGotHit) Engine.radio.playSound(HELLO_KITTY.HIT_SOUND)
this.justGotHit = true
}
}
|