From 0696b94962a0571fad54844f137dca025df4563b Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Fri, 27 Dec 2024 18:30:10 +0100 Subject: game finished, only assets left --- src/entities/hello_kitty/bullet.js | 12 ++--- src/entities/hello_kitty/falling_kitten.js | 59 ++++++++++++++++++++++ src/entities/hello_kitty/laser.js | 7 +-- src/entities/hello_kitty/walking_kitten.js | 80 ++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 src/entities/hello_kitty/falling_kitten.js create mode 100644 src/entities/hello_kitty/walking_kitten.js (limited to 'src/entities/hello_kitty') diff --git a/src/entities/hello_kitty/bullet.js b/src/entities/hello_kitty/bullet.js index 1caeb7c..80ad2dd 100644 --- a/src/entities/hello_kitty/bullet.js +++ b/src/entities/hello_kitty/bullet.js @@ -1,8 +1,6 @@ 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 { @@ -23,7 +21,7 @@ export class Bullet extends Entity { this.spinning = spinning this.velocity = Vector.fromDeg(degrees) this.velocity.multiply(speed) - this.velocity.floor() + // this.velocity.floor() this.gravity = gravity @@ -48,11 +46,7 @@ export class Bullet extends Entity { 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() - } + this.updateAsHazard() + this.checkBounds() } } diff --git a/src/entities/hello_kitty/falling_kitten.js b/src/entities/hello_kitty/falling_kitten.js new file mode 100644 index 0000000..2404183 --- /dev/null +++ b/src/entities/hello_kitty/falling_kitten.js @@ -0,0 +1,59 @@ +import { HELLO_KITTY } from "../../assets.js" +import { Vector } from "../../engine/vector.js" +import { Engine } from "../../engine.js" +import { Entity } from "../entity.js" + +export class FallingKitten extends Entity { + constructor() { + let direction = Engine.random(0, 1) + super({ + size: new Vector(40, 40), + hitbox: new Vector(20, 40), + position: new Vector(Engine.random(0 + 22, Engine.screen.viewport.x - 22), 0), + sprite: HELLO_KITTY.SMALL[0], + pixelated: true, + }) + + this.velocity = new Vector(direction ? 1 : -1, 2) + + this.pointRightDirection() + this.maxBottomPosition = Engine.screen.viewport.y + this.size.y / 2 + } + + update() { + this.position.add(this.velocity) + if ( + this.position.x - this.size.x / 2 < 0 || + this.position.x > Engine.screen.viewport.x - this.size.x / 2 + ) { + this.velocity.x *= -1 + this.pointRightDirection() + } + + if (this.position.y > this.maxBottomPosition) this.remove() + this.updateAsHazard() + } + + + delayBetweenFrames = 20 + timeUntilNextFrame = this.delayBetweenFrames + frameAlternator = false + + draw() { + if (!this.timeUntilNextFrame) { + this.timeUntilNextFrame = this.delayBetweenFrames + this.span.src = this.frameAlternator ? + HELLO_KITTY.SMALL[0] : + HELLO_KITTY.SMALL[1] + this.frameAlternator = !this.frameAlternator + } + this.timeUntilNextFrame-- + + super.draw() + } + + pointRightDirection() { + if (this.velocity.x > 0) this.span.style.transform = "scaleX(-1)" + else this.span.style.transform = "scaleX(1)" + } +} diff --git a/src/entities/hello_kitty/laser.js b/src/entities/hello_kitty/laser.js index b8e480d..8cf576a 100644 --- a/src/entities/hello_kitty/laser.js +++ b/src/entities/hello_kitty/laser.js @@ -2,7 +2,6 @@ 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 { @@ -34,7 +33,7 @@ export class Laser extends Entity { if (!this.loadingTimeLeft) { this.attacking = true this.size.x = 100 - Engine.radio.playSound(HELLO_KITTY.LASER_SOUND) + Engine.radio.playSound(HELLO_KITTY.SOUNDS.LASER) Engine.screen.shake() this.spawnBullets() } @@ -45,9 +44,7 @@ export class Laser extends Entity { 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() - } + this.updateAsHazard() return } diff --git a/src/entities/hello_kitty/walking_kitten.js b/src/entities/hello_kitty/walking_kitten.js new file mode 100644 index 0000000..b027622 --- /dev/null +++ b/src/entities/hello_kitty/walking_kitten.js @@ -0,0 +1,80 @@ +import { HELLO_KITTY } from "../../assets.js" +import { Vector } from "../../engine/vector.js" +import { Engine } from "../../engine.js" +import { Entity } from "../entity.js" + +export class WalkingKitten extends Entity { + constructor() { + let direction = Engine.random(0, 1) + super({ + size: new Vector(40, 40), + hitbox: new Vector(20, 40), + position: new Vector(direction ? 0 : Engine.screen.viewport.x, Engine.screen.viewport.y - 20), + sprite: HELLO_KITTY.SMALL[0], + pixelated: true, + }) + + this.velocity = new Vector(direction ? 1 : -1, 0) + if (direction) this.span.style.transform = "scaleX(-1)" + this.bottomPosition = Engine.screen.viewport.y - 20 + } + + update() { + this.updateJump() + this.position.add(this.velocity) + this.checkBounds() + this.updateAsHazard() + } + + jumping = true + timeUntilNextJump = 0 + gravity = 0.1 + + updateJump() { + if (this.jumping) { + if (this.position.y >= this.bottomPosition) { + this.velocity.y = 0 + this.velocity.x *= 3 + this.position.y = this.bottomPosition + this.jumping = false + this.timeUntilNextJump = Engine.random(-30, 300) + return + } + this.velocity.y += this.gravity + return + } + + this.timeUntilNextJump-- + if (!this.timeUntilNextJump) { + this.velocity.x /= 3 + this.velocity.y = -7 + this.jumping = true + } + } + + delayBetweenFrames = 20 + timeUntilNextFrame = this.delayBetweenFrames + frameAlternator = false + + draw() { + if (!this.timeUntilNextFrame) { + this.timeUntilNextFrame = this.delayBetweenFrames + this.span.src = this.frameAlternator ? + HELLO_KITTY.SMALL[0] : + HELLO_KITTY.SMALL[1] + this.frameAlternator = !this.frameAlternator + } + this.timeUntilNextFrame-- + + super.draw() + } + + checkBounds() { + if ( + this.position.x + this.size.x / 2 < 0 || + this.position.x - this.size.x / 2 > Engine.screen.viewport.x + ) { + this.remove() + } + } +} -- cgit v1.2.3