-
Notifications
You must be signed in to change notification settings - Fork 7
/
Game.js
executable file
·94 lines (91 loc) · 2.18 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
88
89
90
91
92
93
94
define(['./jo', './Object', './Screen', './input', './Loader', './Camera'], function(jo, Object, Screen, input, Loader, Cam){
jo.Game = jo.Object.extend({
init: function(options){
this._super(options);
if(!jo.screen){
jo.screen = new jo.Screen(options);
}
input.setup();
input.reserved = [ input.MOUSE1,
input.MOUSE2,
input.UP,
input.DOWN,
input.LEFT,
input.RIGHT,
input.CTRL,
input.ALT,
input.SHIFT,
input.TAB,
input.SPACE,
input.ENTER,
input.WHEEL_UP];
this.freeze = false;
this.cam = new Cam(0,0);
jo.files = new jo.Loader();
},
loading: function(){
jo.screen.clear();
jo.screen.rect({fill: jo.color(33,33,33)} ,
{x: jo.screen.width/4-10, y: jo.screen.height/2 -30},
jo.screen.width/2+20, 60 );
jo.screen.rect({fill: jo.color(200,200,200)},
{x: jo.screen.width/4, y: jo.screen.height/2 -20},
jo.mapto(jo.files.progress, 0, 1, 0, jo.screen.width/2), 40 );
jo.screen.text({align: 'center', fill: jo.clr.white, stroke: 0},
new jo.Point(jo.screen.width/2, jo.screen.height/2), 'Loading...');
if(jo.files.progress >= 1){
jo.screen.draw(jo.bind(this.loop, this));
this._ready();
}
},
setup: function(fn, hold){
this._setup = fn;
if(!hold){
return fn();
}
},
runSetup: function(){
if(typeof this._setup === 'function'){
return this._setup();
}
},
runReady: function(){
if(typeof this._ready === 'function'){
this._ready();
}
this.run();
},
run: function(){
jo.screen.draw(jo.bind(this.loop, this));
},
load: function(files, folder){
jo.files.load(files, folder);
jo.screen.draw(jo.bind(this.loading, this));
},
ready: function(fn){
this._ready = fn;
},
loop: function(){
this.update(jo.screen.ticks);
this.draw();
},
update: function(t){
if(!this.freeze){
this._super(t);
}
jo.input.update();
this._update(t);
},
draw: function(){
this._draw();
this._super({}, jo.pzero, jo.screen);
},
OnUpdate: function(fn){
this._update = fn;
},
OnDraw: function(fn){
this._draw = fn;
}
});
return jo.Game;
});