Player1444 commited on
Commit
9148502
·
verified ·
1 Parent(s): 08ebbd0

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +312 -0
index.html ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7
+ <title>Super Mario Bros.</title>
8
+
9
+ <style>
10
+ * {
11
+ padding: 0; margin: 0; box-sizing: border-box;
12
+ user-select: none; -webkit-user-select: none; touch-action: none;
13
+ }
14
+ html, body {
15
+ width: 100%; height: 100%; overflow: hidden; background: #000; font-family: "Segoe UI", sans-serif;
16
+ }
17
+ #window {
18
+ display: flex; flex-direction: column; width: 100%; height: 100%;
19
+ border: 2px solid #adadad; background: transparent;
20
+ }
21
+ #titlebar {
22
+ height: 32px; background: #f0f0f0; display: flex; align-items: center;
23
+ justify-content: space-between; flex-shrink: 0; border-bottom: 1px solid #adadad;
24
+ }
25
+ #titlebar-left { display: flex; align-items: center; padding-left: 10px; }
26
+ #titlebar-text { font-size: 12px; color: #333; font-weight: 600; }
27
+ #titlebar-buttons { display: flex; height: 100%; }
28
+ .titlebar-btn {
29
+ width: 46px; height: 100%; border: none; background: transparent; font-size: 16px;
30
+ display: flex; align-items: center; justify-content: center; color: #333; cursor: pointer;
31
+ }
32
+ .titlebar-btn:hover { background: rgba(0, 0, 0, 0.1); }
33
+ #btn-close:hover { background: #e81123; color: white; }
34
+ #game-container {
35
+ display:flex;
36
+ justify-content:center;
37
+ align-items:center;
38
+ background:#000;
39
+ }
40
+
41
+ canvas{
42
+ width:min(100vw, calc(100vh * 4 / 3));
43
+ height:min(100vh, calc(100vw * 3 / 4));
44
+ image-rendering:pixelated;
45
+ }
46
+ body.fullscreen #window { border: none; }
47
+ body.fullscreen #titlebar { display: none; }
48
+
49
+ .touch-zone { position: fixed; z-index: 99999; }
50
+ .touch-btn {
51
+ width: 70px; height: 70px; background: rgba(255, 255, 255, 0.25);
52
+ border: 3px solid rgba(0, 0, 0, 0.4); border-radius: 50%;
53
+ display: flex; align-items: center; justify-content: center;
54
+ font-weight: bold; font-size: 24px; color: rgba(0, 0, 0, 0.6);
55
+ }
56
+ .joystick-base {
57
+ width: 180px; height: 180px; background: rgba(255, 255, 255, 0.15);
58
+ border: 3px solid rgba(0, 0, 0, 0.4); border-radius: 50%; position: relative;
59
+ }
60
+ .joystick-stick {
61
+ width: 80px; height: 80px; background: rgba(0, 0, 0, 0.4); border-radius: 50%;
62
+ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
63
+ }
64
+ #edit-toggle {
65
+ position: fixed; top: 45px; right: 15px; padding: 8px 16px;
66
+ background: rgba(0, 0, 0, 0.6); color: white; border: 2px solid white;
67
+ border-radius: 5px; font-size: 14px; z-index: 100000; cursor: pointer;
68
+ }
69
+ #edit-toggle.editing { background: #e81123; }
70
+ .editing-mode .touch-btn, .editing-mode .joystick-base {
71
+ background: rgba(232, 17, 35, 0.4) !important; border: 3px dashed #fff !important; color: #fff !important;
72
+ }
73
+ </style>
74
+ </head>
75
+ <body>
76
+
77
+ <div id="window">
78
+ <div id="titlebar">
79
+ <div id="titlebar-left"><div id="titlebar-text">Super Mario Bros. unofficial android port by Player1444(Web)</div></div>
80
+ <div id="titlebar-buttons">
81
+ <button class="titlebar-btn" id="btn-minimize">—</button>
82
+ <button class="titlebar-btn" id="btn-maximize">▢</button>
83
+ <button class="titlebar-btn" id="btn-close">✕</button>
84
+ </div>
85
+ </div>
86
+ <div id="game-container">
87
+ <canvas id="c2canvas" width="256" height="240"></canvas>
88
+ </div>
89
+ </div>
90
+
91
+ <button id="edit-toggle">Edit</button>
92
+
93
+ <div id="zone-joystick" class="touch-zone" style="bottom: 40px; left: 40px;">
94
+ <div class="joystick-base"><div class="joystick-stick" id="joystick-stick"></div></div>
95
+ </div>
96
+ <div id="zone-enter" class="touch-zone" style="bottom: 120px; right: 30px;">
97
+ <div class="touch-btn" style="font-size: 16px;">Enter</div>
98
+ </div>
99
+ <div id="zone-shift" class="touch-zone" style="bottom: 120px; right: 110px;">
100
+ <div class="touch-btn" style="font-size: 16px;">Shift</div>
101
+ </div>
102
+ <div id="zone-run" class="touch-zone" style="bottom: 40px; right: 110px;">
103
+ <div class="touch-btn">X</div>
104
+ </div>
105
+ <div id="zone-jump" class="touch-zone" style="bottom: 40px; right: 30px;">
106
+ <div class="touch-btn">Z</div>
107
+ </div>
108
+
109
+ <input style="display:none;" id="c2nwOpenFileDialog" type="file" />
110
+ <input style="display:none;" id="c2nwChooseFolderDialog" type="file" nwdirectory />
111
+ <input style="display:none;" id="c2nwSaveDialog" type="file" nwsaveas />
112
+
113
+ <script src="jquery-3.4.1.min.js"></script>
114
+
115
+
116
+ <script>
117
+ window["c2nodewebkit"] = false;
118
+
119
+
120
+ function createSuperMock() {
121
+ const noop = function() {};
122
+ const proxy = new Proxy(noop, {
123
+ get: function(target, prop) {
124
+ if (prop === Symbol.toPrimitive) return () => "";
125
+ if (prop === 'toString') return () => "";
126
+ if (prop === 'valueOf') return () => 0;
127
+ if (prop === 'then') return undefined;
128
+
129
+
130
+ if (prop === 'platform') return 'win32';
131
+ if (prop === 'filename') return 'index.html';
132
+ if (prop === 'manifest') return { window: { icon: "" } };
133
+ if (prop === 'existsSync') return () => false;
134
+ if (prop === 'readFileSync') return () => "";
135
+ if (prop === 'sep') return '/';
136
+ if (prop === 'join' || prop === 'dirname') return () => "";
137
+
138
+ return proxy;
139
+ },
140
+ apply: function(target, thisArg, args) {
141
+ return proxy;
142
+ },
143
+ construct: function(target, args) {
144
+ return proxy;
145
+ }
146
+ });
147
+ return proxy;
148
+ }
149
+
150
+
151
+ if (typeof window.require === "undefined") {
152
+ window.require = function() { return createSuperMock(); };
153
+ }
154
+
155
+ window.process = createSuperMock();
156
+ window.nw = createSuperMock();
157
+ </script>
158
+
159
+ <script src="c2runtime.js"></script>
160
+
161
+ <script>
162
+ jQuery(document).ready(function () {
163
+ cr_createRuntime("c2canvas");
164
+ loadButtonPositions();
165
+ });
166
+
167
+ document.addEventListener("visibilitychange", function() {
168
+ if (typeof cr_setSuspended !== "undefined") cr_setSuspended(!!document.hidden);
169
+ });
170
+
171
+ document.getElementById("btn-minimize").onclick = () => alert("Окно нельзя свернуть в браузере.");
172
+ document.getElementById("btn-close").onclick = () => {
173
+ document.getElementById("window").style.display = "none";
174
+ if (typeof cr_setSuspended !== "undefined") cr_setSuspended(true);
175
+ };
176
+
177
+ var btnMaximize = document.getElementById("btn-maximize");
178
+ btnMaximize.onclick = () => {
179
+ var elem = document.documentElement;
180
+ if (!document.fullscreenElement) {
181
+ if (elem.requestFullscreen) elem.requestFullscreen();
182
+ else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen();
183
+ } else {
184
+ if (document.exitFullscreen) document.exitFullscreen();
185
+ else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
186
+ }
187
+ };
188
+
189
+ document.addEventListener("fullscreenchange", () => {
190
+ if (document.fullscreenElement) document.body.classList.add("fullscreen");
191
+ else document.body.classList.remove("fullscreen");
192
+ });
193
+
194
+ var isEditing = false;
195
+ var keyMap = { 'zone-jump': [90, 32, 38], 'zone-run': [88], 'zone-shift': [16], 'zone-enter': [13] };
196
+
197
+ function simulateKeyboardEvent(keyCodes, type) {
198
+ if (!keyCodes) return;
199
+ keyCodes.forEach(code => {
200
+ var e = new KeyboardEvent(type, { keyCode: code, which: code, bubbles: true });
201
+ document.dispatchEvent(e); window.dispatchEvent(e);
202
+ var canvas = document.getElementById("c2canvas");
203
+ if (canvas) canvas.dispatchEvent(e);
204
+ });
205
+ }
206
+
207
+ var editToggle = document.getElementById('edit-toggle');
208
+ editToggle.addEventListener('click', function() {
209
+ isEditing = !isEditing;
210
+ if (isEditing) {
211
+ this.classList.add('editing'); this.innerText = 'Save'; document.body.classList.add('editing-mode');
212
+ } else {
213
+ this.classList.remove('editing'); this.innerText = 'Edit'; document.body.classList.remove('editing-mode');
214
+ saveButtonPositions();
215
+ }
216
+ });
217
+
218
+ var activeJoystickKeys = new Set();
219
+ function handleJoystick(e, zone) {
220
+ var touch = e.touches[0];
221
+ var rect = zone.getBoundingClientRect();
222
+ var centerX = rect.left + rect.width / 2;
223
+ var centerY = rect.top + rect.height / 2;
224
+ var dx = touch.clientX - centerX;
225
+ var dy = touch.clientY - centerY;
226
+ var distance = Math.sqrt(dx * dx + dy * dy);
227
+ var angle = Math.atan2(dy, dx);
228
+
229
+ var maxVisualDist = 65;
230
+ var visualDist = Math.min(distance, maxVisualDist);
231
+ var stickX = Math.cos(angle) * visualDist;
232
+ var stickY = Math.sin(angle) * visualDist;
233
+ zone.querySelector('.joystick-stick').style.transform = `translate(calc(-50% + ${stickX}px), calc(-50% + ${stickY}px))`;
234
+
235
+ var deadZone = 30;
236
+ var newKeys = new Set();
237
+ if (distance > deadZone) {
238
+ if (dx > deadZone) newKeys.add(39);
239
+ if (dx < -deadZone) newKeys.add(37);
240
+ if (dy > deadZone) newKeys.add(40);
241
+ if (dy < -deadZone) newKeys.add(38);
242
+ }
243
+
244
+ activeJoystickKeys.forEach(key => { if (!newKeys.has(key)) simulateKeyboardEvent([key], 'keyup'); });
245
+ newKeys.forEach(key => { if (!activeJoystickKeys.has(key)) simulateKeyboardEvent([key], 'keydown'); });
246
+ activeJoystickKeys = newKeys;
247
+ }
248
+
249
+ function resetJoystick(zone) {
250
+ zone.querySelector('.joystick-stick').style.transform = 'translate(-50%, -50%)';
251
+ activeJoystickKeys.forEach(key => simulateKeyboardEvent([key], 'keyup'));
252
+ activeJoystickKeys.clear();
253
+ }
254
+
255
+ var zones = document.querySelectorAll('.touch-zone');
256
+ zones.forEach(zone => {
257
+ var dragX = 0, dragY = 0;
258
+ zone.addEventListener('touchstart', e => {
259
+ if (isEditing) {
260
+ dragX = e.touches[0].clientX - zone.getBoundingClientRect().left;
261
+ dragY = e.touches[0].clientY - zone.getBoundingClientRect().top;
262
+ } else {
263
+ if (zone.id === 'zone-joystick') {
264
+ zone.querySelector('.joystick-stick').style.background = 'rgba(0, 0, 0, 0.6)';
265
+ handleJoystick(e, zone);
266
+ } else {
267
+ zone.querySelector('.touch-btn').style.background = 'rgba(255, 255, 255, 0.6)';
268
+ simulateKeyboardEvent(keyMap[zone.id], 'keydown');
269
+ }
270
+ }
271
+ }, { passive: false });
272
+
273
+ zone.addEventListener('touchmove', e => {
274
+ e.preventDefault();
275
+ if (isEditing) {
276
+ var left = e.touches[0].clientX - dragX;
277
+ var top = e.touches[0].clientY - dragY;
278
+ zone.style.left = Math.max(0, Math.min(window.innerWidth - zone.offsetWidth, left)) + 'px';
279
+ zone.style.top = Math.max(0, Math.min(window.innerHeight - zone.offsetHeight, top)) + 'px';
280
+ zone.style.bottom = 'auto';
281
+ } else if (zone.id === 'zone-joystick') handleJoystick(e, zone);
282
+ }, { passive: false });
283
+
284
+ zone.addEventListener('touchend', e => {
285
+ if (!isEditing) {
286
+ if (zone.id === 'zone-joystick') {
287
+ zone.querySelector('.joystick-stick').style.background = 'rgba(0, 0, 0, 0.4)';
288
+ resetJoystick(zone);
289
+ } else {
290
+ zone.querySelector('.touch-btn').style.background = 'rgba(255, 255, 255, 0.25)';
291
+ simulateKeyboardEvent(keyMap[zone.id], 'keyup');
292
+ }
293
+ }
294
+ }, { passive: false });
295
+ });
296
+
297
+ function saveButtonPositions() {
298
+ var pos = {};
299
+ zones.forEach(z => pos[z.id] = { left: z.style.left, top: z.style.top, bottom: z.style.bottom });
300
+ localStorage.setItem('mario_pos', JSON.stringify(pos));
301
+ }
302
+
303
+ function loadButtonPositions() {
304
+ var saved = JSON.parse(localStorage.getItem('mario_pos') || "{}");
305
+ for (var id in saved) {
306
+ var z = document.getElementById(id);
307
+ if (z) { z.style.left = saved[id].left; z.style.top = saved[id].top; z.style.bottom = saved[id].bottom; }
308
+ }
309
+ }
310
+ </script>
311
+ </body>
312
+ </html>