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
@@ -42,17 +42,65 @@ class MazeObject {
po.rigidBody.setRotation(quat, true)
}
function addRoom(elements, def, offsetZ){
// e = [
// o.floor.clone(),
// o.door.clone(),
// o[def.r ? 'door' : 'wall'].clone(),
// o[def.f ? 'door' : 'wall'].clone(),
// o[def.l ? 'door' : 'wall'].clone()
// ];
let e = elements.map(e=>o[e].clone())
e[0].position.set(0, 0, offsetZ + context.wallSize/2);
e[1].rotateY(_tf.rotation.b);
e[2].rotateY(_tf.rotation.r);
e[3].rotateY(_tf.rotation.f);
e[4].rotateY(_tf.rotation.l);
e[1].position.set(0, 0, offsetZ + 0);
e[2].position.set(-context.wallSize/2, 0, offsetZ + context.wallSize/2);
e[3].position.set(0, 0, offsetZ + context.wallSize);
e[4].position.set(context.wallSize/2, 0, offsetZ + context.wallSize/2);
if (elements[1] == 'wall'){
addPhysics(def.matrix, [0, 0, offsetZ], context.wallSize, 'front')
}
if (elements[2] == 'wall'){
addPhysics(def.matrix, [-context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
if (elements[3] == 'wall'){
addPhysics(def.matrix, [0, 0, offsetZ + context.wallSize], context.wallSize, 'front')
}
if (elements[4] == 'wall'){
addPhysics(def.matrix, [context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
e.forEach(g => {
g.applyMatrix4(def.matrix);
root.add(g);
});
}
this.mazeObject = function(def, room, step = 0) {
if (!def.matrix){
def.matrix = new Matrix4();
}
let offsetZ = 0, e;
def.len = def.len || 0;
// if (step == 0) {
// e = o.door.clone();
// e.rotateY(_tf.rotation.f);
// mazeMeshes.push(e);
// }
if (step == 0) {
// e = o.door.clone();
// e.rotateY(_tf.rotation.f);
// mazeMeshes.push(e);
addRoom(['floor', 'wall', 'wall', 'door', 'wall'], def, -context.wallSize)
}
for (let i = 0; i < def.len; i++) {
let t = o.tunnel.clone();
t.position.set(0, 0, i * context.tubeSize);
@@ -72,44 +120,7 @@ class MazeObject {
addPhysics(def.matrix, [context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
addPhysics(def.matrix, [-context.tubeSize / 2, 0.6, offsetZ/2], offsetZ)
e = [
o.floor.clone(),
o.door.clone(),
o[def.r ? 'door' : 'wall'].clone(),
o[def.f ? 'door' : 'wall'].clone(),
o[def.l ? 'door' : 'wall'].clone()
];
e[0].position.set(0, 0, offsetZ + context.wallSize/2);
e[1].rotateY(_tf.rotation.b);
e[2].rotateY(_tf.rotation.r);
e[3].rotateY(_tf.rotation.f);
e[4].rotateY(_tf.rotation.l);
e[1].position.set(0, 0, offsetZ + 0);
e[2].position.set(-context.wallSize/2, 0, offsetZ + context.wallSize/2);
e[3].position.set(0, 0, offsetZ + context.wallSize);
e[4].position.set(context.wallSize/2, 0, offsetZ + context.wallSize/2);
if (!def.r){
addPhysics(def.matrix, [-context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
if (!def.f){
addPhysics(def.matrix, [0, 0, offsetZ + context.wallSize], context.wallSize, 'front')
}
if (!def.l){
addPhysics(def.matrix, [context.wallSize/2, 0, offsetZ + context.wallSize/2], context.wallSize)
}
e.forEach(g => {
g.applyMatrix4(def.matrix);
root.add(g);
});
addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ)
def.objects && def.objects.forEach(async obj => {
obj.room = room;
@@ -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;
}
}
@@ -16,10 +16,10 @@ class TextObject {
txt.anchorY = 'bottom';
txt.curveRadius = 0;
txt.outlineColor = 0xffffff;
txt.outlineWidth = '1%';
txt.outlineWidth = '15%';
txt.depthOffset = 0.1;
//txt.outlineBlur = '50%';
txt.color = new Color(0xffffff);
txt.color = new Color(0x0);
assignParams(txt, obj)
let m = new MeshStandardMaterial({
roughness: .73,
@@ -15,7 +15,7 @@
<script>
import Utils from '@/lib/utils';
import Utils from '@/lib/Utils';
export default {
emits:['target', 'preview'],