-
Notifications
You must be signed in to change notification settings - Fork 8
/
game.js
87 lines (72 loc) · 1.37 KB
/
game.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
o = $;
/**
* Balloons.
*/
o(function(){
move('#balloons')
.delay('2s')
.set('top', -400)
.set('left', 700)
.rotate(50)
.duration('20s')
.end();
});
/**
* Guy.
*/
o(function(){
var head = o('#guy-head')[0]
, balloons = o('#balloons')
, max = Math.max
, min = Math.min;
function lookat(x, y) {
move('#guy-arm-right')
.rotate(max(-(x * .10), -13))
.duration(500)
.end();
move('#guy-arm-left')
.rotate(min(x * .05, 8))
.duration(500)
.end();
move(head)
.rotate(max(-(x * .15), -22))
.duration(500)
.end();
}
setInterval(function(){
var off = balloons.offset();
lookat(off.left|0, off.top|0);
}, 200);
})
/**
* Rain.
*/
o(function(){
var drops = 30
, drop;
while (drops--) {
drop = o('<div class="rain"></div>');
o('body').append(drop);
moveDrop(drop);
}
});
function moveDrop(drop) {
var x = Math.random() * window.innerWidth * 1.5
, y = Math.random() * window.innerHeight * 1.5;
drop.css({ left: x, top: y });
function loop() {
move(drop)
.add('left', 1000)
.add('top', 1000)
.set('opacity', 0)
.duration(Math.random() * 1000 | 0)
.then()
.set('left', x-1000)
.set('top', y-1000)
.set('opacity', 1)
.duration(0)
.pop()
.end(loop);
}
loop();
}