diff options
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/bigdump.js | 40 | ||||
-rw-r--r-- | src/entities/boshy.js | 21 | ||||
-rw-r--r-- | src/entities/boshybullet.js | 2 | ||||
-rw-r--r-- | src/entities/entity.js | 6 | ||||
-rw-r--r-- | src/entities/hello_kitty.js | 186 | ||||
-rw-r--r-- | src/entities/hello_kitty/bullet.js | 58 | ||||
-rw-r--r-- | src/entities/hello_kitty/bullet_particles.js | 29 | ||||
-rw-r--r-- | src/entities/hello_kitty/laser.js | 72 | ||||
-rw-r--r-- | src/entities/hello_kitty_background.js | 20 | ||||
-rw-r--r-- | src/entities/hp_bar.js | 1 |
10 files changed, 394 insertions, 41 deletions
diff --git a/src/entities/bigdump.js b/src/entities/bigdump.js new file mode 100644 index 0000000..90b4a57 --- /dev/null +++ b/src/entities/bigdump.js @@ -0,0 +1,40 @@ +import { ANTICHEESE } from "../assets.js" +import { Vector } from "../engine/vector.js" +import { Engine } from "../engine.js" +import { Entity } from "./entity.js" +import { boshy } from "../main.js" + +export class BigDump extends Entity { + constructor(bottom = false) { + let position = bottom ? + new Vector(0, boshy.position.y) : + new Vector(boshy.position.x, 0) + + super({ + size: new Vector(200, 10), + position: position, + sprite: ANTICHEESE, + degrees: bottom ? 270 : 0, + }) + + this.bottom = bottom + } + + speed = 10 + maxSize = 200 + + update() { + if (this.size.y < this.maxSize) this.size.y += this.speed * 0.75 + if (this.bottom) this.position.x += this.speed + else this.position.y += this.speed + + console.log("dump", this.position) + + 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/boshy.js b/src/entities/boshy.js index 9a2b589..d2d723f 100644 --- a/src/entities/boshy.js +++ b/src/entities/boshy.js @@ -22,6 +22,7 @@ export class Boshy extends Entity { sprite: BOSHY.NORMAL, }) + /* play initial sound */ switch (currentScene) { case SCENES.PREQUEL: Engine.radio.playSound(BOSHY.SOUNDS.INTRO2) @@ -67,15 +68,18 @@ export class Boshy extends Entity { this.lastShot = Engine.frame /*(reset reload)*/ - let bullet_a_position = this.position.clone() - let bullet_b_position = this.position.clone() + /* it was supposed to shoot twice */ + // let bullet_a_position = this.position.clone() + // let bullet_b_position = this.position.clone() - bullet_a_position.x = bullet_a_position.x + 5 - bullet_b_position.x = bullet_b_position.x - 5 + // bullet_a_position.x = bullet_a_position.x + 5 + // bullet_b_position.x = bullet_b_position.x - 5 - new BoshyBullet(bullet_a_position) - new BoshyBullet(bullet_b_position) - // new BoshyBullet(this.position.clone()) + // new BoshyBullet(bullet_a_position) + // new BoshyBullet(bullet_b_position) + + /* but once again, we need to save resources */ + new BoshyBullet(this.position.clone()) Engine.radio.playSound(BOSHY.SOUNDS.SHOOT) } @@ -84,6 +88,7 @@ export class Boshy extends Entity { this.dead = true this.playDeathSounds() this.spawnBlood() + Engine.screen.shake() this.position.x = 0 this.position.y = Engine.screen.viewport.y @@ -104,7 +109,7 @@ export class Boshy extends Entity { spawnBlood() { for (let i = 0; i<20; i++) { - new Blood(this.position.clone().floor()) + new Blood(this.position.clone()) } } } diff --git a/src/entities/boshybullet.js b/src/entities/boshybullet.js index a87e159..8c8a191 100644 --- a/src/entities/boshybullet.js +++ b/src/entities/boshybullet.js @@ -10,7 +10,7 @@ export class BoshyBullet extends Entity { constructor(position = new Vector(0,0)) { super({ size: new Vector(5, 5), - position: position.floor(), + position: position, sprite: BOSHY.BULLET, }) } diff --git a/src/entities/entity.js b/src/entities/entity.js index 9d27508..0dbe00c 100644 --- a/src/entities/entity.js +++ b/src/entities/entity.js @@ -3,16 +3,20 @@ import { Engine } from "../engine.js" import { entities } from "../main.js" export class Entity { + rotation = 0 + constructor({ size, hitbox = size, sprite, position = new Vector(0,0), pixelated = false, + degrees = 0, }) { this.size = size this.hitbox = hitbox this.position = position + this.rotation = degrees this.span = document.createElement("img") this.span.src = sprite @@ -25,7 +29,7 @@ export class Entity { update() {} draw() { - Engine.screen.draw(this.span, this.position, this.size) + Engine.screen.draw(this.span, this.position, this.size, this.rotation) } diff --git a/src/entities/hello_kitty.js b/src/entities/hello_kitty.js index 69646fd..65fa30b 100644 --- a/src/entities/hello_kitty.js +++ b/src/entities/hello_kitty.js @@ -3,16 +3,21 @@ import { Engine } from "../engine.js" import { Entity } from "./entity.js" import { HELLO_KITTY } from "../assets.js" import { setEnemy, boshy } from "../main.js" +import { Bullet } from "./hello_kitty/bullet.js" +import { Laser } from "./hello_kitty/laser.js" export class HelloKitty extends Entity { - max_hp = 500 + max_hp = 300 hp = this.max_hp - previous = 0 moveInterval = 26 + previous = 0 + stage = 1 justGotHit = false turningRight = false + bulletMarginY = 40 + constructor() { super({ size: new Vector(200, 200), @@ -22,30 +27,25 @@ export class HelloKitty extends Entity { pixelated: true, }) + this.span.style.zIndex = 1 setEnemy(this) } update() { - this.move() + switch (this.stage) { + case 0: this.stage0() + case 1: this.stage1(); break + case 2: this.stage2(); break + } 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 - } - + delayBetweenFrames = 10 + timeUntilNextFrame = this.delayBetweenFrames + frameAlternator = false draw() { /* hit effect */ if (this.justGotHit) { @@ -55,18 +55,162 @@ export class HelloKitty extends Entity { this.span.style.filter = "brightness(100%)" } - if (this.turningRight) this.span.style.transform = "scaleX(-1)" - else this.span.style.transform = "scaleX(1)" + if (this.speed > 0) this.span.style.transform = "scaleX(-1)" + else if (this.speed < 0) 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] + /* this is what it should be doing */ + // this.span.src = (Math.floor(Engine.frame / 10 % 2) == 0) ? + // HELLO_KITTY.MAIN[0] : + // HELLO_KITTY.MAIN[1] + /* but no hi ha pressupost for it */ + /* here's the alternative: */ + if (!this.timeUntilNextFrame) { + this.timeUntilNextFrame = this.delayBetweenFrames + this.span.src = this.frameAlternator ? + HELLO_KITTY.MAIN[0] : + HELLO_KITTY.MAIN[1] + this.frameAlternator = !this.frameAlternator + } + this.timeUntilNextFrame-- /* draw */ super.draw() } + attacksUntilNextStage = 6 + normalAttackDelay = 100 + attackWaitTime = this.normalAttackDelay + + stage0() { + this.innerStage = 0 + this.timeUntilNextInnerStage = 0 + this.attackWaitTime = this.normalAttackDelay + // this.prepareMoving() + this.stage++ + } + /* single shoots stage */ + stage1() { + this.move() + + if (!this.attackWaitTime) { + if (!this.attacksUntilNextStage) { + this.stage++ + this.attacksUntilNextStage = 4 + } else { + this.normalAttack() + this.attackWaitTime = this.normalAttackDelay + this.attacksUntilNextStage-- + } + } + + this.attackWaitTime-- + + } + + innerStage = 0 + timeUntilNextInnerStage = 0 + + /* laser stage */ + stage2() { + switch (this.innerStage) { + case 0: /*(preparation)*/ + this.laserAttackDelay = 120 + this.attackWaitTime = this.laserAttackDelay + 100 + + this.timeUntilNextInnerStage = 120 + this.innerStage++ + case 1: /*(chasing player)*/ + this.moveToPlayer() + this.timeUntilNextInnerStage-- + if (!this.timeUntilNextInnerStage) { + this.timeUntilNextInnerStage = 100 + this.innerStage++ + this.laserAttack(true) + } + return + case 2: /*(first laser shot, waiting)*/ + this.timeUntilNextInnerStage-- + if (!this.timeUntilNextInnerStage) { + this.prepareMoving() + this.innerStage++ + } + return + } + + /* post-preparation behaviour */ + this.move() + if (!this.attackWaitTime) { + if (!this.attacksUntilNextStage) { + this.stage = 0 + this.attacksUntilNextStage = 6 + } else { + this.laserAttack() + + this.attackWaitTime = this.laserAttackDelay + this.laserAttackDelay -= 20 + this.attacksUntilNextStage-- + } + } + this.attackWaitTime-- + } + + + speed = 9 + acceleration = 0.2 + + prepareMoving() { + this.position.x = Engine.screen.viewport.x / 2 + this.speed = 9 + } + + move() { + this.position.x += this.speed + if (this.position.x > 325) this.speed -= this.acceleration + else this.speed += this.acceleration + } + + moveToPlayer() { + let distance = Math.floor(this.position.x - boshy.position.x) + + switch (true) { + case (distance < 10 && distance > -10): this.speed = 0; break + case (distance < -50): this.speed = 10; break + case (distance < -20): this.speed = 5; break + case (distance < 0): this.speed = 2; break + case (distance > 50): this.speed = -10; break + case (distance > 20): this.speed = -5; break + case (distance > 0): this.speed = -2; break + } + this.position.x += this.speed + } + + normalAttack() { + let angleToPlayer = this.getBulletAngleToPlayer() + let bulletCenter = this.position.clone() + bulletCenter.y += this.bulletMarginY + new Bullet({ + position: bulletCenter.clone(), + speed: 10, + degrees: angleToPlayer + Engine.random(-10, 10), + }) + + Engine.screen.shake() + } + + laserAttack(delayed = false) { + new Laser(boshy.position.x, delayed) + } + + getBulletAngleToPlayer() { + let v1 = this.position.clone() + v1.y += this.bulletMarginY + + let v2 = boshy.position + let diff = Vector.substraction(v2, v1) + return Math.floor(diff.toDeg()) + } + hit() { this.hp-- if (!this.justGotHit) Engine.radio.playSound(HELLO_KITTY.HIT_SOUND) 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, + }) + } + } +} diff --git a/src/entities/hello_kitty_background.js b/src/entities/hello_kitty_background.js index 0ff405b..658f3a3 100644 --- a/src/entities/hello_kitty_background.js +++ b/src/entities/hello_kitty_background.js @@ -3,8 +3,8 @@ import { BACKGROUND } from "../assets.js" import { Entity } from "../entities/entity.js" import { Engine } from "../engine.js" -// i am aware this code is a mess -// but i don't have enough time to clean it up +// this is the single worst code in the game +// i'm sorry to whoever is reading this export class HelloKittyBackground extends Entity { speed = 20 @@ -12,7 +12,7 @@ export class HelloKittyBackground extends Entity { constructor(position = null) { let first = (position == null) let size = new Vector(1300, 2080) - let x_margin = 0 + let x_margin = 20 if (position == null) position = new Vector( size.x / 2 + Engine.screen.viewport / 2 - x_margin, - (size.y / 2) + Engine.screen.viewport.y, @@ -23,7 +23,8 @@ export class HelloKittyBackground extends Entity { sprite: BACKGROUND.KITTY, }) this.span.style.zIndex = -3 - this.max_down = (this.size.y / 2) + this.maxDownBeforeSpawningNew = (this.size.y / 2) + this.maxDown = this.size.y / 2 + Engine.screen.viewport.y this.x_margin = x_margin this.stage = first ? 0 : 1 } @@ -31,8 +32,8 @@ export class HelloKittyBackground extends Entity { update() { this.position.y += this.speed if (this.stage == 0) { - if (this.position.y < this.max_down) return - let margin = this.position.y - this.max_down + if (this.position.y < this.maxDownBeforeSpawningNew) return + let margin = this.position.y - this.maxDownBeforeSpawningNew let newPos = new Vector( this.size.x / 2 - this.x_margin, - (this.size.y / 2) + margin @@ -42,9 +43,8 @@ export class HelloKittyBackground extends Entity { this.stage++ return } - if ( - this.position.y > 0 && - Engine.screen.isOffLimits(this.position, this.size) - ) this.position.y -= this.size.y * 2 + if (this.position.y >= this.maxDown) { + this.position.y -= this.size.y * 2 + } } } diff --git a/src/entities/hp_bar.js b/src/entities/hp_bar.js index d6e68bb..a5e5f50 100644 --- a/src/entities/hp_bar.js +++ b/src/entities/hp_bar.js @@ -14,6 +14,7 @@ export class HPBar extends Entity { pixelated: true, }) + this.span.style.zIndex = 1 this.lasthp = enemy.hp } |