quiz game scoring system
This commit is contained in:
@@ -3,31 +3,32 @@ import { assignParams } from "@/lib/MeshUtils";
|
||||
|
||||
class ImageObject {
|
||||
constructor(engine, obj) {
|
||||
var t = new TextureLoader().setPath(obj.path).load(obj.value);
|
||||
//t.encoding = sRGBEncoding;
|
||||
var mp = {
|
||||
map: t,
|
||||
alphaTest: 0.5
|
||||
};
|
||||
if (obj.nm) {
|
||||
mp.normalMap = new TextureLoader().setPath(obj.path).load(obj.nm);
|
||||
}
|
||||
if (obj.em) {
|
||||
mp.emissiveMap = new TextureLoader().setPath(obj.path).load(obj.em);
|
||||
}
|
||||
if (obj.am) {
|
||||
mp.alphaMap = new TextureLoader().setPath(obj.path).load(obj.am);
|
||||
}
|
||||
obj.material && Object.assign(mp, obj.material);
|
||||
let geo = new PlaneGeometry(obj.width || 1, obj.height || 1);
|
||||
if (obj.uv) {
|
||||
var uvAttribute = geo.attributes.uv;
|
||||
for (var i = 0; i < uvAttribute.count; i++) {
|
||||
uvAttribute.setXY(i, obj.uv[2 * i], obj.uv[2 * i + 1]);
|
||||
return new Promise(async(resolve, reject)=>{
|
||||
var t = await engine.loadTexture(obj.value, obj.path)
|
||||
var mp = {
|
||||
map: t,
|
||||
alphaTest: 0.5
|
||||
};
|
||||
if (obj.nm) {
|
||||
mp.normalMap = new TextureLoader().setPath(obj.path).load(obj.nm);
|
||||
}
|
||||
}
|
||||
this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp));
|
||||
assignParams(this.object, obj);
|
||||
if (obj.em) {
|
||||
mp.emissiveMap = new TextureLoader().setPath(obj.path).load(obj.em);
|
||||
}
|
||||
if (obj.am) {
|
||||
mp.alphaMap = new TextureLoader().setPath(obj.path).load(obj.am);
|
||||
}
|
||||
obj.material && Object.assign(mp, obj.material);
|
||||
let geo = new PlaneGeometry(obj.width || 1, obj.height || 1);
|
||||
if (obj.uv) {
|
||||
var uvAttribute = geo.attributes.uv;
|
||||
for (var i = 0; i < uvAttribute.count; i++) {
|
||||
uvAttribute.setXY(i, obj.uv[2 * i], obj.uv[2 * i + 1]);
|
||||
}
|
||||
}
|
||||
this.object = new Mesh(geo, mp.metalness ? new MeshStandardMaterial(mp) : new MeshBasicMaterial(mp));
|
||||
resolve(this)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ class InteractiveObject extends EventDispatcher{
|
||||
this.source = gltf;
|
||||
break;
|
||||
|
||||
case 'Text':
|
||||
case 'Image':
|
||||
case 'TextObject':
|
||||
case 'ImageObject':
|
||||
case 'GenericObject':
|
||||
case 'CharacterObject':
|
||||
case 'VideoPlayer':
|
||||
|
||||
@@ -104,7 +104,7 @@ class MazeObject {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
//console.log('loadingggg', def.objects)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -104,6 +104,13 @@ class DashBoard {
|
||||
text.position.y = -0.33;
|
||||
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', ()=>{
|
||||
dash.quaternion.copy(engine.camera.quaternion)
|
||||
dash.position.copy(engine.camera.position)
|
||||
@@ -145,7 +152,8 @@ class DashBoard {
|
||||
|
||||
this.addPoints = function(p){
|
||||
points += p;
|
||||
console.log('adding points', p, points)
|
||||
pointsText.text = points;
|
||||
pointsText.sync();
|
||||
}
|
||||
|
||||
this.enable = ()=>{
|
||||
|
||||
Reference in New Issue
Block a user