blob: 0ff405b2628879969c6350ba9e8e70c4fbf913f2 (
plain)
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
|
import { Vector } from "../engine/vector.js"
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
export class HelloKittyBackground extends Entity {
speed = 20
constructor(position = null) {
let first = (position == null)
let size = new Vector(1300, 2080)
let x_margin = 0
if (position == null) position = new Vector(
size.x / 2 + Engine.screen.viewport / 2 - x_margin,
- (size.y / 2) + Engine.screen.viewport.y,
)
super({
size: size,
position: position,
sprite: BACKGROUND.KITTY,
})
this.span.style.zIndex = -3
this.max_down = (this.size.y / 2)
this.x_margin = x_margin
this.stage = first ? 0 : 1
}
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
let newPos = new Vector(
this.size.x / 2 - this.x_margin,
- (this.size.y / 2) + margin
)
new HelloKittyBackground(newPos)
this.stage++
return
}
if (
this.position.y > 0 &&
Engine.screen.isOffLimits(this.position, this.size)
) this.position.y -= this.size.y * 2
}
}
|