-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
190 lines (156 loc) · 4.31 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lode Runner in a Box</title>
<script type="text/javascript" src="js-dos-api-3.0.js"></script>
<script type="text/javascript" src="node_modules/hammerjs/hammer.min.js"></script>
<style type="text/css">
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #000000;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.page-container { text-align: center; }
.dosbox-container { width: 640px; height: 400px; }
.dosbox-container > .dosbox-overlay { background: url(cover.png); }
</style>
</head>
<body>
<div class="page-container">
<div id="dosbox"></div>
<br/>
<button onclick="dosbox.requestFullScreen();">Make fullscreen</button>
</div>
<script type="text/javascript">
//init DosBox emulator
var dosbox = new Dosbox({
id: "dosbox",
onload: function (dosbox) {
dosbox.run("GAME.zip", "./LR.COM");
},
onrun: function (dosbox, app) {
console.log("App '" + app + "' is runned");
}
});
//added fake auto-start
window.onload = function(e) {
document
.querySelector(".dosbox-start")
.click();
};
const keybEnter = {
char : '\n',
key : "Enter",
code: "Enter",
keyCode : 13
};
const keybEsc = {
char : '\0',
key : "Esc",
code: "Esc",
keyCode : 27
};
const keybNum2 = {
char : '2',
key : "2",
code: "Numpad2",
keyCode : 98
};
const keybNum4 = {
char : '4',
key : "4",
code: "Numpad4",
keyCode : 100
};
const keybNum5 = {
char : '5',
key : "5",
code: "Numpad5",
keyCode : 101
};
const keybNum6 = {
bubbles : true,
cancelable : true,
char : '6',
key : "6",
code: "Numpad6",
keyCode : 102
};
const keybNum7 = {
char : '7',
key : "7",
code: "Numpad7",
keyCode : 103
};
const keybNum8 = {
char : '8',
key : "8",
code: "Numpad8",
keyCode : 104
};
const keybNum9 = {
char : '9',
key : "9",
code: "Numpad9",
keyCode : 105
};
var el = document.querySelector("#dosbox");
var mc = new Hammer.Manager(el);
mc.add(new Hammer.Tap({ event: "singletap", taps: 1 }));
mc.on("singletap", function(e) {
var centerX = el.offsetLeft + el.offsetWidth / 2.0;
var centerY = el.offsetTop + el.offsetHeight / 2.0;
var x = e.center.x - centerX;
var y = e.center.y - centerY;
var r = Math.min(el.offsetWidth, el.offsetHeight) / 2.0;
var k = keybEnter;
if (x*x+y*y < r*r) {
k = keybEnter;
} else if (x < 0) {
k = keybNum7;
} else {
k = keybNum9;
}
document.dispatchEvent(new KeyboardEvent("keydown", k));
document.dispatchEvent(new KeyboardEvent("keyup", k));
});
mc.add(new Hammer.Pan({ event: "pan"}));
mc.get("pan").set({ direction: Hammer.DIRECTION_ALL });
var lastPan = "none";
mc.on("panstart panend pancancel", function(e) {
lastPan = "none";
});
mc.on("panleft panright panup pandown", function(e) {
if (e.type == lastPan) {
return;
}
lastPan = e.type;
var k = keybNum5;
switch(e.type) {
case "panleft":
k = keybNum4;
break;
case "panright":
k = keybNum6;
break;
case "panup":
k = keybNum8;
break;
case "pandown":
k = keybNum2;
break;
default:
k = keybNum5;
break;
}
document.dispatchEvent(new KeyboardEvent("keydown", k));
document.dispatchEvent(new KeyboardEvent("keyup", k));
});
</script>
</body>
</html>