awacke1 commited on
Commit
985632d
·
verified ·
1 Parent(s): 85be50c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +70 -64
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Harmonies Game 3D</title>
7
  <style>
8
  body {
9
  margin: 0;
@@ -12,9 +12,23 @@
12
  canvas {
13
  display: block;
14
  }
 
 
 
 
 
 
 
 
 
 
15
  </style>
16
  </head>
17
  <body>
 
 
 
 
18
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
19
  <script>
20
  // Initialize scene, camera, and renderer
@@ -24,8 +38,8 @@
24
  renderer.setSize(window.innerWidth, window.innerHeight);
25
  document.body.appendChild(renderer.domElement);
26
 
27
- // Create the game board (grid of tiles)
28
- const boardSize = 6;
29
  const tileSize = 1;
30
  const tiles = [];
31
  const tileTypes = [
@@ -34,6 +48,11 @@
34
  { type: 'grass', color: 0x98fb98 }
35
  ];
36
 
 
 
 
 
 
37
  for (let x = 0; x < boardSize; x++) {
38
  for (let z = 0; z < boardSize; z++) {
39
  const tileType = tileTypes[Math.floor(Math.random() * tileTypes.length)];
@@ -44,6 +63,18 @@
44
  tile.userData = { type: tileType.type, occupied: false };
45
  scene.add(tile);
46
  tiles.push(tile);
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
  }
49
 
@@ -51,84 +82,59 @@
51
  const light = new THREE.AmbientLight(0xffffff, 0.8);
52
  scene.add(light);
53
 
54
- // Add animals
55
- const animalModels = {
56
- swan: { model: null, color: 0xffffff },
57
- deer: { model: null, color: 0x8b4513 },
58
- bear: { model: null, color: 0x000000 }
59
- };
60
-
61
- const animalCards = [
62
- { name: 'Swan', habitat: 'water', color: 0xffffff },
63
- { name: 'Deer', habitat: 'grass', color: 0x8b4513 },
64
- { name: 'Bear', habitat: 'forest', color: 0x000000 }
65
- ];
66
 
67
- const animalGeometry = new THREE.SphereGeometry(0.2, 32, 32);
 
 
 
 
 
 
68
 
69
- for (const animal in animalModels) {
70
- animalModels[animal].model = new THREE.Mesh(
71
- animalGeometry,
72
- new THREE.MeshBasicMaterial({ color: animalModels[animal].color })
73
- );
74
  }
75
 
76
- // Game state
77
- let currentPlayer = 1;
78
- const scores = { 1: 0, 2: 0 };
79
-
80
- // Handle mouse click events
81
- const raycaster = new THREE.Raycaster();
82
- const mouse = new THREE.Vector2();
83
 
84
- function onMouseClick(event) {
85
- mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
86
- mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
87
-
88
- raycaster.setFromCamera(mouse, camera);
89
- const intersects = raycaster.intersectObjects(tiles);
 
 
 
 
90
 
91
- if (intersects.length > 0) {
92
- const tile = intersects[0].object;
 
 
 
93
 
94
- if (tile.userData.occupied) {
95
- alert('This tile is already occupied!');
96
- return;
97
  }
98
-
99
- const selectedAnimal = animalCards[Math.floor(Math.random() * animalCards.length)];
100
-
101
- if (selectedAnimal.habitat !== tile.userData.type) {
102
- alert(`${selectedAnimal.name} cannot live on ${tile.userData.type} tile!`);
103
- return;
104
  }
105
-
106
- const animal = animalModels[selectedAnimal.name.toLowerCase()].model.clone();
107
- animal.position.copy(tile.position);
108
- animal.position.y += 0.2;
109
- scene.add(animal);
110
-
111
- tile.userData.occupied = true;
112
- scores[currentPlayer] += 5;
113
-
114
- switchPlayer();
115
- }
116
- }
117
-
118
- function switchPlayer() {
119
- currentPlayer = currentPlayer === 1 ? 2 : 1;
120
- alert(`Player ${currentPlayer}'s turn!`);
121
  }
122
 
123
- window.addEventListener('click', onMouseClick);
124
-
125
  // Set camera position
126
- camera.position.set(0, 5, 5);
127
  camera.lookAt(0, 0, 0);
128
 
129
  // Animation loop
130
  function animate() {
131
  requestAnimationFrame(animate);
 
132
  renderer.render(scene, camera);
133
  }
134
 
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Harmonies Game 3D - Dynamic Simulation</title>
7
  <style>
8
  body {
9
  margin: 0;
 
12
  canvas {
13
  display: block;
14
  }
15
+ .hud {
16
+ position: absolute;
17
+ top: 10px;
18
+ left: 10px;
19
+ background: rgba(0, 0, 0, 0.5);
20
+ color: white;
21
+ padding: 10px;
22
+ border-radius: 5px;
23
+ font-family: Arial, sans-serif;
24
+ }
25
  </style>
26
  </head>
27
  <body>
28
+ <div class="hud" id="hud">
29
+ <p>Current Type: <span id="currentType">Swan 🦢</span></p>
30
+ </div>
31
+
32
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
33
  <script>
34
  // Initialize scene, camera, and renderer
 
38
  renderer.setSize(window.innerWidth, window.innerHeight);
39
  document.body.appendChild(renderer.domElement);
40
 
41
+ // Game board parameters
42
+ const boardSize = 50; // Gigantic board
43
  const tileSize = 1;
44
  const tiles = [];
45
  const tileTypes = [
 
48
  { type: 'grass', color: 0x98fb98 }
49
  ];
50
 
51
+ // Particle system for motion simulation
52
+ const particleSystem = new THREE.Group();
53
+ scene.add(particleSystem);
54
+
55
+ // Create tiles and particles
56
  for (let x = 0; x < boardSize; x++) {
57
  for (let z = 0; z < boardSize; z++) {
58
  const tileType = tileTypes[Math.floor(Math.random() * tileTypes.length)];
 
63
  tile.userData = { type: tileType.type, occupied: false };
64
  scene.add(tile);
65
  tiles.push(tile);
66
+
67
+ // Add particles for motion simulation
68
+ const particleGeometry = new THREE.SphereGeometry(0.1, 16, 16);
69
+ const particleMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
70
+ const particle = new THREE.Mesh(particleGeometry, particleMaterial);
71
+ particle.position.set(
72
+ x - boardSize / 2 + Math.random(),
73
+ 0.2,
74
+ z - boardSize / 2 + Math.random()
75
+ );
76
+ particle.userData = { direction: new THREE.Vector3(Math.random(), 0, Math.random()).normalize() };
77
+ particleSystem.add(particle);
78
  }
79
  }
80
 
 
82
  const light = new THREE.AmbientLight(0xffffff, 0.8);
83
  scene.add(light);
84
 
85
+ // HUD for displaying the current type
86
+ const hud = document.getElementById('hud');
87
+ const currentTypeDisplay = document.getElementById('currentType');
 
 
 
 
 
 
 
 
 
88
 
89
+ // Current type with emoji
90
+ const animalTypes = [
91
+ { name: 'Swan', emoji: '🦢' },
92
+ { name: 'Deer', emoji: '🦌' },
93
+ { name: 'Bear', emoji: '🐻' }
94
+ ];
95
+ let currentTypeIndex = 0;
96
 
97
+ function updateCurrentType() {
98
+ currentTypeDisplay.textContent = `${animalTypes[currentTypeIndex].name} ${animalTypes[currentTypeIndex].emoji}`;
 
 
 
99
  }
100
 
101
+ updateCurrentType();
 
 
 
 
 
 
102
 
103
+ // Handle key presses to switch types
104
+ window.addEventListener('keydown', (event) => {
105
+ if (event.key === 'ArrowRight') {
106
+ currentTypeIndex = (currentTypeIndex + 1) % animalTypes.length;
107
+ updateCurrentType();
108
+ } else if (event.key === 'ArrowLeft') {
109
+ currentTypeIndex = (currentTypeIndex - 1 + animalTypes.length) % animalTypes.length;
110
+ updateCurrentType();
111
+ }
112
+ });
113
 
114
+ // Particle motion simulation
115
+ function updateParticles() {
116
+ particleSystem.children.forEach(particle => {
117
+ const direction = particle.userData.direction;
118
+ particle.position.add(direction.multiplyScalar(0.01));
119
 
120
+ // Bounce off edges of the board
121
+ if (particle.position.x < -boardSize / 2 || particle.position.x > boardSize / 2) {
122
+ direction.x = -direction.x;
123
  }
124
+ if (particle.position.z < -boardSize / 2 || particle.position.z > boardSize / 2) {
125
+ direction.z = -direction.z;
 
 
 
 
126
  }
127
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
 
 
130
  // Set camera position
131
+ camera.position.set(0, 50, 50);
132
  camera.lookAt(0, 0, 0);
133
 
134
  // Animation loop
135
  function animate() {
136
  requestAnimationFrame(animate);
137
+ updateParticles();
138
  renderer.render(scene, camera);
139
  }
140