refactoring
This commit is contained in:
@@ -1,16 +1,34 @@
|
||||
import { MazeObject } from "./MazeObject";
|
||||
import Utils from "@/lib/Utils";
|
||||
|
||||
const params = {
|
||||
scale: 5,
|
||||
wallSize: 5 * 1.2,
|
||||
tubeSize: 5 * 1.2,
|
||||
}
|
||||
|
||||
const imgParams = {
|
||||
type: 'Image',
|
||||
width: params.wallSize*0.033,
|
||||
height: params.wallSize*0.033,
|
||||
value: '/static/textures/arrow.png'
|
||||
}
|
||||
|
||||
const textParams = {
|
||||
type: 'Text', width:0.073 * params.wallSize,
|
||||
fontPath:'/static/fonts/Montserrat-Regular.ttf', fontSize:0.025
|
||||
}
|
||||
|
||||
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 => ({ position:[-.5,.44,len+.96], rotation:[0,Math.PI, 0], ...imgParams }),
|
||||
l: len => ({ position:[.5,.44,len+.96], rotation:[0,Math.PI, Math.PI], ...imgParams }),
|
||||
f: len => ({ position:[0,.7,len+.96], rotation:[0,Math.PI, Math.PI/2], ...imgParams })
|
||||
},
|
||||
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) => ({ ...textParams, text, position:[-.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
l: (len, text) => ({ ...textParams, text, position:[.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
|
||||
f: (len, text) => ({ ...textParams, text, position:[0,.55,len+.9], rotation:[0,Math.PI, 0] })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +39,7 @@ class MazeQuizGame {
|
||||
return new Promise(async (resolve, reject)=>{
|
||||
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions;
|
||||
let def = this.generate(questions);
|
||||
this.mazeObject = new MazeObject(engine, def)
|
||||
this.mazeObject = new MazeObject(engine, def, params)
|
||||
engine.addEventListener('collision', async e=>{
|
||||
let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData,
|
||||
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
|
||||
@@ -73,19 +91,13 @@ class MazeQuizGame {
|
||||
};
|
||||
len = len || Math.round(Math.random()*tl) + 2;
|
||||
|
||||
// let l = {
|
||||
// l: Math.round(Math.random()*tl) + 2,
|
||||
// r: Math.round(Math.random()*tl) + 2,
|
||||
// f: Math.round(Math.random()*tl/2) + 2
|
||||
// }
|
||||
|
||||
let directions = Utils.shuffleArray( ['l', 'r', 'f'] )
|
||||
|
||||
let mo = {
|
||||
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]
|
||||
...textParams, text: question.q, fontSize:0.033, position:[0,.33,len + .96], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -116,7 +128,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]
|
||||
...textParams, color:0xff0000, text: question.h, fontSize:0.033, position:[0,.44,2+.96], rotation:[0,Math.PI, 0]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -133,9 +145,8 @@ class MazeQuizGame {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return mo;
|
||||
}
|
||||
|
||||
}
|
||||
export {MazeQuizGame}
|
||||
export { MazeQuizGame }
|
||||
Reference in New Issue
Block a user