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
@@ -9,14 +9,15 @@ const params = {
}
const imgParams = {
type: 'Image',
type: 'ImageObject',
width: params.wallSize*0.033,
height: params.wallSize*0.033,
value: '/static/textures/arrow.png'
value: 'arrow.png',
path: '/static/textures/'
}
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
}
@@ -37,6 +38,7 @@ const tl = 4;
class MazeQuizGame extends EventDispatcher {
constructor(engine, data) {
super();
data.noPhysics = true;
return new Promise(async (resolve, reject)=>{
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,
ud2 = engine.physics.world.getCollider(e.handle2)?.parent()?.userData;
let ud = {...ud1, ...ud2}
if (ud?.finish){
console.log('collision', ud)
if (ud.finish){
if (e.started){
engine.dashboard.levelProgress.update(1)
engine.hero.animationsMap._idle = engine.hero.animationsMap.idle
@@ -68,6 +71,18 @@ class MazeQuizGame extends EventDispatcher {
engine.dashboard.updateText(ud.question.q)
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);
})
await this.mazeObject.load();
@@ -116,13 +131,13 @@ class MazeQuizGame extends EventDispatcher {
}
if (i == 0){
mo[d] = {
answer: i,
userData: { corner: { question }},
len: 4,
[dd]: this.generate(questions, qid + 1, 3)
}
}else{
mo[d] = {
userData: { question, qid, answer: i },
userData: { question, qid, answer: i, corner: { question, penalty: true } },
len: 4,
[dd]: {
len: 2,
@@ -140,8 +155,10 @@ class MazeQuizGame extends EventDispatcher {
let path = mo[d][dd];
mo[d][dd] = {
len: 1,
userData: mo[d].userData,
[dd == 'r' ? 'l' : 'r']: path
}
delete mo[d].userData;
}
}
})