/
app.js
118 lines (102 loc) · 3.47 KB
/
app.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// For any third party dependencies, like jQuery, place them in the lib folder.
// Configure loading modules from the lib directory,
// except for 'app' ones, which are in a sibling
// directory.
requirejs.config({
baseUrl: 'js/lib',
paths: {
// Phaser does not fully support require js by default, so
// we need to explicitly add it to the config
Phaser: 'phaser',
// All application files can be required with 'app/<name>'
app: '../app'
},
shim: {
'fancybox': ['jquery'],
'app/shaders/Time': ['Phaser'],
'app/shaders/Frequency': ['Phaser'],
}
});
// Load and start the game
requirejs(['app/game', 'jquery', 'fancybox'],
function(game, $, fancybox) {
requirejs(['app/config', 'app/grid', 'app/generator', 'app/score',
'app/timer', 'app/background'],
function(config, grid, generator, score, timer, background) {
$('#start-button').click(function(){
grid.display(game);
generator.start(game);
score.init(game, grid, generator);
timer.init(game);
$('#start-menu').fadeOut();
$('#pause-menu').data("available", "true");
$(this).off('click');
});
$(window).resize(function(){
var height = $(window).height();
var width = $(window).width();
game.width = width;
game.height = height;
config.game.width = game.width;
config.game.height = game.height;
if (game.renderType === Phaser.WEBGL) {
game.renderer.autoResize = false;
game.renderer.resize(width, height);
}
grid.resize(game);
timer.resize();
generator.resize();
background.resize();
});
var pause = function(){
game.paused = true;
$('#menu-cover').fadeIn(500, function() {
$('#pause-menu').fadeIn(500);
});
};
var unpause = function(){
game.paused = false;
$('#pause-menu').fadeOut(500, function() {
$('#menu-cover').fadeOut(500);
});
};
$('#pause-resume').click(function(){
unpause();
});
// Preload the first tutorial, but after the page is done
$("#tutorial>video")[0].load();
$("#how-button").click(function(){
var vids = $("#tutorial>.tutorial-item");
// User will probably continue through the tutorial, so
// preload the rest of them.
vids.map(function(_, elem){
if (elem.load !== undefined && elem.readyState !== 4)
elem.load();
});
$.fancybox(vids, {
beforeShow : function() {
var e = this.element[0];
if (e.play !== undefined)
e.play();
},
loop: false,
helpers : {
title : {
type : 'inside'
}
}
});
});
window.onkeyup = function(e){
if(String.fromCharCode(e.which) == 'P'
&& $('#pause-menu').data("available") == "true")
{
if(game.paused == false){
pause();
} else{
unpause();
}
};
};
});
});