From fa10d07e737abb781dd89a5bbdfbb55f1fc57969 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Mon, 10 Apr 2023 12:03:51 +0200 Subject: [PATCH] example with lifepoints --- index.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 88092b4..5a14356 100644 --- a/index.html +++ b/index.html @@ -2985,11 +2985,22 @@ AFRAME.registerComponent('collision-check', { dependencies: ['raycaster'], init: function () { + let lifePoints = 10 this.el.addEventListener('raycaster-intersection', function (e) { color = e.detail.els[0].getAttribute("color") let rig = document.getElementById("rig").getAttribute("position") - if (color == "red") - rig.z += .5 + if (color == "red"){ + rig.z += .5 // very naive, could instead take the opposite direction, lerping away + setFeedbackHUD("wall hit" + " " + --lifePoints + "<3") + if (lifePoints < 1) { + lifePoints = 10 + setFeedbackHUD("dead, respawing") + rig.set(0,0,0) // really origin? + } + } + if (color == "green"){ + setFeedbackHUD("bonus" + " " + lifePoints++ + "<3") + } }); } }); @@ -3034,7 +3045,7 @@ AFRAME.registerComponent('startfunctions', { - +