-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoodad.js
69 lines (58 loc) · 1.61 KB
/
doodad.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
import doodads from '../res/sprites/doodads/*.png'
import { GameObjects, Math } from 'phaser'
export class Doodad extends GameObjects.Sprite {
constructor(scene) {
super(scene, 0, 0, 'speed')
scene.add.existing(this)
scene.groups.doodads.add(this)
this.setActive(false)
this.setVisible(false)
this.setDepth(0)
}
kill() {
this.setActive(false)
this.setVisible(false)
}
update(time, delta) {
this.y += this.speed * (delta / 1000)
this.angle += this.rotationSpeed * (delta / 1000)
if (this.y >= 700) {
this.kill()
}
}
spawn(x, y) {
const doodadIndex = Math.Between(0, Object.keys(doodads).length - 1)
this.doodadKey = Object.keys(doodads)[doodadIndex]
this.setAlpha(1)
this.setAngle(0)
this.setPosition(x, y)
this.setScale(1, 1)
this.setTexture(this.doodadKey)
this.setActive(true)
this.setVisible(true)
switch (this.doodadKey) {
case 'meteor1':
case 'meteor2':
case 'meteor3':
case 'meteor4':
this.setAngle(Math.FloatBetween(0, 360))
this.speed = Math.FloatBetween(60, 120)
this.setScale((((this.speed - 60) / 60) * 0.25) + 0.75)
this.rotationSpeed = Math.FloatBetween(-60, 60)
break
case 'star1':
case 'star2':
case 'star3':
this.setAlpha(0.5)
this.setAngle(Math.FloatBetween(0, 360))
this.setScale(0.25)
this.speed = Math.FloatBetween(500, 750)
this.rotationSpeed = 0
break
case 'speed':
this.speed = Math.FloatBetween(400, 500)
this.rotationSpeed = 0
break
}
}
}