summaryrefslogtreecommitdiff
path: root/src/entities/hello_kitty.js
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-27 18:30:10 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-27 18:30:10 +0100
commit0696b94962a0571fad54844f137dca025df4563b (patch)
tree8aeff72e8fc46a7dab2b2f556febd962e3f67e4b /src/entities/hello_kitty.js
parent474a7253b6b67e2ed33936f6b633587d5d304b66 (diff)
game finished, only assets left
Diffstat (limited to 'src/entities/hello_kitty.js')
-rw-r--r--src/entities/hello_kitty.js268
1 files changed, 236 insertions, 32 deletions
diff --git a/src/entities/hello_kitty.js b/src/entities/hello_kitty.js
index 65fa30b..a7d5f68 100644
--- a/src/entities/hello_kitty.js
+++ b/src/entities/hello_kitty.js
@@ -5,14 +5,16 @@ 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"
+import { WalkingKitten } from "./hello_kitty/walking_kitten.js"
+import { FallingKitten } from "./hello_kitty/falling_kitten.js"
+import { Blood } from "./boshyblood.js"
export class HelloKitty extends Entity {
- max_hp = 300
+ max_hp = 200
hp = this.max_hp
- moveInterval = 26
+ alive = true
- previous = 0
- stage = 1
+ stage = 0
justGotHit = false
turningRight = false
@@ -30,23 +32,29 @@ export class HelloKitty extends Entity {
this.span.style.zIndex = 1
setEnemy(this)
+ this.nextStage()
}
update() {
+ if (!this.alive) {
+ this.deathAnimation()
+ return
+ }
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()
+ case 2: this.stage2Lasers(); break
+ case 3: this.stage3Kittens(); break
+ case 4: this.stage4Touhou(); break
+ default: this.nextStage()
}
+ this.updateAsHazard()
}
delayBetweenFrames = 10
timeUntilNextFrame = this.delayBetweenFrames
frameAlternator = false
draw() {
+ if (!this.alive) { super.draw(); return }
/* hit effect */
if (this.justGotHit) {
this.span.style.filter = "brightness(500%)"
@@ -78,32 +86,51 @@ export class HelloKitty extends Entity {
super.draw()
}
- attacksUntilNextStage = 6
normalAttackDelay = 100
attackWaitTime = this.normalAttackDelay
- stage0() {
- this.innerStage = 0
- this.timeUntilNextInnerStage = 0
- this.attackWaitTime = this.normalAttackDelay
- // this.prepareMoving()
+ nextStage() {
this.stage++
+
+ switch (this.stage) {
+ case 1:
+ this.attacksUntilNextStage = 6
+ this.attackWaitTime = this.normalAttackDelay
+ this.prepareMoving()
+ break
+ case 2:
+ this.innerStage = 0
+ this.timeUntilNextInnerStage = 0
+ this.attacksUntilNextStage = 4
+ break
+ case 3:
+ this.attacksUntilNextStage = 12
+ break
+ case 4:
+ this.innerStage = 0
+ this.timeUntilNextInnerStage = 120
+ break
+ default:
+ this.stage = 0
+ this.nextStage()
+ }
}
+
/* 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.nextStage()
+ return
}
- }
+ this.normalAttack()
+ this.attackWaitTime = this.normalAttackDelay
+ this.attacksUntilNextStage--
+
+ }
this.attackWaitTime--
}
@@ -112,7 +139,7 @@ export class HelloKitty extends Entity {
timeUntilNextInnerStage = 0
/* laser stage */
- stage2() {
+ stage2Lasers() {
switch (this.innerStage) {
case 0: /*(preparation)*/
this.laserAttackDelay = 120
@@ -142,19 +169,105 @@ export class HelloKitty extends Entity {
this.move()
if (!this.attackWaitTime) {
if (!this.attacksUntilNextStage) {
- this.stage = 0
- this.attacksUntilNextStage = 6
- } else {
- this.laserAttack()
+ this.nextStage()
+ return
+ }
+
+ this.laserAttack()
+
+ this.attackWaitTime = this.laserAttackDelay
+ this.laserAttackDelay -= 30
+ this.attacksUntilNextStage--
+ }
+ this.attackWaitTime--
+ }
+
+ kittenAttackDelay = 40
+ stage3Kittens() {
+ this.move()
- this.attackWaitTime = this.laserAttackDelay
- this.laserAttackDelay -= 20
- this.attacksUntilNextStage--
+ if (!this.attackWaitTime) {
+ if (!this.attacksUntilNextStage) {
+ this.nextStage()
+ return
}
+ this.kittenAttack()
+ this.attackWaitTime = this.kittenAttackDelay
+ this.attacksUntilNextStage--
}
this.attackWaitTime--
}
+ /* bullets!!! */
+ stage4Touhou() {
+ switch (this.innerStage) {
+ case 0: /*(still moving)*/
+ this.move()
+
+ this.timeUntilNextInnerStage--
+ if (!this.timeUntilNextInnerStage) {
+ this.innerStage++
+ this.timeUntilNextInnerStage = 30
+ }
+ return
+
+ case 1: /*(go to center)*/
+ this.moveToCenter()
+ this.timeUntilNextInnerStage--
+ if (!this.timeUntilNextInnerStage) {
+ this.position.x = 325 /*(center of the screen)*/
+ this.innerStage++
+ this.attacksUntilNextInnerStage = 5
+ this.attackReload = 40
+ this.attackWaitTime = 20
+ }
+ return
+
+ case 2: /*(circle attacks)*/
+ this.attackWaitTime--
+ if (this.attackWaitTime > 0) return
+
+ this.circleAttack()
+ this.attackWaitTime = this.attackReload
+
+ this.attacksUntilNextInnerStage--
+ if (!this.attacksUntilNextInnerStage) {
+ this.innerStage++
+ this.attacksUntilNextInnerStage = 8
+ this.attackReload = 30
+ this.extraAttackReload = 10
+ this.isNextAttackNormal = true
+ }
+ return
+
+ case 3: /*(circle attacks + kaboom)*/
+ this.attackWaitTime--
+ if (this.attackWaitTime > 0) return
+
+ if (this.isNextAttackNormal) {
+ this.circleAttack()
+ this.attackWaitTime = this.extraAttackReload
+ } else {
+ this.circleAttackFaster()
+ this.attackWaitTime = this.attackReload
+ }
+ this.isNextAttackNormal = !this.isNextAttackNormal
+
+ this.attacksUntilNextInnerStage--
+ if (!this.attacksUntilNextInnerStage) {
+ this.innerStage++
+ this.attacksUntilNextInnerStage = 6
+ this.attackReload = 30
+ this.extraAttackReload = 10
+ }
+ return
+
+ default:
+ this.nextStage()
+ return
+ }
+ }
+
speed = 9
acceleration = 0.2
@@ -164,6 +277,7 @@ export class HelloKitty extends Entity {
this.speed = 9
}
+ moveInterval = 26
move() {
this.position.x += this.speed
if (this.position.x > 325) this.speed -= this.acceleration
@@ -185,6 +299,21 @@ export class HelloKitty extends Entity {
this.position.x += this.speed
}
+ moveToCenter() {
+ let distance = this.position.x - 325 /*(viewport.y / 2)*/
+ if (distance < 2 && distance > -2) return
+
+ switch (true) {
+ 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()
@@ -197,11 +326,55 @@ export class HelloKitty extends Entity {
Engine.screen.shake()
}
-
+
laserAttack(delayed = false) {
new Laser(boshy.position.x, delayed)
}
+ kittenAttack() {
+ new WalkingKitten()
+ new FallingKitten()
+ }
+
+ circleAttack() {
+ let bulletCenter = this.position.clone()
+ bulletCenter.y += this.bulletMarginY
+ let bullets = 10
+ let interval = 360 / bullets
+ let initialAngle = this.getBulletAngleToPlayer()
+
+ for (let i = 0; i < bullets; i++) {
+ new Bullet({
+ position: bulletCenter.clone(),
+ speed: 3,
+ degrees: initialAngle + interval * i,
+ spinning: true,
+ })
+ }
+
+ Engine.radio.playSound(HELLO_KITTY.SOUNDS.SHOOT)
+ }
+
+ circleAttackFaster() {
+ let bulletCenter = this.position.clone()
+ bulletCenter.y += this.bulletMarginY
+ let bullets = 12
+ let interval = 360 / bullets
+ let initialAngle = Engine.random(0, 360)
+
+ for (let i = 0; i < bullets; i++) {
+ new Bullet({
+ position: bulletCenter.clone(),
+ speed: 7,
+ degrees: initialAngle + interval * i,
+ spinning: true,
+ })
+ }
+
+ Engine.radio.playSound(HELLO_KITTY.SOUNDS.SHOOT_LOUD)
+ Engine.screen.shake()
+ }
+
getBulletAngleToPlayer() {
let v1 = this.position.clone()
v1.y += this.bulletMarginY
@@ -212,8 +385,39 @@ export class HelloKitty extends Entity {
}
hit() {
+ if (!this.alive) return
+
this.hp--
- if (!this.justGotHit) Engine.radio.playSound(HELLO_KITTY.HIT_SOUND)
+
+ if (this.hp == 0) { this.die(); return }
+
+ if (!this.justGotHit) Engine.radio.playSound(HELLO_KITTY.SOUNDS.HIT)
this.justGotHit = true
}
+
+ async die() {
+ this.alive = false
+ Engine.radio.stopMusic()
+ await Engine.radio.playSoundUntilEnd(HELLO_KITTY.SOUNDS.DEATH)
+ this.explode()
+ }
+
+ deathAnimationDelay = 60
+ deathAnimation() {
+ if (this.deathAnimationDelay) {
+ this.deathAnimationDelay--
+ return
+ }
+
+ this.size.x += 1
+ }
+
+ async explode() {
+ for (let i = 0; i < 40; i++) {
+ new Blood(this.position.clone())
+ }
+ this.remove()
+ await Engine.radio.playSoundUntilEnd(HELLO_KITTY.SOUNDS.BLOOD_RIP)
+ Engine.radio.playSound(HELLO_KITTY.SOUNDS.WIN)
+ }
}