summaryrefslogtreecommitdiff
path: root/src/entities/hello_kitty.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/hello_kitty.js')
-rw-r--r--src/entities/hello_kitty.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/entities/hello_kitty.js b/src/entities/hello_kitty.js
new file mode 100644
index 0000000..eb7552a
--- /dev/null
+++ b/src/entities/hello_kitty.js
@@ -0,0 +1,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
+ }
+}