-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
478 lines (432 loc) Β· 17.5 KB
/
Copy pathindex.html
File metadata and controls
478 lines (432 loc) Β· 17.5 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" href="Logo.png" type="image/png">
<title>PlyGround Physics Engine</title>
<style>
html {cursor: url('pointer.png'), auto; }
body { margin:0; overflow:hidden; background:#0d1117; color:white; font-family:"Segoe UI",sans-serif; }
.navbar { display:flex; align-items:center; justify-content:space-between; background:linear-gradient(90deg,#00ff95,#0077ff); padding:10px 20px; }
.navbar-left { display:flex; align-items:center; }
.navbar img { height:40px; margin-right:10px; }
.navbar h1 { font-size:22px; margin:0; }
.delete-menu { display:flex; gap:10px; }
.delete-menu button { background:#111; color:white; border:1px solid #00ff95; border-radius:6px; padding:5px 10px; cursor:pointer; transition:0.2s; }
.delete-menu button:hover { background:#00ff95; color:black; }
canvas { display:block; background:#161b22; }
/* --- NEW UI STYLES --- */
/* Sidebar */
#sidebar {
position: fixed;
top: 60px;
right: -360px; /* hidden by default */
width: 340px;
height: calc(100% - 60px);
background: linear-gradient(180deg, rgba(10,12,18,0.98), rgba(18,20,28,0.98));
border-left: 1px solid rgba(255,255,255,0.03);
padding: 14px;
box-shadow: -30px 0 60px rgba(0,0,0,0.6);
transition: right 0.34s cubic-bezier(.2,.8,.2,1);
z-index: 200;
overflow-y: auto;
backdrop-filter: blur(6px);
}
#sidebar.open { right: 0; }
.ui-section-title { font-weight:600; margin: 6px 0 10px 0; color: #dbefff; font-size:14px; }
.console-guide {
background: rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.07);
border-radius: 12px;
padding: 14px;
margin-top: 14px;
font-size: 12px;
line-height: 1.6;
color: #d6e7ff;
}
.console-guide strong { color: #ffffff; }
.console-guide code {
display: inline-block;
background: rgba(255,255,255,0.07);
padding: 1px 6px;
border-radius: 5px;
color: #a8fffa;
font-family: Consolas, monospace;
font-size: 11.5px;
margin: 1px 0;
}
.tab-buttons { display:flex; gap:8px; margin-bottom:12px; }
.tab-buttons button {
flex:1;
padding:8px;
border-radius:8px;
background: rgba(255,255,255,0.03);
color: #cfefff;
border: 1px solid rgba(255,255,255,0.04);
cursor:pointer;
}
.tab-buttons button.active { background: rgba(0,255,255,0.08); border-color: rgba(0,255,255,0.18); color: #ffffff; }
.tab-content { display:none; }
.tab-content.active { display:block; }
.object-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
margin-bottom: 15px;
}
.object-item {
display:flex;
align-items:center;
gap:10px;
padding:10px;
background: rgba(255,255,255,0.02);
border: 1px solid rgba(255,255,255,0.03);
border-radius:8px;
cursor: grab;
user-select: none;
}
.object-item:active { cursor: grabbing; }
/* Audio Control Panel Styling */
.audio-control-panel {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 10px;
padding: 12px;
margin: 14px 0;
}
.audio-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.audio-row label {
font-size: 13px;
color: #cfefff;
}
.volume-slider {
flex: 1;
-webkit-appearance: none;
appearance: none;
height: 6px;
border-radius: 3px;
background: rgba(255, 255, 255, 0.1);
outline: none;
cursor: pointer;
}
.volume-slider::-webkit-slider-runnable-track {
background: linear-gradient(90deg, #00ff95, #0077ff);
height: 6px;
border-radius: 3px;
}
.volume-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 14px;
height: 14px;
border-radius: 50%;
background: #ffffff;
cursor: pointer;
margin-top: -4px;
box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
/* Audio Resume Prompt Overlay */
#audio-resume-prompt {
position: fixed;
top: 75px;
left: 50%;
transform: translateX(-50%);
background: rgba(13, 17, 23, 0.9);
border: 1px solid #00ff95;
padding: 10px 20px;
border-radius: 30px;
font-size: 14px;
color: #ffffff;
z-index: 9999;
cursor: pointer;
box-shadow: 0 4px 20px rgba(0, 255, 149, 0.2);
backdrop-filter: blur(8px);
transition: opacity 0.3s ease;
display: none;
align-items: center;
gap: 8px;
}
.prop-row { display:flex; justify-content:space-between; gap:8px; align-items:center; margin:8px 0; }
.prop-row label { flex:1; font-size:13px; color:#d7eefe; }
.prop-row input[type="number"], .prop-row input[type="text"] {
width:100px;
padding:6px;
border-radius:6px;
border:1px solid rgba(255,255,255,0.06);
background: rgba(255,255,255,0.02);
color: white;
}
.prop-row input[type="checkbox"] { transform:scale(1.2); }
#apply-props {
margin-top:10px;
width:100%;
padding:8px;
border-radius:8px;
border:none;
background: linear-gradient(90deg,#00c9ff,#0077ff);
color:#001;
font-weight:700;
cursor:pointer;
}
/* small helper: selection highlight overlay top-right */
.ui-hint { position:fixed; right:360px; top:70px; color:rgba(200,220,255,0.65); font-size:12px; z-index:210; display:none; }
.ui-hint.visible { display:block; }
/* make sure canvas area still clickable for drag/drop */
#world { touch-action: none; }
/* menu button */
#uiMenuBtn {
background: rgba(0,0,0,0.12);
border: 1px solid rgba(255,255,255,0.06);
color: white;
padding:6px 10px;
border-radius:8px;
cursor:pointer;
margin-left:8px;
}
</style>
</head>
<body>
<audio id="bgMusic" src="BackGroundMusic.webm" loop></audio>
<div id="audio-resume-prompt">π΅ Click anywhere to resume background music</div>
<div class="navbar">
<div class="navbar-left">
<img src="Logo.png" alt="Logo">
<h1>PlyGround Physics Engine</h1>
</div>
<div class="delete-menu">
<button id="delLast">Delete Last</button>
<button id="delAll">Delete All</button>
<button id="delMode">Delete Mode: OFF</button>
<button id="uiMenuBtn" title="Open UI">β° UI</button>
</div>
</div>
<canvas id="world"></canvas>
<div id="sidebar" aria-hidden="true">
<div class="tab-buttons">
<button class="tab-btn active" data-tab="objects">Objects</button>
<button class="tab-btn" data-tab="properties">Properties</button>
<button class="tab-btn" data-tab="console">Console</button>
</div>
<div id="tab-objects" class="tab-content active">
<div class="ui-section-title">Drag & Drop Objects</div>
<div class="object-grid">
<div class="object-item" draggable="true" data-type="box">π¦ Box</div>
<div class="object-item" draggable="true" data-type="ball">βͺ Ball</div>
<div class="object-item" draggable="true" data-type="triangle">πΊ Triangle</div>
<div class="object-item" draggable="true" data-type="rod">β¬ Rod</div>
<div class="object-item" draggable="true" data-type="star">β Star</div>
<div class="object-item" draggable="true" data-type="hex">⬣ Hex</div>
<div class="object-item" draggable="true" data-type="plank">πͺ΅ Plank</div>
<div class="object-item" draggable="true" data-type="miniball">β’ MiniBall</div>
<div class="object-item" draggable="true" data-type="tnt">π£ TNT</div>
<div class="object-item" draggable="true" data-type="torch">π―οΈ Torch</div>
<div class="object-item" draggable="true" data-type="cannon">π« Cannon</div>
<div class="object-item" draggable="true" data-type="encoder">π₯οΈ Encoder</div>
<div class="object-item" draggable="true" data-type="gravitywell">π Gravity Well</div>
<div class="object-item" draggable="true" data-type="portal">π Portal Pair</div>
</div>
<div class="ui-section-title">Audio Settings</div>
<div class="audio-control-panel">
<div class="audio-row">
<label id="volume-label">π BGM Volume (50%)</label>
<input type="range" id="bgm-volume" class="volume-slider" min="0" max="1" step="0.01" value="0.5">
</div>
</div>
<div style="height:10px"></div>
<div class="ui-section-title">Quick Tips</div>
<div style="font-size:13px;color:#cde8ff;line-height:1.4">
β’ Drag items onto the canvas to spawn.<br>
β’ Double-click an object on the canvas to inspect its properties.<br>
β’ Edit density/friction and press Apply to update live.<br>
β’ Objects marked 'Burnable' will ignite from nearby fire.
</div>
</div>
<div id="tab-properties" class="tab-content">
<div class="ui-section-title">Selected Object</div>
<div id="no-selection" style="color:#9fbfe6;font-size:13px">
No object selected. Double-click an object on the canvas.
</div>
<div id="prop-panel" style="display:none">
<div class="prop-row">
<label>Label</label>
<input id="prop-label" type="text" />
</div>
<div class="prop-row">
<label>Density</label>
<input id="prop-density" type="number" step="0.01" />
</div>
<div class="prop-row">
<label>Friction</label>
<input id="prop-friction" type="number" step="0.01" />
</div>
<div class="prop-row" style="justify-content:flex-start;">
<label style="flex:0 0 auto;margin-right:6px">Burnable</label>
<input id="prop-burn" type="checkbox" />
</div>
<button id="apply-props">Apply</button>
<div style="height:12px"></div>
<div style="font-size:12px;color:#cde8ff">
Note: Some changes (like mass/density) may slightly alter current velocities.
</div>
</div>
</div>
<div id="tab-console" class="tab-content">
<div class="ui-section-title">Encoder Console</div>
<div id="console-instructions" style="font-size:13px;color:#cde8ff;line-height:1.5;margin-bottom:10px;">
Write a single command and press <strong>M</strong> while pointing at a target object to execute it.
</div>
<textarea id="encoder-console-input" placeholder=".teleport(200,150)" style="width:100%; min-height:140px; padding:10px; border-radius:10px; border:1px solid rgba(255,255,255,0.08); background:rgba(255,255,255,0.04); color:white; font-family:Consolas,monospace; font-size:14px; resize:vertical;"></textarea>
<div id="console-autofill" style="margin-top:10px; display:flex; flex-wrap:wrap; gap:8px;">
<button type="button" class="autofill-btn">.teleport(200,150)</button>
<button type="button" class="autofill-btn">.transform(ball)</button>
<button type="button" class="autofill-btn">.push(0.05,right)</button>
<button type="button" class="autofill-btn">.size(1.3)</button>
<button type="button" class="autofill-btn">.get(density)</button>
<button type="button" class="autofill-btn">.get(burning)</button>
<button type="button" class="autofill-btn">if(.get(name)=="Box"){ .burn() }</button>
<button type="button" class="autofill-btn">.color(#ff0000)</button>
<button type="button" class="autofill-btn">.setvelocity(5,-2)</button>
<button type="button" class="autofill-btn">.setgravity(0.0008)</button>
<button type="button" class="autofill-btn">.setgravity(0.0004,400)</button>
</div>
<button id="encoder-console-run" style="margin-top:10px; width:100%; padding:10px; border:none; border-radius:10px; background: linear-gradient(90deg,#7b61ff,#c98bff); color:#fff; cursor:pointer; font-weight:700;">Save Command</button>
<div id="console-feedback" style="margin-top:10px; font-size:13px; color:#b1f2c5;"></div>
<div class="console-guide">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:10px;">
<span style="font-size:18px">π₯οΈ</span>
<strong style="font-size:14px;letter-spacing:0.5px">ENCODER REFERENCE</strong>
</div>
<div style="margin-bottom:10px;padding:8px;background:rgba(0,188,255,0.06);border-left:2px solid rgba(0,188,255,0.4);border-radius:6px;">
<strong style="color:#7dd3fc;font-size:12px">β‘ SYNTAX</strong><br>
<code>.command(arg1, arg2)</code><br>
<span style="font-size:12px;opacity:0.8">Double-click Encoder β write command β press <strong>M</strong> aimed at a target.</span>
</div>
<div style="margin-bottom:10px;padding:8px;background:rgba(160,80,255,0.06);border-left:2px solid rgba(160,80,255,0.4);border-radius:6px;">
<strong style="color:#c084fc;font-size:12px">π CONTROL FLOW</strong><br>
<code>if(.get(name)=="Box")</code><br>
<code> .burn()</code><br>
<code>else</code><br>
<code> .teleport(300,100)</code>
</div>
<div style="margin-bottom:10px;">
<strong style="color:#86efac;font-size:12px">π¦ MOVEMENT</strong><br>
<code>.teleport(x, y)</code> β snap position<br>
<code>.push(force, dir)</code> β left/right/up/down<br>
<code>.setvelocity(vx, vy)</code> β override velocity<br>
<code>.applyforce(fx, fy)</code> β raw force vector
</div>
<div style="margin-bottom:10px;">
<strong style="color:#fde68a;font-size:12px">π§ PROPERTIES</strong><br>
<code>.size(scale)</code> β resize body<br>
<code>.setdensity(n)</code> β change mass<br>
<code>.setfriction(n)</code> β surface grip<br>
<code>.rotate(deg)</code> β rotate in degrees<br>
<code>.color(#hex)</code> β repaint fill<br>
<code>.setlabel(name)</code> β rename entity
</div>
<div style="margin-bottom:10px;">
<strong style="color:#fca5a5;font-size:12px">π₯ ACTIONS</strong><br>
<code>.burn()</code> β ignite body<br>
<code>.transform(type)</code> β morph to box/ball/etc<br>
<code>.delete()</code> β remove from world<br>
<code>.makestatic()</code> / <code>.makedynamic()</code>
</div>
<div style="margin-bottom:10px;">
<strong style="color:#67e8f9;font-size:12px">π GRAVITY WELL</strong><br>
<code>.setgravity(force)</code> β pull strength<br>
<code>.setgravity(force, radius)</code> β force + range
</div>
<div style="padding:8px;background:rgba(255,255,255,0.03);border-radius:6px;">
<strong style="color:#d1d5db;font-size:12px">π‘ GET VALUES</strong><br>
<code>.get(name)</code> Β· <code>.get(density)</code> Β· <code>.get(x)</code><br>
<code>.get(burning)</code> Β· <code>.get(mass)</code> Β· <code>.get(angle)</code>
</div>
</div>
</div>
</div>
<div class="ui-hint" id="uiHint">Double-click object β properties appear</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const bgMusic = document.getElementById('bgMusic');
const volumeSlider = document.getElementById('bgm-volume');
const volumeLabel = document.getElementById('volume-label');
const resumePrompt = document.getElementById('audio-resume-prompt');
function updateLabelText(value) {
const percentage = Math.round(value * 100);
if (percentage === 0) {
volumeLabel.textContent = `π Muted (0%)`;
} else if (percentage < 50) {
volumeLabel.textContent = `π BGM Volume (${percentage}%)`;
} else {
volumeLabel.textContent = `π BGM Volume (${percentage}%)`;
}
}
// Recover volume state
const savedVolume = sessionStorage.getItem('bgm_volume_level');
if (savedVolume !== null) {
bgMusic.volume = savedVolume;
volumeSlider.value = savedVolume;
updateLabelText(savedVolume);
} else {
bgMusic.volume = volumeSlider.value;
}
// Recover duration timestamp
const savedTime = sessionStorage.getItem('bgm_playback_time');
if (savedTime !== null) {
bgMusic.currentTime = parseFloat(savedTime);
}
// Check if music was previously active before refresh
const wasPlayingBeforeRefresh = sessionStorage.getItem('bgm_is_playing') === 'true';
// Track state in real-time
bgMusic.addEventListener('timeupdate', () => {
sessionStorage.setItem('bgm_playback_time', bgMusic.currentTime);
});
bgMusic.addEventListener('play', () => {
sessionStorage.setItem('bgm_is_playing', 'true');
});
bgMusic.addEventListener('pause', () => {
sessionStorage.setItem('bgm_is_playing', 'false');
});
// Volume slider inputs
volumeSlider.addEventListener('input', (e) => {
const volumeValue = e.target.value;
bgMusic.volume = volumeValue;
sessionStorage.setItem('bgm_volume_level', volumeValue);
updateLabelText(volumeValue);
});
// Attempt to trigger playback automatically
const playAudio = () => {
bgMusic.play()
.then(() => {
// If successful, hide prompt banner completely
resumePrompt.style.display = 'none';
})
.catch(err => {
// Chrome blocked it! Show prompt banner if it was playing previously
if (wasPlayingBeforeRefresh) {
resumePrompt.style.display = 'flex';
}
});
};
// Run autoplay on load
playAudio();
// Catch-all interaction handler to clear the block rule on any page click
const startAudioOnInteraction = () => {
bgMusic.play().then(() => {
resumePrompt.style.display = 'none';
}).catch(err => console.log("Audio contextual lock error."));
document.removeEventListener('click', startAudioOnInteraction);
};
document.addEventListener('click', startAudioOnInteraction);
});
</script>
<script src="https://cdn.jsdelivr.net/npm/matter-js@0.19.0/build/matter.min.js"></script>
<script src="script.js"></script>
</body>
</html>