summaryrefslogtreecommitdiff
path: root/src/entities/hello_kitty.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/hello_kitty.js')
-rw-r--r--src/entities/hello_kitty.js186
1 files changed, 165 insertions, 21 deletions
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)