-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.js
100 lines (100 loc) · 4.69 KB
/
index.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
define(["require", "exports", "./mariogame", "./input_controller", "./fps_controller"], function (require, exports, mariogame_1, input_controller_1, fps_controller_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class MyApp {
constructor() {
this.mobileMode = false;
this.isSixtyFPS = true;
this.useragent = '';
rivets.bind(document.getElementsByTagName('body')[0], { data: this });
this.canvas = document.getElementById('my-canvas');
this.useragent = navigator.userAgent.toLocaleLowerCase();
//mobile device
if ((window.innerWidth < 600 || this.useragent.includes('iphone') ||
this.useragent.includes('ipad') || this.useragent.includes('android'))
&& window.innerWidth < window.innerHeight) {
this.mobileMode = true;
}
if (this.mobileMode) {
document.getElementById('header').style.display = "none";
$("#mobileDiv").show();
$('#my-canvas').width(window.innerWidth);
$('#my-canvas').appendTo("#mobileCanvas");
$("body").css({ "overflow": "hidden" });
this.inputController = new input_controller_1.InputController('divTouchSurface');
document.getElementById('my-canvas').addEventListener('touchstart', function (e) { e.preventDefault(); }, false);
document.getElementById('my-canvas').addEventListener('touchend', function (e) { e.preventDefault(); }, false);
document.getElementById('my-canvas').addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
}
else {
this.inputController = new input_controller_1.InputController('divMain');
//MS Edge doesn't work well with wasd keys, misses some key up events
//also spacebar key made ux scroll sometimes so using a and s instead
this.inputController.KeyMappings = {
Mapping_Left: 'Left',
Mapping_Right: 'Right',
Mapping_Up: 'Up',
Mapping_Down: 'Down',
// Mapping_Action_1:'Shift',
// Mapping_Action_2:' ',
Mapping_Action_1: 'a',
Mapping_Action_2: 's',
Mapping_Start: 'p',
Mapping_Select: 'n',
Mapping_Joy_L: ',',
Mapping_Joy_R: '.'
};
this.inputController.setupGamePad();
// this.inputController.Gamepad_Process_Axis = true;
$('#divMain').show();
}
this.ctx = this.canvas.getContext('2d');
this.createGame();
this.fpsController = new fps_controller_1.FPSController(60);
$('#divLoading').hide();
window.requestAnimationFrame(this.draw.bind(this));
}
createGame() {
this.marioGame = new mariogame_1.MarioGame(this.canvas.width, this.canvas.height, this.ctx, this.inputController, this.mobileMode, this.isSixtyFPS);
}
//30 FPS mode to experience the game as originally designed
thirty() {
this.isSixtyFPS = false;
this.fpsController.UpdateTargetFPS(30);
this.fpsController.enabled = true;
this.createGame();
}
//switch back to 60 FPS mode which is the default
sixty() {
this.isSixtyFPS = true;
this.fpsController.UpdateTargetFPS(60);
this.fpsController.enabled = false;
this.createGame();
}
prevLevel() {
if (this.marioGame.currentLevel > 1)
this.marioGame.loadLevel(this.marioGame.currentLevel - 1);
}
nextLevel() {
if (this.marioGame.currentLevel < 8)
this.marioGame.loadLevel(this.marioGame.currentLevel + 1);
}
btnClick() {
this.marioGame.startGame();
}
drawGame() {
this.marioGame.draw();
}
draw() {
if (this.fpsController.enabled == false) //not using frame skipping - draw as fast as screen allows
this.drawGame();
else if (this.fpsController.IsFrameReady()) //use frame skipping for either high refresh or for 30FPS mode
{
this.drawGame();
}
window.requestAnimationFrame(this.draw.bind(this));
}
}
window["myApp"] = new MyApp();
});
//# sourceMappingURL=index.js.map