forked from amandahogan/boogie-water
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boulders.js
47 lines (41 loc) · 1.04 KB
/
boulders.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
let boulder
module.exports = {
create,
update,
getBoulder,
getOtherBoulder
}
function create (game) {
boulder = game.add.sprite(500, 500, 'boulder1')
boulder.scale.setTo(3, 3)
boulder.animations.add('rock', [0, 1], 5, true)
boulder.animations.play('rock')
game.physics.arcade.enable(boulder)
boulder.body.velocity.y = -190
boulder.body.immovable = true
boulder.body.setSize(40, 20)
boulder2 = game.add.sprite(800, 1200, 'boulder2')
boulder2.scale.setTo(3, 3)
boulder2.animations.add('rock', [0, 1], 5, true)
boulder2.animations.play('rock')
game.physics.arcade.enable(boulder2)
boulder2.body.velocity.y = -190
boulder2.body.immovable = true
boulder2.body.setSize(40, 20)
}
function update (game) {
if(boulder.y <= -200) {
boulder.x = 400+(Math.random()*600)
boulder.y = 1000+(Math.random()*500)
}
if(boulder2.y <= -200) {
boulder2.x = 400+(Math.random()*600)
boulder2.y = 1000+(Math.random()*500)
}
}
function getBoulder() {
return boulder
}
function getOtherBoulder() {
return boulder2
}