382 lines
11 KiB
JavaScript
382 lines
11 KiB
JavaScript
//
|
|
// whackAMole/createWhackAMoleConsole.js
|
|
//
|
|
// Created by Thijs Wenker on 8/29/16.
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
var constants = Script.require('./constants.js');
|
|
var helpers = Script.require('./helpers.js');
|
|
|
|
// TEST_MODE it bound to DEBUG mode for now.
|
|
var TEST_MODE = constants.DEBUG;
|
|
|
|
var READOUT_PLAYER_ONE_LEFT = 0;
|
|
var READOUT_PLAYER_ONE_RIGHT = 1;
|
|
var READOUT_PLAYER_TWO_LEFT = 2;
|
|
var READOUT_PLAYER_TWO_RIGHT = 3;
|
|
var NUMBER_OF_READOUTS = 4;
|
|
var ENABLE_COIN_SLOT = false;
|
|
|
|
|
|
function createConsole(transform) {
|
|
var entityProperties = {
|
|
position: {
|
|
x: 0.0,
|
|
y: 0.0,
|
|
z: -1.0
|
|
},
|
|
dimensions: {
|
|
x: 0.83636653423309326,
|
|
y: 1.6340843439102173,
|
|
z: 1.1064004898071289
|
|
},
|
|
modelURL: helpers.getModelURL('wam_console_7.fbx'),
|
|
name: 'Whack a mole - Console',
|
|
type: 'Model',
|
|
userData: JSON.stringify({
|
|
whackAMole: {
|
|
masterVolume: 1.0
|
|
}
|
|
}),
|
|
script: Script.resolvePath('whackAMoleConsoleEntity.js'),
|
|
serverScripts: Script.resolvePath('whackAMoleConsoleES.js')
|
|
};
|
|
return helpers.createEntity(entityProperties, transform);
|
|
}
|
|
|
|
function createBlinkingText(wamConsole) {
|
|
var entityProperties = {
|
|
animation: {
|
|
firstFrame: 55,
|
|
fps: 6,
|
|
running: 1,
|
|
url: helpers.getModelURL('wam_Blinky_Text_noBinormals.fbx')
|
|
},
|
|
dimensions: {
|
|
x: 0.72638344764709473,
|
|
y: 0.95610815286636353,
|
|
z: 0.16568982601165771
|
|
},
|
|
modelURL: helpers.getModelURL('wam_Blinky_Text_noBinormals.fbx'),
|
|
name: 'wam-Blinky Text',
|
|
parentID: wamConsole.id,
|
|
position: {
|
|
x: 0.016573669388890266,
|
|
y: 0.45618551969528198,
|
|
z: -0.27032655477523804
|
|
},
|
|
rotation: {
|
|
w: 1,
|
|
x: -1.52587890625e-05,
|
|
y: -1.52587890625e-05,
|
|
z: -1.52587890625e-05
|
|
},
|
|
type: 'Model'
|
|
};
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
|
|
function createDigitalReadout(wamConsole, id) {
|
|
var isPlayerOne = id === READOUT_PLAYER_ONE_LEFT || id === READOUT_PLAYER_ONE_RIGHT;
|
|
var model = helpers.getModelURL(isPlayerOne ? 'digitBox_BLUE_V2.fbx' : 'digitBox_RED_V2.fbx');
|
|
var entityProperties = {
|
|
animation: {
|
|
currentFrame: 0,
|
|
fps: 8,
|
|
lastFrame: 11,
|
|
running: true,
|
|
url: model
|
|
},
|
|
|
|
modelURL: model,
|
|
name: 'wam-readout_' + (id + 1),
|
|
|
|
type: 'Model'
|
|
};
|
|
switch (id) {
|
|
case READOUT_PLAYER_ONE_LEFT:
|
|
entityProperties.position = {
|
|
x: -0.39989519119262695,
|
|
y: 0.96664208173751831,
|
|
z: -0.41372117400169373
|
|
};
|
|
entityProperties.rotation = {
|
|
w: 1,
|
|
x: -1.52587890625e-05,
|
|
y: -1.52587890625e-05,
|
|
z: -1.52587890625e-05
|
|
};
|
|
entityProperties.dimensions = {
|
|
x: 0.18993330001831055,
|
|
y: 0.32326388359069824,
|
|
z: 0.22765985131263733
|
|
};
|
|
break;
|
|
case READOUT_PLAYER_ONE_RIGHT:
|
|
entityProperties.position = {
|
|
x: -0.19996488094329834,
|
|
y: 0.94903564453125,
|
|
z: -0.37536010146141052
|
|
};
|
|
entityProperties.rotation = {
|
|
w: 0.9856259822845459,
|
|
x: -0.013565242290496826,
|
|
y: -0.13878083229064941,
|
|
z: -0.095109462738037109
|
|
};
|
|
entityProperties.dimensions = {
|
|
x: 0.18985645473003387,
|
|
y: 0.32313311100006104,
|
|
z: 0.22756774723529816
|
|
};
|
|
break;
|
|
case READOUT_PLAYER_TWO_LEFT:
|
|
entityProperties.position = {
|
|
x: 0.19998270273208618,
|
|
y: 0.940826416015625,
|
|
z: -0.41379457712173462
|
|
};
|
|
entityProperties.rotation = {
|
|
w: 1,
|
|
x: -1.52587890625e-05,
|
|
y: -1.52587890625e-05,
|
|
z: -1.52587890625e-05
|
|
};
|
|
entityProperties.dimensions = {
|
|
x: 0.18993330001831055,
|
|
y: 0.32326388359069824,
|
|
z: 0.22765985131263733
|
|
};
|
|
break;
|
|
case READOUT_PLAYER_TWO_RIGHT:
|
|
entityProperties.position = {
|
|
x: 0.3999653160572052,
|
|
y: 0.94903570413589478,
|
|
z: -0.37539303302764893
|
|
};
|
|
entityProperties.rotation = {
|
|
w: 0.9856259822845459,
|
|
x: -0.013565242290496826,
|
|
y: -0.13878083229064941,
|
|
z: -0.095109462738037109
|
|
};
|
|
entityProperties.dimensions = {
|
|
x: 0.18985645473003387,
|
|
y: 0.32313311100006104,
|
|
z: 0.22756774723529816
|
|
};
|
|
break;
|
|
}
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
|
|
function createTarget(wamConsole) {
|
|
var entityProperties = {
|
|
animation: {
|
|
fps: 8,
|
|
lastFrame: 128,
|
|
running: 1,
|
|
url: helpers.getModelURL('wam_target_noBinormals.fbx')
|
|
},
|
|
dimensions: {
|
|
x: 0.71503448486328125,
|
|
y: 0.71442329883575439,
|
|
z: 0.084382906556129456
|
|
},
|
|
modelURL: helpers.getModelURL('wam_target_noBinormals.fbx'),
|
|
name: 'wam-signtarget',
|
|
position: {
|
|
x: 0.012882668524980545,
|
|
y: 0.38965654373168945,
|
|
z: -0.25231426954269409
|
|
},
|
|
rotation: {
|
|
w: 1,
|
|
x: -1.52587890625e-05,
|
|
y: -1.52587890625e-05,
|
|
z: -1.52587890625e-05
|
|
},
|
|
type: 'Model'
|
|
};
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
|
|
function createMole(wamConsole, x, y, collider) {
|
|
var entityProperties = {
|
|
dimensions: {
|
|
x: 0.14389017224311829,
|
|
y: 0.17452259361743927,
|
|
z: 0.13297519087791443
|
|
},
|
|
modelURL: helpers.getModelURL('moleRig_Opt.fbx'),
|
|
name: constants.MOLE_IDENTIFIER_PREFIX + (x + 1) + '_' + (y + 1),
|
|
position: {
|
|
x: -0.25 + (0.25 * x),
|
|
y: -0.28051349520683289,
|
|
z: -0.125 + (0.25 * y)
|
|
},
|
|
rotation: {
|
|
w: 1,
|
|
x: -1.52587890625e-05,
|
|
y: -1.52587890625e-05,
|
|
z: -1.52587890625e-05
|
|
},
|
|
type: 'Model',
|
|
userData: JSON.stringify({
|
|
whackAMole: {
|
|
colliderID: collider.id
|
|
}
|
|
})
|
|
};
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
|
|
function createHoleCollider(wamConsole, x, y) {
|
|
var entityProperties = {
|
|
dimensions: {
|
|
x: 0.14389017224311829,
|
|
y: 0.17452259361743927,
|
|
z: 0.13297519087791443
|
|
},
|
|
name: constants.MOLE_COLLIDER_PREFIX + (x + 1) + '_' + (y + 1),
|
|
visible: false,
|
|
position: {
|
|
x: -0.25 + (0.25 * x),
|
|
y: -0.10051349520683289,
|
|
z: -0.125 + (0.25 * y)
|
|
},
|
|
type: 'Sphere'
|
|
};
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
function createCoinSlot(wamConsole) {
|
|
var entityProperties = {
|
|
dimensions: {
|
|
x: 0.63820791244506836,
|
|
y: 0.39726802706718445,
|
|
z: 0.14158163964748383
|
|
},
|
|
modelURL: Script.resolvePath('coinBox/models/newCoinSlot.fbx'),
|
|
position: {
|
|
x: -0.084594681859016418,
|
|
y: -0.37774658203125,
|
|
z: 0.50634002685546875
|
|
},
|
|
type: 'Model',
|
|
script: Script.resolvePath('coinBox/carnivalCoinBoxEntity.js'),
|
|
userData: JSON.stringify({
|
|
grabbableKey: {
|
|
wantsTrigger: true
|
|
}
|
|
})
|
|
};
|
|
return helpers.createEntity(entityProperties, wamConsole);
|
|
}
|
|
|
|
function createCoinCollider(coinSlot) {
|
|
var entityProperties = {
|
|
dimensions: {
|
|
x: 0.2,
|
|
y: 0.2,
|
|
z: 0.2
|
|
},
|
|
name: 'coin_collider',
|
|
visible: false,
|
|
position: {
|
|
x: 0.1345946818590164,
|
|
y: 0.00274658203125,
|
|
z: -0.00634002685546875
|
|
},
|
|
type: 'Sphere'
|
|
};
|
|
return helpers.createEntity(entityProperties, coinSlot);
|
|
}
|
|
|
|
function createMallet(parent, left, consoleEntityID) {
|
|
var position = {
|
|
x: (left ? -1.0 : 1.0) * 0.5242646932601929,
|
|
y: 0.12,
|
|
z: -0.16840522289276123
|
|
};
|
|
var rotation = Quat.fromPitchYawRollDegrees(-45, 0, 0);
|
|
var entityProperties = {
|
|
collisionsWillMove: true,
|
|
compoundShapeURL: helpers.getModelURL('mallet_phys.obj'),
|
|
dimensions: {
|
|
x: 0.24804636836051941,
|
|
y: 0.53404051065444946,
|
|
z: 0.24767011404037476
|
|
},
|
|
gravity: {
|
|
x: 0,
|
|
y: -9.8,
|
|
z: 0
|
|
},
|
|
modelURL: helpers.getModelURL(left ? 'wam_mallet_blue_emissive.fbx' : 'wam_mallet_red_emissive.fbx'),
|
|
name: 'Whack a mole - Mallet',
|
|
position: position,
|
|
rotation: rotation,
|
|
shapeType: 'compound',
|
|
type: 'Model',
|
|
collidesWith: "static,dynamic,kinematic,",
|
|
collisionMask: 7,
|
|
script: Script.resolvePath('whackAMoleMalletEntity.js')
|
|
};
|
|
|
|
var mallet = helpers.createEntity(entityProperties, parent);
|
|
Entities.editEntity(mallet.id, {
|
|
userData: JSON.stringify({
|
|
grabbableKey: {
|
|
cloneable: true,
|
|
cloneLifetime: 20,
|
|
cloneLimit: 2,
|
|
cloneDynamic: true
|
|
},
|
|
whackAMole: {
|
|
consoleEntityID: consoleEntityID,
|
|
player: left ? constants.PLAYER_ONE : constants.PLAYER_TWO
|
|
}
|
|
})
|
|
});
|
|
|
|
return mallet;
|
|
}
|
|
|
|
var console = createConsole({
|
|
position: MyAvatar.position,
|
|
rotation: MyAvatar.orientation
|
|
});
|
|
createBlinkingText(console);
|
|
createTarget(console);
|
|
|
|
for (var i = 0; i < NUMBER_OF_READOUTS; i++) {
|
|
createDigitalReadout(console, i);
|
|
}
|
|
|
|
if (ENABLE_COIN_SLOT) {
|
|
createCoinCollider(createCoinSlot(console));
|
|
}
|
|
|
|
var MOLE_GRID_SIZE = {x: 3, y: 3};
|
|
for (var x = 0; x < MOLE_GRID_SIZE.x; x++) {
|
|
for (var y = 0; y < MOLE_GRID_SIZE.y; y++) {
|
|
var collider = createHoleCollider(console, x, y);
|
|
var mole = createMole(console, x, y, collider);
|
|
}
|
|
}
|
|
|
|
createMallet(console, true, console.id);
|
|
createMallet(console, false, console.id);
|
|
|
|
if (TEST_MODE) {
|
|
Script.scriptEnding.connect(function() {
|
|
// should only have to delete the parent entity
|
|
Entities.deleteEntity(console.id);
|
|
});
|
|
} else {
|
|
Script.stop();
|
|
}
|