This commit is contained in:
2025-10-21 18:50:52 +03:00
parent 3ff60a1cf4
commit 8f817eee14
13 changed files with 157 additions and 100 deletions
@@ -1,9 +1,24 @@
import { MazeObject } from "./MazeObject";
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,.73,len+.96], rotation:[0,Math.PI, Math.PI/2], scale: [0.03, 0.03, 0.03] })
},
answers:{
r: (len, text) => ({ type: 'text', text, position:[-.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
l: (len, text) => ({ type: 'text', text, position:[.5,.3,len+.9], rotation:[0,Math.PI, 0] }),
f: (len, text) => ({ type: 'text', text, position:[0,.7,len+.9], rotation:[0,Math.PI, 0] })
}
}
const tl = 4;
class MazeQuizGame {
constructor(engine, context, questions) {
let def = this.generate(questions);
console.log(def)
this.mazeObject = new MazeObject(engine, def)
}
@@ -16,40 +31,65 @@ class MazeQuizGame {
generate(questions, idx = 0){
let cq = questions[idx]
if (!cq) return {};
let len = Math.round(Math.random()*4) + 2;
let lr = Math.round(Math.random()*4) + 2;
let lrv = Math.random() > 0.5;
return {
let 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
}
let directions = Utils.shuffleArray( ['l', 'r', 'f'] )
let mo = {
len,
objects:[
{
type: 'text', text: cq.s, position:[0,.4,len+.96], rotation:[0,Math.PI, 0]
},{
type: 'image', value: '/static/textures/arrow.png', position:[-.5,.44,len+.96], rotation:[0,Math.PI, 0], scale: [0.03, 0.03, 0.03]
},{
type: 'text', text: 'Вярно', position:[-.5,.3,len+.9], rotation:[0,Math.PI, 0]
},{
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]
},{
type: 'text', text: 'Невярно', position:[.5,.3,len+.9], rotation:[0,Math.PI, 0]
type: 'text', text: cq.q, position:[0,.4,len + .96], rotation:[0,Math.PI, 0]
}
],
[lrv?'r':'l']:{
len: 10 - lr,
[lrv?'l':'r']: {
len: lr,
objects:[
{
type: 'text', text: cq.h, position:[0,.44,lr+.96], rotation:[0,Math.PI, 0]
}
]
}
},
[lrv?'l':'r']:{
len: lr,
[lrv?'r':'l']: this.generate(questions, idx + 1)
}
]
}
cq.a.forEach((a, i)=>{
let d = directions[i];
mo.objects.push(
defaults.arrows[d](len),
defaults.answers[d](len, a)
)
let dd;
if (d == 'f'){
dd = l.l > l.r ? 'l' : 'r';
}else {
dd = d == 'l' ? 'r' : 'l'
}
if (i == 0){
mo[d] = {
len: l[d],
[dd]: this.generate(questions, idx + 1)
}
}else{
mo[d] = {
len: l[d],
[dd]: {
len: 8 - l[d],
objects:[
{
type: 'text', text: cq.h, position:[0,.44,8 - l[d]+.96], rotation:[0,Math.PI, 0]
}
]
}
}
}
if (d == 'f'){
let path = mo[d][dd];
mo[d][dd] = {
len: 1,
[dd == 'r' ? 'l' : 'r']: path
}
}
})
return mo;
}
}