finish events

This commit is contained in:
2025-10-29 13:34:54 +02:00
parent 93e03b4843
commit 127f71f345
8 changed files with 104 additions and 82 deletions
@@ -20,6 +20,24 @@ class MazeQuizGame {
constructor(engine, context, questions) {
let def = this.generate(questions);
this.mazeObject = new MazeObject(engine, def)
engine.addEventListener('collision', async e=>{
let ud = engine.phy.world.getCollider(e.handle2)?.parent()?.userData;
if (ud?.finish && engine.hero?.animationsMap?.win){
if (e.started){
engine.hero.animationsMap._idle = engine.hero.animationsMap.idle
engine.hero.animationsMap.idle = engine.hero.animationsMap.win
engine.hero.characterControls.cameraDelta = Math.PI;
await Utils.wait(1000);
engine.hero.characterControls.direction += Math.PI;
await Utils.wait(10000);
this.onfinish?.()
}else{
engine.hero.animationsMap.idle = engine.hero.animationsMap._idle
engine.hero.characterControls.cameraDelta = 0
}
}
//console.log(e, ud, engine.hero?.animationsMap);
})
}
async load(){
@@ -32,7 +50,7 @@ class MazeQuizGame {
let question = questions[qid]
if (!question) return {
len:3,
finish: true,
userData: { finish: true },
objects:[
{
type: 'gltf',
@@ -52,7 +70,7 @@ class MazeQuizGame {
let directions = Utils.shuffleArray( ['l', 'r', 'f'] )
let mo = {
len, question, qid,
len, userData: { question, qid },
objects:[
{
type: 'text', text: question.q, fontSize:0.033, width:0.5, position:[0,.33,len + .96], rotation:[0,Math.PI, 0]
@@ -74,11 +92,13 @@ class MazeQuizGame {
}
if (i == 0){
mo[d] = {
len: 3,
answer: i,
len: 4,
[dd]: this.generate(questions, qid + 1, 3)
}
}else{
mo[d] = {
userData: { question, qid, answer: i },
len: 4,
[dd]: {
len: 2,