diff --git a/index.html b/index.html index bd6ba01..1527232 100644 --- a/index.html +++ b/index.html @@ -3018,7 +3018,7 @@ AFRAME.registerComponent('collision-check-target', { radius = e.detail.els[0].getAttribute("radius") score += 1/radius setFeedbackHUD("hit" + radius + "target, score: "+score) - if (score > 20}{ + if (score > 20){ score = 20 setFeedbackHUD("you win") } @@ -3026,6 +3026,33 @@ AFRAME.registerComponent('collision-check-target', { } }); +let gatesToPass = ["gate1","gate2","gate3"] +let gatesPassed = [] +let firstGatePassed +let lapDurations = [] +AFRAME.registerComponent('gate-through', { + dependencies: ['raycaster'], + + init: function () { + this.el.addEventListener('raycaster-intersection', function (e) { + if (!firstGatePassed) firstGatePassed = +Date.now() + let gateId = e.target.parentElement.id + setFeedbackHUD("gate through "+ gateId) + e.target.parentElement.setAttribute("color", "orange") + gatesPassed.push(gateId) + if (gatesPassed.length >= gatesToPass.length && gatesPassed.slice(-gatesToPass.length).join() == gatesToPass.join()){ + lap = Date.now() - firstGatePassed + setFeedbackHUD("circuit done in "+(lap/1000).toFixed(2)+"s") + if (lapDurations.length && lap < lapDurations.sort()[0]) + setFeedbackHUD("fastest lap!") + lapDurations.push(lap) + gatesPassed = [] + firstGatePassed = null + } + }); + } +}); + // used for testing AFRAME.registerComponent('startfunctions', { init: function () { @@ -3064,10 +3091,10 @@ AFRAME.registerComponent('startfunctions', { - - + @@ -3076,6 +3103,16 @@ AFRAME.registerComponent('startfunctions', { + + + + + + + + + +