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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
import { Vector } from "../engine/vector.js"
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 = 300
hp = this.max_hp
moveInterval = 26
previous = 0
stage = 1
justGotHit = false
turningRight = false
bulletMarginY = 40
constructor() {
super({
size: new Vector(200, 200),
hitbox: new Vector(100, 200),
position: new Vector(325, 140),
sprite: HELLO_KITTY.MAIN[0],
pixelated: true,
})
this.span.style.zIndex = 1
setEnemy(this)
}
update() {
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()
}
}
delayBetweenFrames = 10
timeUntilNextFrame = this.delayBetweenFrames
frameAlternator = false
draw() {
/* hit effect */
if (this.justGotHit) {
this.span.style.filter = "brightness(500%)"
this.justGotHit = false
} else {
this.span.style.filter = "brightness(100%)"
}
if (this.speed > 0) this.span.style.transform = "scaleX(-1)"
else if (this.speed < 0) this.span.style.transform = "scaleX(1)"
/* frame */
/* 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)
this.justGotHit = true
}
}
|