-
Notifications
You must be signed in to change notification settings - Fork 1
/
fireworks.js
138 lines (111 loc) · 3.48 KB
/
fireworks.js
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
/// <reference path="../../bas/jonny-maps/scripts/index.d.ts" />
const overlayLayerName = "fireworks-layer"
class FireWork {
static shootingStar = 16;
static explosions = [0, 4, 8]
eventPhase = 0
/**
* @type {Parameters<typeof WA.room.setTiles>[0]}
*/
setTiles = []
shootUpOffset = 0
constructor(x, y, tilesetstart, tilesetWidth) {
this.startPosition = {
x, y
}
this.tilesetWidth = tilesetWidth
this.tilesetstart = tilesetstart
this.explosionColored = FireWork.explosions[(Math.floor(Math.random() * FireWork.explosions.length))]
this.shoot()
}
async shoot() {
this.unset()
this.set([
{
layer: overlayLayerName,
tile: this.tilesetstart + FireWork.shootingStar,
x: this.startPosition.x,
y: this.startPosition.y - this.shootUpOffset
}, {
layer: overlayLayerName,
tile: this.tilesetstart + FireWork.shootingStar + this.tilesetWidth,
x: this.startPosition.x,
y: this.startPosition.y + 1 - this.shootUpOffset++
}
])
if(this.shootUpOffset >= 5) {
setTimeout(() => {
this.unset()
this.explode();
}, 50)
return
}
setTimeout(() => {
this.shoot()
}, 100)
}
explode() {
const topLeft = {
x: this.startPosition.x - 1,
y: this.startPosition.y - this.shootUpOffset - 1
}
/**
* @type {Parameters<typeof WA.room.setTiles>[0]}
*/
const tiles = []
for(let x = 0; x < 4; x++) {
for(let y = 0; y < 3; y++) {
tiles.push({
layer: overlayLayerName,
tile: (this.tilesetstart) + this.explosionColored + x + (y * this.tilesetWidth),
x: topLeft.x + x,
y: topLeft.y + y
})
}
}
this.set(tiles)
setTimeout(() => {
this.unset()
}, 1000)
}
/**
*
* @param {Parameters<typeof WA.room.setTiles>[0]} tiles
*/
set(tiles) {
this.setTiles.push(...tiles)
WA.room.setTiles(tiles)
}
unset() {
WA.room.setTiles(this.setTiles.map(tile => ({ ...tile, tile: 0 })))
this.setTiles = []
}
}
Promise.all([WA.room.getTiledMap(), WA.onInit()]).then(([map]) => {
const tileset = map.tilesets.find(ts => ts.name == "fireworks")
let firworks = []
/**
* @type {{x:number,y:number}}
*/
let currentPosition
WA.player.onPlayerMove(pos => {
currentPosition = pos
})
setInterval(() => {
const now = new Date()
const isEvening = Math.abs(24 - now.getHours()) < 4
if(isEvening && currentPosition) {
for(let i = 0; i < 5; i++) {
const chunk = 24
const x = (Math.random() * chunk) - (chunk / 2)
const y = (Math.random() * chunk) - (chunk / 2)
const player = {
x: (currentPosition.x / 32),
y: (currentPosition.y / 32)
}
firworks.push(new FireWork(Math.floor(player.x + x), Math.floor(player.y + y), tileset.firstgid, tileset.columns))
}
}
firworks = firworks.filter(f => f.eventPhase < 2)
}, 500)
})