Skip to content

Commit 01e8cd8

Browse files
committed
Test peer.js
1 parent 05016f7 commit 01e8cd8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer
66
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
77
import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPass.js";
88
import { isMobile } from "./device";
9+
import { Match } from "./game/match";
910

1011
// Required for Github Pages deployment
1112
THREE.DefaultLoadingManager.setURLModifier((url) => {
@@ -100,6 +101,11 @@ const oddMat = new THREE.MeshStandardMaterial({
100101

101102
// === Scene setup ===
102103
async function init() {
104+
const game = isMobile() ? await Match.join() : await Match.host();
105+
game.onAction = (data) => { currentTarget = new THREE.Vector3(-4 + Math.random() * 8, currentTarget?.y, -4 + Math.random() * 8) };
106+
window.addEventListener('pagehide', () => game.dispose(), { once: true });
107+
window.addEventListener('beforeunload', () => game.dispose(), { once: true });
108+
103109
const tileSrc = (await loadGLB("/models/box.glb")).children[0] as THREE.Mesh;
104110
const tileGeometry = (tileSrc.geometry as THREE.BufferGeometry).clone();
105111
tileGeometry.computeBoundingBox();
@@ -209,6 +215,7 @@ async function init() {
209215
const intersects = raycaster.intersectObjects(tiles, false);
210216

211217
if (intersects.length > 0) {
218+
game.play({ type: 'Move' });
212219
const picked = intersects[0]?.object as THREE.Mesh;
213220
currentTarget = picked.getWorldPosition(new THREE.Vector3());
214221
currentTarget.x += 0.4;

0 commit comments

Comments
 (0)