Player1444 commited on
Commit
dec329d
·
verified ·
1 Parent(s): eb280dc

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +376 -0
index.html ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ var isRunLocked = false;
257
+
258
+ zones.forEach(function(zone) {
259
+ var dragX = 0, dragY = 0;
260
+
261
+
262
+ if (zone.id === 'zone-run') {
263
+ zone.addEventListener('touchstart', function(e) {
264
+ if (isEditing) {
265
+
266
+ var touch = e.touches[0];
267
+ var rect = zone.getBoundingClientRect();
268
+ dragX = touch.clientX - rect.left;
269
+ dragY = touch.clientY - rect.top;
270
+ } else {
271
+
272
+ isRunLocked = !isRunLocked;
273
+
274
+ if (isRunLocked) {
275
+
276
+ simulateKeyboardEvent([88], 'keydown');
277
+ zone.querySelector('.touch-btn').style.background = 'rgba(0, 255, 0, 0.6)'; // Зеленый — показывает, что залипло
278
+ zone.querySelector('.touch-btn').style.borderColor = '#00ff00';
279
+ } else {
280
+
281
+ simulateKeyboardEvent([88], 'keyup');
282
+ zone.querySelector('.touch-btn').style.background = 'rgba(255, 255, 255, 0.25)';
283
+ zone.querySelector('.touch-btn').style.borderColor = 'rgba(0, 0, 0, 0.4)';
284
+ }
285
+ }
286
+ }, { passive: false });
287
+
288
+ zone.addEventListener('touchmove', function(e) {
289
+ if (isEditing) {
290
+ e.preventDefault();
291
+ var touch = e.touches[0];
292
+ var left = touch.clientX - dragX;
293
+ var top = touch.clientY - dragY;
294
+ left = Math.max(0, Math.min(window.innerWidth - zone.offsetWidth, left));
295
+ top = Math.max(0, Math.min(window.innerHeight - zone.offsetHeight, top));
296
+ zone.style.left = left + 'px';
297
+ zone.style.top = top + 'px';
298
+ zone.style.bottom = 'auto';
299
+ }
300
+
301
+ }, { passive: false });
302
+
303
+ zone.addEventListener('touchend', function(e) {
304
+
305
+ if (!isEditing && isRunLocked) {
306
+ zone.querySelector('.touch-btn').style.background = 'rgba(0, 255, 0, 0.6)';
307
+ }
308
+ }, { passive: false });
309
+
310
+ } else {
311
+
312
+ zone.addEventListener('touchstart', function(e) {
313
+ if (isEditing) {
314
+ var touch = e.touches[0];
315
+ var rect = zone.getBoundingClientRect();
316
+ dragX = touch.clientX - rect.left;
317
+ dragY = touch.clientY - rect.top;
318
+ } else {
319
+ if (zone.id === 'zone-joystick') {
320
+ zone.querySelector('.joystick-stick').style.background = 'rgba(0, 0, 0, 0.6)';
321
+ handleJoystick(e, zone);
322
+ } else {
323
+ zone.querySelector('.touch-btn').style.background = 'rgba(255, 255, 255, 0.6)';
324
+ simulateKeyboardEvent(keyMap[zone.id], 'keydown');
325
+ }
326
+ }
327
+ }, { passive: false });
328
+
329
+ zone.addEventListener('touchmove', function(e) {
330
+ e.preventDefault();
331
+ if (isEditing) {
332
+ var touch = e.touches[0];
333
+ var left = touch.clientX - dragX;
334
+ var top = touch.clientY - dragY;
335
+ left = Math.max(0, Math.min(window.innerWidth - zone.offsetWidth, left));
336
+ top = Math.max(0, Math.min(window.innerHeight - zone.offsetHeight, top));
337
+ zone.style.left = left + 'px';
338
+ zone.style.top = top + 'px';
339
+ zone.style.bottom = 'auto';
340
+ } else {
341
+ if (zone.id === 'zone-joystick') {
342
+ handleJoystick(e, zone);
343
+ }
344
+ }
345
+ }, { passive: false });
346
+
347
+ zone.addEventListener('touchend', function(e) {
348
+ if (!isEditing) {
349
+ if (zone.id === 'zone-joystick') {
350
+ zone.querySelector('.joystick-stick').style.background = 'rgba(0, 0, 0, 0.4)';
351
+ resetJoystick(zone);
352
+ } else {
353
+ zone.querySelector('.touch-btn').style.background = 'rgba(255, 255, 255, 0.25)';
354
+ simulateKeyboardEvent(keyMap[zone.id], 'keyup');
355
+ }
356
+ }
357
+ }, { passive: false });
358
+ }
359
+ });
360
+
361
+ function saveButtonPositions() {
362
+ var pos = {};
363
+ zones.forEach(z => pos[z.id] = { left: z.style.left, top: z.style.top, bottom: z.style.bottom });
364
+ localStorage.setItem('mario_pos', JSON.stringify(pos));
365
+ }
366
+
367
+ function loadButtonPositions() {
368
+ var saved = JSON.parse(localStorage.getItem('mario_pos') || "{}");
369
+ for (var id in saved) {
370
+ var z = document.getElementById(id);
371
+ if (z) { z.style.left = saved[id].left; z.style.top = saved[id].top; z.style.bottom = saved[id].bottom; }
372
+ }
373
+ }
374
+ </script>
375
+ </body>
376
+ </html>