diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-26 14:24:53 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-26 14:24:53 +0100 |
commit | 474a7253b6b67e2ed33936f6b633587d5d304b66 (patch) | |
tree | 456b9cef3cb59da8e0eb575b9425a1fedfe67e1e /src/entities/hello_kitty/laser.js | |
parent | 1fc522bc8c4a96858223e597ced8fea94ba57874 (diff) |
hello kitty stage 1 and 2 done
Diffstat (limited to 'src/entities/hello_kitty/laser.js')
-rw-r--r-- | src/entities/hello_kitty/laser.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/entities/hello_kitty/laser.js b/src/entities/hello_kitty/laser.js new file mode 100644 index 0000000..b8e480d --- /dev/null +++ b/src/entities/hello_kitty/laser.js @@ -0,0 +1,72 @@ +import { WHITE, HELLO_KITTY } from "../../assets.js" +import { Vector } from "../../engine/vector.js" +import { Engine } from "../../engine.js" +import { Entity } from "../entity.js" +import { boshy } from "../../main.js" +import { Bullet } from "./bullet.js" + +export class Laser extends Entity { + attacking = false + loadingTimeLeft = 70 + attackTimeLeft = 40 + + attackSize = 150 + shrinkSpeed = 15 + + constructor(x, delayed) { + super({ + size: new Vector(40, Engine.screen.viewport.y), + position: new Vector(x, Engine.screen.viewport.y / 2), + sprite: WHITE, + pixelated: true, + }) + this.span.style.zIndex = -1 + if (delayed) { + this.size.x = 60 + this.loadingTimeLeft = 100 + } + } + + update() { + if (this.loadingTimeLeft) { + if (this.size.x) this.size.x -= 1 + this.loadingTimeLeft-- + if (!this.loadingTimeLeft) { + this.attacking = true + this.size.x = 100 + Engine.radio.playSound(HELLO_KITTY.LASER_SOUND) + Engine.screen.shake() + this.spawnBullets() + } + return + } + + if (this.attackTimeLeft) { + if (this.size.x == this.attackSize) this.size.x += 10 + else this.size.x = this.attackSize + this.attackTimeLeft-- + if (Engine.collision.collidingWithBoshy(this.position, this.hitbox)) { + boshy.die() + } + return + } + + this.size.x -= this.shrinkSpeed + if (this.size.x <= 0) this.remove() + + } + + spawnBullets() { + let bulletCenter = new Vector(this.position.x, Engine.screen.viewport.y) + let randomness_angle = Engine.random(-20, 20) + for (let i = -1; i < 2; i++) { + new Bullet({ + position: bulletCenter.clone(), + speed: 6, + spinning: true, + degrees: 270 + 40 * i + randomness_angle, + gravity: 0.15, + }) + } + } +} |