From 25adfc618e77db9a5ee3b98ce0dab0be832efed0 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Tue, 24 Dec 2024 17:58:20 +0100 Subject: hello kitty base done --- src/entities/hello_kitty.js | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/entities/hello_kitty.js (limited to 'src/entities/hello_kitty.js') 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 + } +} -- cgit v1.2.3