diff --git a/src/assets/sfx/quack.mp3 b/src/assets/sfx/quack.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..5c9d5c87de7cc144af2afe5175151cf0c89ecff1 Binary files /dev/null and b/src/assets/sfx/quack.mp3 differ diff --git a/src/assets/sfx/specialquack.mp3 b/src/assets/sfx/specialquack.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..ac461e6c916fc2cb86230d66661c8316bd415fbb Binary files /dev/null and b/src/assets/sfx/specialquack.mp3 differ diff --git a/src/components/duck.js b/src/components/duck.js index 50f24de70f4a74855d5346d3bc543c1f765b7eb0..0b9a1c4721b51b8da2ff488fcd188c9fb9f87069 100644 --- a/src/components/duck.js +++ b/src/components/duck.js @@ -12,14 +12,18 @@ AFRAME.registerComponent("duck", { this.force = new CANNON.Vec3(0, this.data.initialForce, 0); this.initialScale = this.el.object3D.scale.x; this.maxScale = this.data.maxScale * this.initialScale; + + this._handleGrabStart = this._handleGrabStart.bind(this); }, play: function() { this.system.addComponent(this); + this.el.addEventListener("grab-start", this._handleGrabStart); }, pause: function() { this.system.removeComponent(this); + this.el.removeEventListener("grab-start", this._handleGrabStart); }, beforeStep: function() { @@ -36,5 +40,14 @@ AFRAME.registerComponent("duck", { this.el.body.applyForce(this.force, this.position); } } + }, + + _handleGrabStart: function() { + const rand = Math.floor(Math.random() * Math.floor(100)); + if (rand < 1) { + this.el.emit("specialquack"); + } else if (rand < 20) { + this.el.emit("quack"); + } } }); diff --git a/src/components/quack.js b/src/components/quack.js new file mode 100644 index 0000000000000000000000000000000000000000..e97b6f8f1bf5cfccd2efab3dcc4f486d09c2330d --- /dev/null +++ b/src/components/quack.js @@ -0,0 +1,27 @@ +AFRAME.registerComponent("quack", { + schema: { + quackPercentage: { default: 1 }, + specialQuackPercentage: { default: 0.01 } + }, + + init: function() { + this._handleGrabStart = this._handleGrabStart.bind(this); + }, + + play: function() { + this.el.addEventListener("grab-start", this._handleGrabStart); + }, + + pause: function() { + this.el.removeEventListener("grab-start", this._handleGrabStart); + }, + + _handleGrabStart: function() { + const rand = Math.random(); + if (rand < this.data.specialQuackPercentage) { + this.el.emit("specialquack"); + } else if (rand < this.data.quackPercentage) { + this.el.emit("quack"); + } + } +}); diff --git a/src/components/super-spawner.js b/src/components/super-spawner.js index 27fee415c1b3735e43bae322f78a2b631e657633..41e2d7aeabbe77f2dc0ba9b3821170fab9724db5 100644 --- a/src/components/super-spawner.js +++ b/src/components/super-spawner.js @@ -10,6 +10,7 @@ AFRAME.registerComponent("super-spawner", { init: function() { this.entities = new Map(); this.timeout = null; + this.defaultScale = this.el.getAttribute("scale").clone(); }, play: function() { @@ -23,6 +24,7 @@ AFRAME.registerComponent("super-spawner", { clearTimeout(this.timeout); this.timeout = null; this.el.setAttribute("visible", true); + this.el.setAttribute("scale", this.defaultScale); }, remove: function() { @@ -63,8 +65,10 @@ AFRAME.registerComponent("super-spawner", { if (this.data.spawnCooldown > 0) { this.el.setAttribute("visible", false); + this.el.setAttribute("scale", { x: 0.0001, y: 0.0001, z: 0.0001 }); this.timeout = setTimeout(() => { this.el.setAttribute("visible", true); + this.el.setAttribute("scale", this.defaultScale); this.timeout = null; }, this.data.spawnCooldown * 1000); } diff --git a/src/hub.html b/src/hub.html index a3c2379d51cb5a1dc92f1db11479873a5d210632..f70734cccf20bd158b9782bfe9df6f1a8474e919 100644 --- a/src/hub.html +++ b/src/hub.html @@ -63,6 +63,9 @@ <a-asset-item id="watch-model" response-type="arraybuffer" src="./assets/hud/watch.glb"></a-asset-item> <a-asset-item id="interactable-duck" response-type="arraybuffer" src="./assets/interactables/duck/DuckyMesh.glb"></a-asset-item> + <a-asset-item id="quack" src="./assets/sfx/quack.mp3" response-type="arraybuffer" preload="auto"></a-asset-item> + <a-asset-item id="specialquack" src="./assets/sfx/specialquack.mp3" response-type="arraybuffer" preload="auto"></a-asset-item> + <img id="water-normal-map" src="./assets/waternormals.jpg"> <!-- Templates --> @@ -193,6 +196,9 @@ position="2.9 1.2 0" body="mass: 0; type: static; shape: box;" collision-filter="collisionForces: false;" + quack + sound__quack="src: #quack; on: quack; poolSize: 2;" + sound__specialquack="src: #specialquack; on: specialquack;" ></a-entity> <a-entity @@ -337,31 +343,11 @@ </template> <template data-selector=".LeftHand"> - <a-entity bone-visibility> - <!-- <a-entity - id="left-super-hand" - event-repeater=" - events: action_grab, action_release, action_primary_down, action_primary_up; - eventSource: #player-left-controller" - static-body="shape: sphere; sphereRadius: 0.02" - mixin="super-hands" - position="0 0.05 0" - ></a-entity> --> - </a-entity> + <a-entity bone-visibility></a-entity> </template> <template data-selector=".RightHand"> - <a-entity bone-visibility> -<!-- <a-entity - id="right-super-hand" - event-repeater=" - events: action_grab, action_release, action_primary_down, action_primary_up; - eventSource: #player-right-controller" - static-body="shape: sphere; sphereRadius: 0.02" - mixin="super-hands" - position="0 -0.05 0" - ></a-entity> --> - </a-entity> + <a-entity bone-visibility></a-entity> </template> </a-entity> diff --git a/src/hub.js b/src/hub.js index fb04f61961c62e38ef4a9c440729212c978130aa..24f1b9d665457fe5fe5242e004d9835b17d0f0a4 100644 --- a/src/hub.js +++ b/src/hub.js @@ -93,6 +93,7 @@ import "./components/super-spawner"; import "./components/event-repeater"; import "./components/controls-shape-offset"; import "./components/duck"; +import "./components/quack"; import "./components/cursor-controller";