Update index.html
Browse files- index.html +172 -18
index.html
CHANGED
@@ -1,19 +1,173 @@
|
|
1 |
-
<!
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>A-Frame Space Shooter with 3D Editor</title>
|
6 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
|
7 |
+
<style>
|
8 |
+
.ui-panel {
|
9 |
+
position: fixed;
|
10 |
+
top: 20px;
|
11 |
+
left: 20px;
|
12 |
+
z-index: 9999;
|
13 |
+
background: rgba(0,0,0,0.7);
|
14 |
+
padding: 10px;
|
15 |
+
border-radius: 5px;
|
16 |
+
color: white;
|
17 |
+
font-family: Arial, sans-serif;
|
18 |
+
}
|
19 |
+
.ui-panel button {
|
20 |
+
display: block;
|
21 |
+
margin: 5px 0;
|
22 |
+
padding: 5px 10px;
|
23 |
+
}
|
24 |
+
.animation-panel {
|
25 |
+
position: fixed;
|
26 |
+
top: 20px;
|
27 |
+
right: 20px;
|
28 |
+
z-index: 9999;
|
29 |
+
background: rgba(0,0,0,0.7);
|
30 |
+
padding: 10px;
|
31 |
+
border-radius: 5px;
|
32 |
+
color: white;
|
33 |
+
font-family: Arial, sans-serif;
|
34 |
+
}
|
35 |
+
.animation-panel input {
|
36 |
+
width: 50px;
|
37 |
+
margin-right: 5px;
|
38 |
+
}
|
39 |
+
</style>
|
40 |
+
</head>
|
41 |
+
<body>
|
42 |
+
<div class="ui-panel">
|
43 |
+
<button onclick="addPrimitive('box')">Add Box</button>
|
44 |
+
<button onclick="addPrimitive('sphere')">Add Sphere</button>
|
45 |
+
<button onclick="addPrimitive('cylinder')">Add Cylinder</button>
|
46 |
+
<button onclick="addPrimitive('cone')">Add Cone</button>
|
47 |
+
<button onclick="addPrimitive('torus')">Add Torus</button>
|
48 |
+
<button onclick="toggleGameMode()">Toggle Game Mode</button>
|
49 |
+
</div>
|
50 |
+
|
51 |
+
<div class="animation-panel">
|
52 |
+
<h3>Animation Controls</h3>
|
53 |
+
<p>Velocity:</p>
|
54 |
+
<input id="vx" type="number" placeholder="X">
|
55 |
+
<input id="vy" type="number" placeholder="Y">
|
56 |
+
<input id="vz" type="number" placeholder="Z">
|
57 |
+
<p>Rotation (degrees):</p>
|
58 |
+
<input id="rx" type="number" placeholder="X">
|
59 |
+
<input id="ry" type="number" placeholder="Y">
|
60 |
+
<input id="rz" type="number" placeholder="Z">
|
61 |
+
<button onclick="applyAnimation()">Apply Animation</button>
|
62 |
+
</div>
|
63 |
+
|
64 |
+
<a-scene fog="type: linear; color: #87CEEB; near: 0; far: 50">
|
65 |
+
<a-sky color="#87CEEB"></a-sky>
|
66 |
+
<a-entity id="player" position="0 1.6 0">
|
67 |
+
<a-entity camera look-controls wasd-controls>
|
68 |
+
<a-entity id="cursor" cursor="fuse: false;" position="0 0 -1"
|
69 |
+
geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03"
|
70 |
+
material="color: white; shader: flat"
|
71 |
+
raycaster="objects: .enemy, .spawner, .editable"></a-entity>
|
72 |
+
</a-entity>
|
73 |
+
</a-entity>
|
74 |
+
<a-entity id="scoreBar" position="0 3 -5">
|
75 |
+
<a-box width="1" height="0.1" depth="0.1" color="#444444"></a-box>
|
76 |
+
<a-box id="scoreIndicator" width="1" height="0.1" depth="0.1" color="#FFA500" scale="0 1 1"></a-box>
|
77 |
+
<a-text value="Score" position="0 0.1 0" align="center" color="white"></a-text>
|
78 |
+
</a-entity>
|
79 |
+
<a-entity id="healthDisplay" position="0 2.5 -5" scale="5 5 5"></a-entity>
|
80 |
+
<a-entity id="unitCounters" position="-0.8 0.6 -1.5" scale="0.5 0.5 0.5"></a-entity>
|
81 |
+
</a-scene>
|
82 |
+
|
83 |
+
<script>
|
84 |
+
// ... [All the game logic from the previous script goes here] ...
|
85 |
+
|
86 |
+
// Editor functionality
|
87 |
+
let selectedObject = null;
|
88 |
+
let isGameMode = true;
|
89 |
+
|
90 |
+
function addPrimitive(type) {
|
91 |
+
const scene = document.querySelector('a-scene');
|
92 |
+
const newEntity = document.createElement('a-entity');
|
93 |
+
newEntity.setAttribute('geometry', `primitive: ${type}`);
|
94 |
+
newEntity.setAttribute('material', 'color: #4CC3D9');
|
95 |
+
newEntity.setAttribute('position', '0 1.5 -3');
|
96 |
+
newEntity.setAttribute('class', 'editable');
|
97 |
+
newEntity.addEventListener('click', function() { selectObject(this); });
|
98 |
+
scene.appendChild(newEntity);
|
99 |
+
}
|
100 |
+
|
101 |
+
function selectObject(obj) {
|
102 |
+
if (selectedObject) {
|
103 |
+
selectedObject.setAttribute('material', 'color', '#4CC3D9');
|
104 |
+
}
|
105 |
+
selectedObject = obj;
|
106 |
+
selectedObject.setAttribute('material', 'color', '#FF0000');
|
107 |
+
}
|
108 |
+
|
109 |
+
function applyAnimation() {
|
110 |
+
if (!selectedObject) {
|
111 |
+
alert('Please select an object first');
|
112 |
+
return;
|
113 |
+
}
|
114 |
+
|
115 |
+
const vx = parseFloat(document.getElementById('vx').value) || 0;
|
116 |
+
const vy = parseFloat(document.getElementById('vy').value) || 0;
|
117 |
+
const vz = parseFloat(document.getElementById('vz').value) || 0;
|
118 |
+
const rx = parseFloat(document.getElementById('rx').value) || 0;
|
119 |
+
const ry = parseFloat(document.getElementById('ry').value) || 0;
|
120 |
+
const rz = parseFloat(document.getElementById('rz').value) || 0;
|
121 |
+
|
122 |
+
let currentPosition = selectedObject.getAttribute('position');
|
123 |
+
|
124 |
+
selectedObject.setAttribute('animation__position', {
|
125 |
+
property: 'position',
|
126 |
+
dur: 1000,
|
127 |
+
dir: 'alternate',
|
128 |
+
loop: true,
|
129 |
+
to: `${currentPosition.x + vx} ${currentPosition.y + vy} ${currentPosition.z + vz}`,
|
130 |
+
easing: 'linear'
|
131 |
+
});
|
132 |
+
|
133 |
+
selectedObject.setAttribute('animation__rotation', {
|
134 |
+
property: 'rotation',
|
135 |
+
dur: 1000,
|
136 |
+
dir: 'alternate',
|
137 |
+
loop: true,
|
138 |
+
to: `${rx} ${ry} ${rz}`,
|
139 |
+
easing: 'linear'
|
140 |
+
});
|
141 |
+
}
|
142 |
+
|
143 |
+
function toggleGameMode() {
|
144 |
+
isGameMode = !isGameMode;
|
145 |
+
const cursor = document.querySelector('#cursor');
|
146 |
+
if (isGameMode) {
|
147 |
+
cursor.setAttribute('raycaster', 'objects', '.enemy, .spawner');
|
148 |
+
} else {
|
149 |
+
cursor.setAttribute('raycaster', 'objects', '.editable');
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
// Modify the click event listener to work with both game and edit modes
|
154 |
+
scene.addEventListener('click', (event) => {
|
155 |
+
if (isGameMode) {
|
156 |
+
fireLaser(player, '#00FF00');
|
157 |
+
} else if (event.detail.intersectedEl && event.detail.intersectedEl.classList.contains('editable')) {
|
158 |
+
selectObject(event.detail.intersectedEl);
|
159 |
+
}
|
160 |
+
});
|
161 |
+
|
162 |
+
// Initialize the game
|
163 |
+
updateHealthDisplay();
|
164 |
+
updateUnitCounters();
|
165 |
+
|
166 |
+
setInterval(() => {
|
167 |
+
updateGame();
|
168 |
+
score++;
|
169 |
+
updateScoreDisplay();
|
170 |
+
}, 1000);
|
171 |
+
</script>
|
172 |
+
</body>
|
173 |
+
</html>
|