-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
76 lines (66 loc) · 1.33 KB
/
controller.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
Game.Controller =(function(){
var nextGameTick = (new Date).getTime(),
FPS = 60,
MAX_FRAME_SKIP = 5,
SKIP_TICKS = 1000/FPS,
context = config.context,
anime=false,
paused=false,
playing=false,
appView;
return{
initialize: function(){
_.bindAll(this,'animate','render','startAnimation','restart');
appView = new Game.Views.App({ el:document });
},
finshRound: function(){
cancelRequestAnimationFrame(anime);
playing = false;
},
startAnimation: function(){
playing = true;
if(Game.curves.alive() < 2){
console.log('not enough players');
return;
}
$('#start').fadeOut();
document.getElementById('right').style.opacity = 0.2;
this.animate();
},
restart: function(){
playing = true;
appView.restart();
this.startAnimation();
},
animate: function(){
anime = requestAnimationFrame(this.animate);
this.render();
},
updateScores: function(){
appView.updateScores();
},
addPlayer: function(){
appView.addPlayer();
},
render: function(){
appView.update();
},
pause: function(){
if(!playing)
return;
if(anime === false)
{
paused = false;
this.animate();
$('#paused').fadeOut();
}
else
{
cancelRequestAnimationFrame(anime);
anime = false;
paused = true;
$('#paused').fadeIn();
}
}
};
})();