From 474a7253b6b67e2ed33936f6b633587d5d304b66 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Thu, 26 Dec 2024 14:24:53 +0100 Subject: hello kitty stage 1 and 2 done --- src/entities/hello_kitty/bullet.js | 58 ++++++++++++++++++++++ src/entities/hello_kitty/bullet_particles.js | 29 +++++++++++ src/entities/hello_kitty/laser.js | 72 ++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 src/entities/hello_kitty/bullet.js create mode 100644 src/entities/hello_kitty/bullet_particles.js create mode 100644 src/entities/hello_kitty/laser.js (limited to 'src/entities/hello_kitty') diff --git a/src/entities/hello_kitty/bullet.js b/src/entities/hello_kitty/bullet.js new file mode 100644 index 0000000..1caeb7c --- /dev/null +++ b/src/entities/hello_kitty/bullet.js @@ -0,0 +1,58 @@ +import { 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 { BulletParticle } from "./bullet_particles.js" + +export class Bullet extends Entity { + constructor({ + position, + speed, + spinning = false, + degrees = 0, + gravity = 0, + }) { + super({ + size: new Vector(30, 30), + position: position, + sprite: HELLO_KITTY.BULLET, + degrees: degrees + }) + + this.spinning = spinning + this.velocity = Vector.fromDeg(degrees) + this.velocity.multiply(speed) + this.velocity.floor() + + this.gravity = gravity + + if (speed > 6) this.emittingParticles = true + } + + particleReloadTime = 10 + particleTimeWait = this.particleReloadTime + spinSpeed = 10 + + update() { + this.velocity.y += this.gravity + this.position.add(this.velocity) + + if (this.emittingParticles) { + if (!this.particleTimeWait) { + this.particleTimeWait = this.particleReloadTime + new BulletParticle(this.position.clone()) + } + this.particleTimeWait-- + } + + if (this.spinning) this.rotation += this.spinSpeed + + if (Engine.collision.collidingWithBoshy(this.position, this.hitbox)) { + boshy.die() + } + if (Engine.screen.isOffLimits(this.position, this.size)) { + this.remove() + } + } +} diff --git a/src/entities/hello_kitty/bullet_particles.js b/src/entities/hello_kitty/bullet_particles.js new file mode 100644 index 0000000..c4dee60 --- /dev/null +++ b/src/entities/hello_kitty/bullet_particles.js @@ -0,0 +1,29 @@ +import { HELLO_KITTY } from "../../assets.js" +import { Vector } from "../../engine/vector.js" +import { Engine } from "../../engine.js" +import { Entity } from "../entity.js" + +export class BulletParticle extends Entity { + constructor(position) { + super({ + size: new Vector(20, 20), + position: position, + sprite: HELLO_KITTY.BULLET, + }) + this.rotation = Engine.random(0, 360) + this.rotationSpeed = Engine.random(-10, 10) + this.velocity = new Vector( + Engine.random(-2, 2), + Engine.random(-2, 2), + ) + } + + update() { + this.position.add(this.velocity) + this.rotation += this.rotationSpeed + this.size.x = this.size.y -= 1 + if (this.size.x <= 0) { + this.remove() + } + } +} 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, + }) + } + } +} -- cgit v1.2.3