summaryrefslogtreecommitdiff
path: root/src/entities/hello_kitty/bullet.js
blob: 1caeb7c191ab62c25f47ce13e6532c9b867389f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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()
        }
    }
}