summaryrefslogtreecommitdiff
path: root/src/entities/hello_kitty/bullet.js
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-26 14:24:53 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-26 14:24:53 +0100
commit474a7253b6b67e2ed33936f6b633587d5d304b66 (patch)
tree456b9cef3cb59da8e0eb575b9425a1fedfe67e1e /src/entities/hello_kitty/bullet.js
parent1fc522bc8c4a96858223e597ced8fea94ba57874 (diff)
hello kitty stage 1 and 2 done
Diffstat (limited to 'src/entities/hello_kitty/bullet.js')
-rw-r--r--src/entities/hello_kitty/bullet.js58
1 files changed, 58 insertions, 0 deletions
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()
+ }
+ }
+}