interactive objects integration
This commit is contained in:
@@ -3,25 +3,28 @@ import Utils from "@/lib/Utils";
|
||||
|
||||
const defaults = {
|
||||
arrows:{
|
||||
r: len => ({ type: 'image', value: '/static/textures/arrow.png', position:[-.5,.44,len+.96], rotation:[0,Math.PI, 0], scale: [0.03, 0.03, 0.03] }),
|
||||
l: len => ({ type: 'image', value: '/static/textures/arrow.png', position:[.5,.44,len+.96], rotation:[0,Math.PI, Math.PI], scale: [0.03, 0.03, 0.03] }),
|
||||
f: len => ({ type: 'image', value: '/static/textures/arrow.png', position:[0,.7,len+.96], rotation:[0,Math.PI, Math.PI/2], scale: [0.03, 0.03, 0.03] })
|
||||
r: len => ({ type: 'Image', value: '/static/textures/arrow.png', position:[-.5,.44,len+.96], rotation:[0,Math.PI, 0], scale: [0.03, 0.03, 0.03] }),
|
||||
l: len => ({ type: 'Image', value: '/static/textures/arrow.png', position:[.5,.44,len+.96], rotation:[0,Math.PI, Math.PI], scale: [0.03, 0.03, 0.03] }),
|
||||
f: len => ({ type: 'Image', value: '/static/textures/arrow.png', position:[0,.7,len+.96], rotation:[0,Math.PI, Math.PI/2], scale: [0.03, 0.03, 0.03] })
|
||||
},
|
||||
answers:{
|
||||
r: (len, text) => ({ type: 'text', width:0.5, text, fontSize:0.025, position:[-.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
l: (len, text) => ({ type: 'text', width:0.5, text, fontSize:0.025, position:[.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
f: (len, text) => ({ type: 'text', width:0.5, text, fontSize:0.025, position:[0,.55,len+.9], rotation:[0,Math.PI, 0] })
|
||||
r: (len, text) => ({ type: 'Text', width:0.5, text, fontSize:0.025, position:[-.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
l: (len, text) => ({ type: 'Text', width:0.5, text, fontSize:0.025, position:[.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
f: (len, text) => ({ type: 'Text', width:0.5, text, fontSize:0.025, position:[0,.55,len+.9], rotation:[0,Math.PI, 0] })
|
||||
}
|
||||
}
|
||||
|
||||
const tl = 4;
|
||||
|
||||
class MazeQuizGame {
|
||||
constructor(engine, context, questions) {
|
||||
constructor(engine, data) {
|
||||
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.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;
|
||||
let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData,
|
||||
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
|
||||
let ud = {...ud1, ...ud2}
|
||||
if (ud?.finish){
|
||||
if (e.started){
|
||||
engine.dashboard.updateProgress(1)
|
||||
@@ -53,7 +56,7 @@ class MazeQuizGame {
|
||||
async load(){
|
||||
await this.mazeObject.load();
|
||||
this.object = this.mazeObject.object;
|
||||
return this.object;
|
||||
return this;
|
||||
}
|
||||
|
||||
generate(questions, qid = 0, len){
|
||||
@@ -63,7 +66,7 @@ class MazeQuizGame {
|
||||
userData: { finish: true },
|
||||
objects:[
|
||||
{
|
||||
type: 'gltf',
|
||||
type: 'Gltf',
|
||||
position:[0,.25,len + .52], scale: [0.037, 0.037, 0.037], rotation: [0, Math.PI/4, 0],
|
||||
value: '/static/meshes/award.glb'
|
||||
}
|
||||
@@ -83,12 +86,12 @@ class MazeQuizGame {
|
||||
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]
|
||||
type: 'Text', text: question.q, fontSize:0.033, width:0.5, position:[0,.33,len + .96], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
question.a.forEach((a, i)=>{
|
||||
question.a.filter(a=>!!a).forEach((a, i)=>{
|
||||
let d = directions[i];
|
||||
mo.objects.push(
|
||||
defaults.arrows[d](len),
|
||||
@@ -114,7 +117,7 @@ class MazeQuizGame {
|
||||
len: 2,
|
||||
objects:[
|
||||
{
|
||||
type: 'text', width:0.5, color:0xff0000, text: question.h, fontSize:0.033, position:[0,.44,2+.96], rotation:[0,Math.PI, 0]
|
||||
type: 'Text', width:0.5, color:0xff0000, text: question.h, fontSize:0.033, position:[0,.44,2+.96], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user