diff --git a/index.html b/index.html new file mode 100755 index 0000000..f935c1c --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + Semplice Island FPS + + + +
+ titolo +
+
ISTRUZIONI
+
Clicca per giocare
+
+
+
+
Rifiuti: 0
+
Tempo: XX:XX
+ + + + \ No newline at end of file diff --git a/models/rifiuto.glb b/models/rifiuto.glb new file mode 100755 index 0000000..410584e Binary files /dev/null and b/models/rifiuto.glb differ diff --git a/progetto/TODO.txt b/progetto/TODO.txt new file mode 100755 index 0000000..12e65a1 --- /dev/null +++ b/progetto/TODO.txt @@ -0,0 +1 @@ +TODO: \ No newline at end of file diff --git a/progetto/idea gioco.drawio b/progetto/idea gioco.drawio new file mode 100755 index 0000000..09a02d2 --- /dev/null +++ b/progetto/idea gioco.drawio @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/progetto/idea gioco.png b/progetto/idea gioco.png new file mode 100755 index 0000000..f3f1df4 Binary files /dev/null and b/progetto/idea gioco.png differ diff --git a/progetto/progetto.txt b/progetto/progetto.txt new file mode 100755 index 0000000..4e4d7f7 --- /dev/null +++ b/progetto/progetto.txt @@ -0,0 +1,6 @@ +posizioni: 20 posizioni predefinite scelte random +tempo 1° fase: 1m +tempo 2° fase: 5s * punteggio +schermata iniziale: click + controlli + bckg trailer (loop video) + titolo +schermata intermedia: istruzioni +schermata finale: punteggio finale + record + classifica(?) \ No newline at end of file diff --git a/progetto/schermata iniziale.png b/progetto/schermata iniziale.png new file mode 100755 index 0000000..fc24ac4 Binary files /dev/null and b/progetto/schermata iniziale.png differ diff --git a/script.js b/script.js new file mode 100755 index 0000000..0ae1e99 --- /dev/null +++ b/script.js @@ -0,0 +1,87 @@ +import * as THREE from 'three'; +import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js'; +import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; + +// 1. SCENA E CAMERA +const scene = new THREE.Scene(); +scene.background = new THREE.Color(0x87ceeb); +const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); +const renderer = new THREE.WebGLRenderer(); +renderer.setSize(window.innerWidth, window.innerHeight); +document.body.appendChild(renderer.domElement); +window.addEventListener('resize', function () { + renderer.setSize(window.innerWidth, window.innerHeight) +}) + +// 2. LUCI E AMBIENTE +scene.add(new THREE.AmbientLight(0xffffff, 1)); +const island = new THREE.Mesh(new THREE.CircleGeometry(20, 32), new THREE.MeshStandardMaterial({ color: 0x4df556 })); // #4df555 +island.rotation.x = -Math.PI / 2; +scene.add(island); + +// 3. CONTROLLI +function lock() { + document.getElementById('start').style.display = 'none'; + document.getElementById('punti').style.display = 'block'; + document.getElementById('tempo').style.display = 'block'; +} +function unlock() { + document.getElementById('start').style.display = 'flex'; + document.getElementById('punti').style.display = 'none'; + document.getElementById('tempo').style.display = 'none'; +} +const controls = new PointerLockControls(camera, document.body); +document.getElementById('start').addEventListener('click', () => controls.lock()); +controls.addEventListener('lock', lock); +controls.addEventListener('unlock', unlock); + +// 4. GESTIONE RIFIUTI (20 pezzi) +const trashArray = []; +let score = 0; +const loader = new GLTFLoader(); + +loader.load('models/rifiuto.glb', (gltf) => { + const mesh = gltf.scene.getObjectByName("Trash_Pile_03_GEO"); + mesh.geometry.center(); // Centra l'oggetto per collisioni precise + for (let i = 0; i < 20; i++) { + const clone = mesh.clone(); + scene.add(clone); + trashArray.push(clone); + spawn(clone); + } +}); + +function spawn(obj) { + const a = Math.random() * Math.PI * 2; + const r = Math.random() * 18; + obj.position.set(Math.cos(a) * r, 0.3, Math.sin(a) * r); +} + +// 5. MOVIMENTO E COLLISIONI +const keys = {}; +document.onkeydown = (e) => keys[e.code] = true; +document.onkeyup = (e) => keys[e.code] = false; + +function animate() { + requestAnimationFrame(animate); + if (controls.isLocked) { + if (keys['KeyW']) controls.moveForward(0.15); + if (keys['KeyS']) controls.moveForward(-0.15); + if (keys['KeyA']) controls.moveRight(-0.15); + if (keys['KeyD']) controls.moveRight(0.15); + camera.position.y = 1.6; + + // Controllo collisioni + const pPos = camera.position.clone(); + pPos.y -= 1.0; + trashArray.forEach(t => { + if (new THREE.Box3().setFromObject(t).expandByScalar(0.3).containsPoint(pPos)) { + score++; + document.getElementById('score').innerText = score; + spawn(t); + } + }); + } + renderer.render(scene, camera); +} +animate(); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100755 index 0000000..6b93027 --- /dev/null +++ b/style.css @@ -0,0 +1,41 @@ +:root { + --top: 10px; + --border: 20px; + --text: 1.5rem; +} +body { + margin: 0; + overflow: hidden; + font-family: sans-serif; +} +#punti { + position: absolute; + top: var(--top); + left: var(--border); + color: white; + font-size: var(--text); + pointer-events: none; + display: none; +} +#tempo { + position: absolute; + top: var(--top); + right: var(--border); + color: white; + font-size: var(--text); + pointer-events: none; + display: none; +} +#start { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0,0,0,0.5); + color: white; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; +} \ No newline at end of file diff --git a/textures/rifiuto/Trash_AlbedoTransparency.png b/textures/rifiuto/Trash_AlbedoTransparency.png new file mode 100755 index 0000000..2ca6634 Binary files /dev/null and b/textures/rifiuto/Trash_AlbedoTransparency.png differ diff --git a/textures/rifiuto/Trash_Ambient_Occlusion.png b/textures/rifiuto/Trash_Ambient_Occlusion.png new file mode 100755 index 0000000..2ca6634 Binary files /dev/null and b/textures/rifiuto/Trash_Ambient_Occlusion.png differ diff --git a/textures/rifiuto/Trash_MetallicSmoothness.png b/textures/rifiuto/Trash_MetallicSmoothness.png new file mode 100755 index 0000000..7fd18e3 Binary files /dev/null and b/textures/rifiuto/Trash_MetallicSmoothness.png differ diff --git a/textures/rifiuto/Trash_Normal.png b/textures/rifiuto/Trash_Normal.png new file mode 100755 index 0000000..1d6da08 Binary files /dev/null and b/textures/rifiuto/Trash_Normal.png differ diff --git a/textures/rifiuto/Trash_Roughness.png b/textures/rifiuto/Trash_Roughness.png new file mode 100755 index 0000000..74acbac Binary files /dev/null and b/textures/rifiuto/Trash_Roughness.png differ