Ueban2 commited on
Commit
46c1f7d
·
verified ·
1 Parent(s): c0dfee2

Deploy from HuggingChat

Browse files
Files changed (2) hide show
  1. README.md +9 -5
  2. index.html +322 -19
README.md CHANGED
@@ -1,10 +1,14 @@
1
  ---
2
- title: Minecraft Mobile Final
3
- emoji: 😻
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ title: "Minecraft Mobile Final"
3
+ emoji: 🛸
4
+ colorFrom: green
5
+ colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - huggingchat
10
  ---
11
 
12
+ # Minecraft Mobile Final
13
+
14
+ Built with [HuggingChat](https://huggingface.co/chat).
index.html CHANGED
@@ -1,19 +1,322 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ru">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
+ <title>Minecraft Mobile Final</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ overflow: hidden;
11
+ background-color: #87CEEB;
12
+ font-family: sans-serif;
13
+ touch-action: none;
14
+ user-select: none;
15
+ }
16
+ #game-container {
17
+ position: relative;
18
+ width: 100vw;
19
+ height: 100vh;
20
+ background-color: #87CEEB;
21
+ overflow: hidden;
22
+ }
23
+ canvas {
24
+ display: block;
25
+ }
26
+ #controls {
27
+ position: absolute;
28
+ bottom: 20px; /* Почти в самый низ */
29
+ left: 30px;
30
+ width: 120px;
31
+ height: 120px;
32
+ background: rgba(255, 255, 255, 0.15);
33
+ backdrop-filter: blur(5px);
34
+ border-radius: 50%;
35
+ display: flex;
36
+ justify-content: center;
37
+ align-items: center;
38
+ border: 1px solid rgba(255,255,255,0.3);
39
+ box-shadow: 0 8px 32px rgba(0,0,0,0.2);
40
+ }
41
+ #joystick {
42
+ width: 50px;
43
+ height: 50px;
44
+ background: rgba(0, 0, 0, 0.6);
45
+ border-radius: 50%;
46
+ position: relative;
47
+ border: 2px solid rgba(255,255,255,0.8);
48
+ box-shadow: 0 4px 10px rgba(0,0,0,0.4);
49
+ }
50
+ #jump-btn {
51
+ position: absolute;
52
+ bottom: 20px; /* Почти в самый низ */
53
+ right: 30px;
54
+ width: 80px;
55
+ height: 80px;
56
+ background: rgba(0, 0, 0, 0.6);
57
+ backdrop-filter: blur(5px);
58
+ color: white;
59
+ border-radius: 50%;
60
+ display: flex;
61
+ justify-content: center;
62
+ align-items: center;
63
+ font-weight: bold;
64
+ border: 2px solid rgba(255,255,255,0.8);
65
+ text-align: center;
66
+ font-size: 13px;
67
+ box-shadow: 0 8px 32px rgba(0,0,0,0.2);
68
+ }
69
+ #mode-switch {
70
+ position: absolute;
71
+ top: 40px; /* Сместили чуть ниже от края */
72
+ left: 50%;
73
+ transform: translateX(-50%);
74
+ background: rgba(0, 0, 0, 0.5);
75
+ backdrop-filter: blur(8px);
76
+ color: white;
77
+ padding: 10px 20px;
78
+ border-radius: 20px;
79
+ font-size: 15px;
80
+ border: 1px solid rgba(255,255,255,0.4);
81
+ box-shadow: 0 4px 15px rgba(0,0,0,0.2);
82
+ letter-spacing: 0.5px;
83
+ }
84
+ #hotbar {
85
+ position: absolute;
86
+ bottom: 160px; /* Опустили ещё ниже, ближе к управлению */
87
+ left: 50%;
88
+ transform: translateX(-50%);
89
+ display: flex;
90
+ gap: 12px;
91
+ background: rgba(0, 0, 0, 0.4);
92
+ backdrop-filter: blur(10px);
93
+ padding: 12px;
94
+ border-radius: 16px;
95
+ border: 1px solid rgba(255,255,255,0.3);
96
+ box-shadow: 0 8px 32px rgba(0,0,0,0.3);
97
+ }
98
+ .slot {
99
+ width: 45px;
100
+ height: 45px;
101
+ border: 3px solid #888;
102
+ background: #555;
103
+ cursor: pointer;
104
+ transition: 0.2s;
105
+ }
106
+ .slot.active { border-color: #fff; transform: scale(1.1); box-shadow: 0 0 10px #fff; }
107
+
108
+ .block-grass { background-color: #5da130; }
109
+ .block-dirt { background-color: #8B4513; }
110
+ .block-stone { background-color: #808080; }
111
+ .block-wood { background-color: #A0522D; }
112
+ </style>
113
+ </head>
114
+ <body>
115
+
116
+ <div id="game-container">
117
+ <div id="mode-switch">Режим: Ломать ⛏️</div>
118
+
119
+ <canvas id="gameCanvas"></canvas>
120
+
121
+ <div id="controls">
122
+ <div id="joystick"></div>
123
+ </div>
124
+
125
+ <div id="jump-btn">ПРЫЖОК</div>
126
+
127
+ <div id="hotbar">
128
+ <div class="slot active block-grass" data-type="grass"></div>
129
+ <div class="slot block-dirt" data-type="dirt"></div>
130
+ <div class="slot block-stone" data-type="stone"></div>
131
+ <div class="slot block-wood" data-type="wood"></div>
132
+ </div>
133
+ </div>
134
+
135
+ <script>
136
+ const canvas = document.getElementById('gameCanvas');
137
+ const ctx = canvas.getContext('2d');
138
+ const modeBtn = document.getElementById('mode-switch');
139
+
140
+ function resize() {
141
+ canvas.width = window.innerWidth;
142
+ canvas.height = window.innerHeight;
143
+ }
144
+ window.onresize = resize;
145
+ resize();
146
+
147
+ const gridSize = 40;
148
+ const world = {};
149
+ const player = {
150
+ x: 400, y: 100, w: 36, h: 64,
151
+ vx: 0, vy: 0, speed: 5,
152
+ jumpPower: -12, gravity: 0.6, grounded: false,
153
+ animTimer: 0
154
+ };
155
+
156
+ const camera = { x: 0, y: 0 };
157
+ let selectedBlock = 'grass';
158
+ let isBuildMode = false;
159
+
160
+ const blockColors = {
161
+ grass: '#5da130', dirt: '#8B4513', stone: '#808080', wood: '#A0522D'
162
+ };
163
+
164
+ // Генерируем ОГРОМНЫЙ мир (от -200 до 500 блоков)
165
+ for(let x = -200; x < 500; x++) {
166
+ for(let y = 8; y < 30; y++) {
167
+ if(y === 8) world[`${x},${y}`] = 'grass';
168
+ else if(y > 15) world[`${x},${y}`] = 'stone';
169
+ else world[`${x},${y}`] = 'dirt';
170
+ }
171
+ }
172
+
173
+ // Touch handling
174
+ let joystickActive = false;
175
+ let joyX = 0;
176
+ const joystick = document.getElementById('joystick');
177
+
178
+ document.getElementById('controls').addEventListener('touchstart', (e) => {
179
+ joystickActive = true;
180
+ e.preventDefault();
181
+ }, {passive: false});
182
+
183
+ window.addEventListener('touchend', () => {
184
+ joystickActive = false;
185
+ joyX = 0;
186
+ joystick.style.transform = `translate(0, 0)`;
187
+ });
188
+
189
+ window.addEventListener('touchmove', (e) => {
190
+ if(!joystickActive) return;
191
+ const touch = e.touches[0];
192
+ const rect = document.getElementById('controls').getBoundingClientRect();
193
+ const centerX = rect.left + rect.width/2;
194
+ joyX = (touch.clientX - centerX) / (rect.width/2);
195
+ if(joyX > 1) joyX = 1;
196
+ if(joyX < -1) joyX = -1;
197
+ joystick.style.transform = `translate(${joyX * 25}px, 0)`;
198
+ }, {passive: false});
199
+
200
+ document.getElementById('jump-btn').addEventListener('touchstart', (e) => {
201
+ if(player.grounded) player.vy = player.jumpPower;
202
+ e.preventDefault();
203
+ });
204
+
205
+ modeBtn.addEventListener('touchstart', (e) => {
206
+ isBuildMode = !isBuildMode;
207
+ modeBtn.innerText = isBuildMode ? "Режим: Строить 📦" : "Режим: Ломать ⛏️";
208
+ e.preventDefault();
209
+ });
210
+
211
+ document.querySelectorAll('.slot').forEach(slot => {
212
+ slot.addEventListener('touchstart', (e) => {
213
+ document.querySelectorAll('.slot').forEach(s => s.classList.remove('active'));
214
+ slot.classList.add('active');
215
+ selectedBlock = slot.dataset.type;
216
+ e.stopPropagation();
217
+ });
218
+ });
219
+
220
+ canvas.addEventListener('touchstart', (e) => {
221
+ const touch = e.touches[0];
222
+ // КРИТИЧЕСКИЙ МОМЕНТ: прибавляем координаты камеры
223
+ const gx = Math.floor((touch.clientX + camera.x) / gridSize);
224
+ const gy = Math.floor((touch.clientY + camera.y) / gridSize);
225
+
226
+ if(isBuildMode) {
227
+ if(!world[`${gx},${gy}`]) world[`${gx},${gy}`] = selectedBlock;
228
+ } else {
229
+ delete world[`${gx},${gy}`];
230
+ }
231
+ });
232
+
233
+ function update() {
234
+ player.vx = joyX * player.speed;
235
+ player.vy += player.gravity;
236
+ player.x += player.vx;
237
+ player.y += player.vy;
238
+
239
+ player.grounded = false;
240
+ const px = Math.floor((player.x + player.w/2) / gridSize);
241
+ const py = Math.floor((player.y + player.h) / gridSize);
242
+
243
+ if(world[`${px},${py}`]) {
244
+ player.y = py * gridSize - player.h;
245
+ player.vy = 0;
246
+ player.grounded = true;
247
+ }
248
+
249
+ // Плавное перемещение камеры за игроком
250
+ camera.x = player.x - canvas.width / 2;
251
+ camera.y = player.y - canvas.height / 2;
252
+ if (camera.y > 0) camera.y = 0; // Чтобы не видеть «пустоту» выше неба
253
+ }
254
+
255
+ function draw() {
256
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
257
+
258
+ ctx.save();
259
+ ctx.translate(-camera.x, -camera.y);
260
+
261
+ // Рисуем блоки
262
+ for(let key in world) {
263
+ const [x, y] = key.split(',').map(Number);
264
+
265
+ // Оптимизация отрисовки (только то, что на экране)
266
+ if (x * gridSize < camera.x - gridSize || x * gridSize > camera.x + canvas.width) continue;
267
+ if (y * gridSize < camera.y - gridSize || y * gridSize > camera.y + canvas.height) continue;
268
+
269
+ ctx.fillStyle = blockColors[world[key]];
270
+ ctx.fillRect(x * gridSize, y * gridSize, gridSize, gridSize);
271
+
272
+ // Эффект объема
273
+ ctx.fillStyle = 'rgba(255,255,255,0.2)';
274
+ ctx.fillRect(x * gridSize, y * gridSize, gridSize, 4);
275
+ ctx.fillStyle = 'rgba(0,0,0,0.2)';
276
+ ctx.fillRect(x * gridSize, y * gridSize + gridSize - 4, gridSize, 4);
277
+
278
+ ctx.strokeStyle = 'rgba(0,0,0,0.05)';
279
+ ctx.strokeRect(x * gridSize, y * gridSize, gridSize, gridSize);
280
+ }
281
+
282
+ // Анимация Стива
283
+ player.animTimer += 0.1;
284
+ const bobbing = Math.sin(player.animTimer) * 2;
285
+ const renderY = player.y + (player.vx !== 0 ? bobbing : 0);
286
+
287
+ // Тело
288
+ ctx.fillStyle = '#006400';
289
+ ctx.fillRect(player.x, renderY + 20, player.w, 25);
290
+ // Голова
291
+ ctx.fillStyle = '#FFDBAC';
292
+ ctx.fillRect(player.x + 4, renderY, player.w - 8, 22);
293
+ // Глаза
294
+ ctx.fillStyle = '#fff';
295
+ ctx.fillRect(player.x + 8, renderY + 8, 6, 4);
296
+ ctx.fillRect(player.x + player.w - 14, renderY + 8, 6, 4);
297
+ ctx.fillStyle = '#000';
298
+ ctx.fillRect(player.x + 10, renderY + 9, 3, 3);
299
+ ctx.fillRect(player.x + player.w - 11, renderY + 9, 3, 3);
300
+ // Рот
301
+ ctx.fillStyle = '#8B4513';
302
+ ctx.fillRect(player.x + 12, renderY + 16, 12, 3);
303
+ // Штаны
304
+ ctx.fillStyle = '#0000CD';
305
+ ctx.fillRect(player.x, renderY + 45, player.w, 19);
306
+ // Руки
307
+ ctx.fillStyle = '#FFDBAC';
308
+ ctx.fillRect(player.x - 6, renderY + 22, 6, 15);
309
+ ctx.fillRect(player.x + player.w, renderY + 22, 6, 15);
310
+
311
+ ctx.restore();
312
+ }
313
+
314
+ function loop() {
315
+ update();
316
+ draw();
317
+ requestAnimationFrame(loop);
318
+ }
319
+ loop();
320
+ </script>
321
+ </body>
322
+ </html>