-
Notifications
You must be signed in to change notification settings - Fork 1
/
sutoringu.js
66 lines (57 loc) · 1.92 KB
/
sutoringu.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
/**
* Created by Damian Terlecki on 15.04.17.
*/
"use strict";
let Sutoringu = function () {
const width = 800;
const height = 600;
const uiHeight = 100;
this.game = new Phaser.Game(width, height, Phaser.AUTO, 'game', false, false);
this.game._uiHeight = uiHeight;
this.game._width = width;
this.game._height = height;
};
let jsonp = (function () {
let call = {};
call.send = function (src, options) {
let callback_name = options.callbackName || 'callback',
on_success = options.onSuccess || function () {
},
on_timeout = options.onTimeout || function () {
},
timeout = options.timeout || 30;
let timeoutTrigger = window.setTimeout(function () {
window[callback_name] = function () {
};
on_timeout.call(options.context);
}, timeout * 1000);
window[callback_name] = function (data) {
window.clearTimeout(timeoutTrigger);
if (data.result === 'success') {
on_success.call(options.context, data);
} else {
on_timeout.call(options.context);
}
};
let script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = src;
document.getElementsByTagName('head')[0].appendChild(script);
};
return call;
})();
Sutoringu.prototype = {
start: function () {
this.game.state.add('Boot', Sutoringu.Boot);
this.game.state.add('Menu', Sutoringu.Menu);
this.game.state.add('AdvancedMenu', Sutoringu.AdvancedMenu);
this.game.state.add('Preload', Sutoringu.Preload);
this.game.state.add('Play', Sutoringu.Play);
this.game.state.add('GameOver', Sutoringu.GameOver);
this.game.state.start('Boot');
},
};
window.onload = function () {
new Sutoringu().start();
};