5186f0a6
Geoffrey PREUD'HOMME
Best score
|
1
2
3
4
5
6
7
8
9
|
$.fn.extend({
animateCss: function (animationName) {
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
$(this).addClass('animated ' + animationName).one(animationEnd, function() {
$(this).removeClass('animated ' + animationName);
});
}
});
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
10
11
12
|
$(function() {
var socket = io();
var scores = [];
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
13
|
var list = $('#scores ol');
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
14
15
|
socket.emit('getScores');
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
16
|
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
17
18
19
20
21
|
socket.on('scores', function(newScores) {
scores = newScores;
redrawScores();
});
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
22
23
24
25
26
27
28
29
|
socket.on('newScore', function addScore(obj) {
scores.push(obj);
redrawScores();
});
socket.on('msg', function(msg) {
$('#sub').text(msg);
});
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
30
|
|
5186f0a6
Geoffrey PREUD'HOMME
Best score
|
31
|
var oldScore = 0;
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
32
33
34
|
var shakeStart = 0;
var SHAKE_DURATION = 10
var SHAKE_MAX_THRESOLD = 100
|
5186f0a6
Geoffrey PREUD'HOMME
Best score
|
35
|
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
36
|
function redrawScores() {
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
37
38
|
var sortable = [];
scores.sort(function(b, a) {return a.score - b.score})
|
ba814e44
Geoffrey PREUD'HOMME
GUI revue
|
39
|
var list = $('#scores ol');
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
40
|
list.empty();
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
41
|
for (i in scores) {
|
cd9681f5
Geoffrey PREUD'HOMME
Ajustement in AW
|
42
|
if (i < 8) {
|
ba814e44
Geoffrey PREUD'HOMME
GUI revue
|
43
44
45
|
var obj = scores[i];
list.append($('<li>').text(obj.score + ' - ' + obj.name));
}
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
46
|
}
|
5186f0a6
Geoffrey PREUD'HOMME
Best score
|
47
48
49
50
51
52
53
|
if (scores[0]) {
$('#bestBlock').css('display', 'block');
$('#bestBlock .score').text(scores[0].score);
$('#bestBlock .name').text(scores[0].name);
if (scores[0].score > oldScore) {
$('#bestBlock').animateCss('rotateIn');
oldScore = scores[0].score;
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
54
|
shakeStart = Date.now()/1000;
|
5186f0a6
Geoffrey PREUD'HOMME
Best score
|
55
56
|
}
}
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
57
58
|
}
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
59
60
61
|
function rainbowColor(el) {
var hue = Math.floor(Math.random()*360);
el.css('filter', 'hue-rotate('+hue+'deg)');
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
62
63
|
}
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
64
65
66
67
68
69
|
var logo = $('#logo');
setInterval(function rainbowLogo() {
rainbowColor(logo);
}, 500);
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
70
71
72
73
|
function shake(thresold) {
var x = Math.round((2*Math.random()-1)*thresold);
var y = Math.round((2*Math.random()-1)*thresold);
$('body').css('transform', 'translate('+x+'px, '+y+'px)');
|
893c4e9a
Geoffrey PREUD'HOMME
Stars
|
74
75
76
77
|
}
var h = $('#stars').height();
var w = $('#stars').width();
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
78
|
|
893c4e9a
Geoffrey PREUD'HOMME
Stars
|
79
80
|
for (var i = 0; i < 10; i++) {
$('#stars').append($('<img>').attr('src', 'graphics/star.png').css('top', (Math.random() * h) + 'px'))
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
81
82
|
}
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
83
84
85
86
87
88
89
|
(function anim() {
var now = Date.now()/1000;
// Logo
var scale = (Math.sin(now*5) + 1)/5 + 0.7;
var rot = Math.sin(now*10)/10;
logo.css('transform', 'rotate(' + rot + 'rad) scale(' + scale + ')');
|
5186f0a6
Geoffrey PREUD'HOMME
Best score
|
90
|
rainbowColor($('#bestBlock .score'));
|
48449675
Geoffrey PREUD'HOMME
Améliorations
|
91
92
93
94
95
96
|
// Shake
if (now - shakeStart < SHAKE_DURATION) {
shake(Math.exp(10 * (shakeStart - now) / SHAKE_DURATION) * SHAKE_MAX_THRESOLD)
}
|
893c4e9a
Geoffrey PREUD'HOMME
Stars
|
97
98
99
100
|
// Stars
$('#stars img').each(function(i, el) {
var e = $(el);
var pos = e.position()
|
12ff9794
Geoffrey PREUD'HOMME
En fait les étoil...
|
101
102
|
if (pos.top < 0) {
e.css('top', h + 'px');
|
893c4e9a
Geoffrey PREUD'HOMME
Stars
|
103
104
|
e.css('left', Math.floor(Math.random() * w) + 'px');
} else {
|
12ff9794
Geoffrey PREUD'HOMME
En fait les étoil...
|
105
|
e.css('top', (pos.top - 100) + 'px');
|
893c4e9a
Geoffrey PREUD'HOMME
Stars
|
106
107
108
|
}
});
|
e704c732
Geoffrey PREUD'HOMME
Avancement web
|
109
110
111
112
113
|
requestAnimationFrame(anim);
})();
|
ea5a9738
Geoffrey PREUD'HOMME
Scoreboard : coté...
|
114
|
});
|