-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
86 lines (73 loc) · 2.47 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
var Game = function Game() {
var bgCanvas, spriteCanvas, bgContext, spriteContext, menuCanvas, menuContext;
var stage = new Stage();
//var overworld = new OverWorld();
var currentScene;
//var cursor = new Cursor();
var SCREENRATIO = .85;
this.init = function() {
//this.bgCanvas = document.getElementById('background');
this.spriteCanvas = document.getElementById('sprite');
width = this.spriteCanvas.width;
height = this.spriteCanvas.height;
window.addEventListener("keydown", function(evt) { currentScene.keydown(evt); }, false);
this.spriteCanvas.addEventListener("mousedown", function(evt) {
evt.preventDefault();
currentScene.mousedown(evt);
}, false);
this.spriteCanvas.addEventListener("mouseup", function(evt) {
evt.preventDefault();
currentScene.mouseup(evt);
}, false);
this.spriteCanvas.addEventListener("moustout", function(evt) {
evt.preventDefault();
currentScene.mouseout(evt);
}, false);
this.spriteCanvas.addEventListener("mousemove", function(evt) {
evt.preventDefault();
currentScene.mousemove(evt);
}, false);
this.spriteCanvas.addEventListener("touchstart", function(evt) {
evt.preventDefault();
currentScene.touchstart(evt);
}, false);
this.spriteCanvas.addEventListener("touchend", function(evt) {
evt.preventDefault();
currentScene.touchend(evt);
}, false);
this.spriteCanvas.addEventListener("touchcancel", function(evt) {
evt.preventDefault();
currentScene.touchcancel(evt);
}, false);
this.spriteCanvas.addEventListener("touchmove", function(evt) {
evt.preventDefault();
currentScene.touchmove(evt);
}, false);
this.spriteCanvas.addEventListener("contextmenu", function(evt) { evt.preventDefault(); }, false);
if (this.spriteCanvas.getContext) {
//this.bgContext = this.bgCanvas.getContext('2d');
this.spriteContext = this.spriteCanvas.getContext('2d');
_height = window.innerHeight;
_width = window.innerWidth;//_height*10/16;
this.spriteCanvas.width = _width;
this.spriteCanvas.height = _height;
//this.bgCanvas.width = _width;
//this.bgCanvas.height = _height;
stage.init(_width, _height);
currentScene = stage;
return true;
}
return false;
};
this.draw = function() {
var ctx = this.spriteContext;
currentScene.draw(ctx);
};
this.update = function() {
currentScene.update();
};
// Start the animation loop
this.start = function() {
animate();
};
}