quiz game scoring system

This commit is contained in:
2025-11-11 18:13:53 +02:00
parent 351c6097f3
commit b1312d9b54
5 changed files with 60 additions and 34 deletions
@@ -3,8 +3,8 @@ import { assignParams } from "@/lib/MeshUtils";
class ImageObject { class ImageObject {
constructor(engine, obj) { constructor(engine, obj) {
var t = new TextureLoader().setPath(obj.path).load(obj.value); return new Promise(async(resolve, reject)=>{
//t.encoding = sRGBEncoding; var t = await engine.loadTexture(obj.value, obj.path)
var mp = { var mp = {
map: t, map: t,
alphaTest: 0.5 alphaTest: 0.5
@@ -27,7 +27,8 @@ class ImageObject {
} }
} }
this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp)); this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp));
assignParams(this.object, obj); resolve(this)
})
} }
} }
@@ -57,8 +57,8 @@ class InteractiveObject extends EventDispatcher{
this.source = gltf; this.source = gltf;
break; break;
case 'Text': case 'TextObject':
case 'Image': case 'ImageObject':
case 'GenericObject': case 'GenericObject':
case 'CharacterObject': case 'CharacterObject':
case 'VideoPlayer': case 'VideoPlayer':
@@ -104,7 +104,7 @@ class MazeObject {
addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], offsetZ) addPhysics(def.matrix, [-tubeSize / 2, 0.6, offsetZ/2], offsetZ)
addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ) addRoom(['floor', 'door', def.r ? 'door' : 'wall', def.f ? 'door' : 'wall', def.l ? 'door' : 'wall'], def, offsetZ)
if (def.userData?.qid !== undefined || def.userData?.finish){ if (def.userData?.qid !== undefined || def.userData?.finish || def.userData?.corner){
addPhysics(def.matrix, [0,0,offsetZ + wallSize/2], { width: wallSize/2, height: wallSize/2, depth: wallSize/2}, 'side', true, def.userData) addPhysics(def.matrix, [0,0,offsetZ + wallSize/2], { width: wallSize/2, height: wallSize/2, depth: wallSize/2}, 'side', true, def.userData)
} }
//console.log('loadingggg', def.objects) //console.log('loadingggg', def.objects)
@@ -9,14 +9,15 @@ const params = {
} }
const imgParams = { const imgParams = {
type: 'Image', type: 'ImageObject',
width: params.wallSize*0.033, width: params.wallSize*0.033,
height: params.wallSize*0.033, height: params.wallSize*0.033,
value: '/static/textures/arrow.png' value: 'arrow.png',
path: '/static/textures/'
} }
const textParams = { const textParams = {
type: 'Text', width:0.073 * params.wallSize, type: 'TextObject', width:0.073 * params.wallSize,
fontPath:'/static/fonts/Montserrat-Regular.ttf', fontSize:0.025 fontPath:'/static/fonts/Montserrat-Regular.ttf', fontSize:0.025
} }
@@ -37,6 +38,7 @@ const tl = 4;
class MazeQuizGame extends EventDispatcher { class MazeQuizGame extends EventDispatcher {
constructor(engine, data) { constructor(engine, data) {
super();
data.noPhysics = true; data.noPhysics = true;
return new Promise(async (resolve, reject)=>{ return new Promise(async (resolve, reject)=>{
let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions; let questions = data.shuffle ? Utils.shuffleArray(data.questions) : data.questions;
@@ -46,7 +48,8 @@ class MazeQuizGame extends EventDispatcher {
let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData, let ud1 = engine.physics.world.getCollider(e.handle1)?.parent()?.userData,
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData; ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
let ud = {...ud1, ...ud2} let ud = {...ud1, ...ud2}
if (ud?.finish){ console.log('collision', ud)
if (ud.finish){
if (e.started){ if (e.started){
engine.dashboard.levelProgress.update(1) engine.dashboard.levelProgress.update(1)
engine.hero.animationsMap._idle = engine.hero.animationsMap.idle engine.hero.animationsMap._idle = engine.hero.animationsMap.idle
@@ -68,6 +71,18 @@ class MazeQuizGame extends EventDispatcher {
engine.dashboard.updateText(ud.question.q) engine.dashboard.updateText(ud.question.q)
engine.dashboard.levelProgress.update(ud.qid / questions.length) engine.dashboard.levelProgress.update(ud.qid / questions.length)
} }
if (ud.corner && e.started){
let q = ud.corner.question;
if (!q.pointsAdded){
if (!ud.corner.penalty){
q.pointsAdded = true;
engine.dashboard.addPoints(data.questionPoints - !!q.applyPenalty * data.questionPenalty)
}else{
q.applyPenalty = true;
}
}
}
//console.log(e, ud, engine.hero?.animationsMap); //console.log(e, ud, engine.hero?.animationsMap);
}) })
await this.mazeObject.load(); await this.mazeObject.load();
@@ -116,13 +131,13 @@ class MazeQuizGame extends EventDispatcher {
} }
if (i == 0){ if (i == 0){
mo[d] = { mo[d] = {
answer: i, userData: { corner: { question }},
len: 4, len: 4,
[dd]: this.generate(questions, qid + 1, 3) [dd]: this.generate(questions, qid + 1, 3)
} }
}else{ }else{
mo[d] = { mo[d] = {
userData: { question, qid, answer: i }, userData: { question, qid, answer: i, corner: { question, penalty: true } },
len: 4, len: 4,
[dd]: { [dd]: {
len: 2, len: 2,
@@ -140,8 +155,10 @@ class MazeQuizGame extends EventDispatcher {
let path = mo[d][dd]; let path = mo[d][dd];
mo[d][dd] = { mo[d][dd] = {
len: 1, len: 1,
userData: mo[d].userData,
[dd == 'r' ? 'l' : 'r']: path [dd == 'r' ? 'l' : 'r']: path
} }
delete mo[d].userData;
} }
} }
}) })
+9 -1
View File
@@ -104,6 +104,13 @@ class DashBoard {
text.position.y = -0.33; text.position.y = -0.33;
dash.add(text); dash.add(text);
const pointsText = new Text()
Object.assign(pointsText, {
text:``, fontSize: 0.044, font: '/static/fonts/Montserrat-Regular.ttf'
})
pointsText.position.set(0.88 * engine.aspect/2, 0.33, 0);
dash.add(pointsText);
engine.addEventListener('beforeRender', ()=>{ engine.addEventListener('beforeRender', ()=>{
dash.quaternion.copy(engine.camera.quaternion) dash.quaternion.copy(engine.camera.quaternion)
dash.position.copy(engine.camera.position) dash.position.copy(engine.camera.position)
@@ -145,7 +152,8 @@ class DashBoard {
this.addPoints = function(p){ this.addPoints = function(p){
points += p; points += p;
console.log('adding points', p, points) pointsText.text = points;
pointsText.sync();
} }
this.enable = ()=>{ this.enable = ()=>{