mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:58:08 +02:00
make blocky swipable
This commit is contained in:
parent
c7ae3396eb
commit
f1e826b305
4 changed files with 236 additions and 215 deletions
|
@ -200,11 +200,6 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"angularDamping": 0,
|
"angularDamping": 0,
|
||||||
"angularVelocity": {
|
|
||||||
"x": 0,
|
|
||||||
"y": -0.2617993950843811,
|
|
||||||
"z": 0
|
|
||||||
},
|
|
||||||
"collisionSoundURL": "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
"collisionSoundURL": "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
||||||
"created": "2016-05-09T19:30:40Z",
|
"created": "2016-05-09T19:30:40Z",
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
|
|
|
@ -46,213 +46,239 @@ var blocks = [
|
||||||
];
|
];
|
||||||
|
|
||||||
var arrangements = [{
|
var arrangements = [{
|
||||||
name: 'greenhenge',
|
name: 'greenhenge',
|
||||||
blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_YELLOW],
|
blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_YELLOW],
|
||||||
target: "atp:/blocky/newblocks1.json"
|
target: "atp:/blocky/newblocks1.json"
|
||||||
},
|
}, {
|
||||||
{
|
name: 'tallstuff',
|
||||||
name: 'tallstuff',
|
blocks: [BLOCK_RED, BLOCK_RED, BLOCK_RED],
|
||||||
blocks: [BLOCK_RED, BLOCK_RED, BLOCK_RED],
|
target: "atp:/blocky/newblocks2.json"
|
||||||
target: "atp:/blocky/newblocks2.json"
|
}, {
|
||||||
},
|
name: 'ostrich',
|
||||||
{
|
blocks: [BLOCK_RED, BLOCK_RED, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_NATURAL],
|
||||||
name: 'ostrich',
|
target: "atp:/blocky/newblocks5.json"
|
||||||
blocks: [BLOCK_RED, BLOCK_RED, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_NATURAL],
|
}, {
|
||||||
target: "atp:/blocky/newblocks5.json"
|
name: 'fourppl',
|
||||||
},
|
blocks: [BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL],
|
||||||
{
|
target: "atp:/blocky/newblocks3.json"
|
||||||
name: 'fourppl',
|
}, {
|
||||||
blocks: [BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_BLUE, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL, BLOCK_NATURAL],
|
name: 'frogguy',
|
||||||
target: "atp:/blocky/newblocks3.json"
|
blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_RED, BLOCK_RED, BLOCK_NATURAL, BLOCK_NATURAL],
|
||||||
},
|
target: "atp:/blocky/newblocks4.json"
|
||||||
{
|
}, {
|
||||||
name: 'frogguy',
|
name: 'dominoes',
|
||||||
blocks: [BLOCK_GREEN, BLOCK_GREEN, BLOCK_GREEN, BLOCK_YELLOW, BLOCK_RED, BLOCK_RED, BLOCK_NATURAL, BLOCK_NATURAL],
|
blocks: [BLOCK_RED, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW],
|
||||||
target: "atp:/blocky/newblocks4.json"
|
target: "atp:/blocky/arrangement6B.json"
|
||||||
},
|
}]
|
||||||
{
|
|
||||||
name: 'dominoes',
|
|
||||||
blocks: [BLOCK_RED, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW, BLOCK_YELLOW],
|
|
||||||
target: "atp:/blocky/arrangement6B.json"
|
|
||||||
}]
|
|
||||||
|
|
||||||
var PLAYABLE_BLOCKS_POSITION = {
|
var PLAYABLE_BLOCKS_POSITION = {
|
||||||
x: 1097.6,
|
x: 1097.6,
|
||||||
y: 460.5,
|
y: 460.5,
|
||||||
z: -66.22
|
z: -66.22
|
||||||
};
|
};
|
||||||
|
|
||||||
var TARGET_BLOCKS_POSITION = {
|
var TARGET_BLOCKS_POSITION = {
|
||||||
x: 1096.82,
|
x: 1096.82,
|
||||||
y: 460.5,
|
y: 460.5,
|
||||||
z: -67.689
|
z: -67.689
|
||||||
};
|
};
|
||||||
//#debug
|
//#debug
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
print('BLOCK ENTITY SCRIPT')
|
print('BLOCK ENTITY SCRIPT')
|
||||||
var _this;
|
var _this;
|
||||||
|
|
||||||
function Blocky() {
|
function Blocky() {
|
||||||
_this = this;
|
_this = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Blocky.prototype = {
|
||||||
|
busy: false,
|
||||||
|
debug: false,
|
||||||
|
playableBlocks: [],
|
||||||
|
targetBlocks: [],
|
||||||
|
preload: function(entityID) {
|
||||||
|
print('BLOCKY preload')
|
||||||
|
this.entityID = entityID;
|
||||||
|
Script.update.connect(_this.update);
|
||||||
|
},
|
||||||
|
|
||||||
|
createTargetBlocks: function(arrangement) {
|
||||||
|
var created = [];
|
||||||
|
print('BLOCKY create target blocks')
|
||||||
|
|
||||||
|
var created = [];
|
||||||
|
var success = Clipboard.importEntities(arrangement.target);
|
||||||
|
if (success === true) {
|
||||||
|
created = Clipboard.pasteEntities(TARGET_BLOCKS_POSITION)
|
||||||
|
print('created ' + created);
|
||||||
}
|
}
|
||||||
|
|
||||||
Blocky.prototype = {
|
this.targetBlocks = created;
|
||||||
debug: false,
|
print('BLOCKY TARGET BLOCKS:: ' + this.targetBlocks);
|
||||||
playableBlocks: [],
|
},
|
||||||
targetBlocks: [],
|
|
||||||
preload: function(entityID) {
|
|
||||||
print('BLOCKY preload')
|
|
||||||
this.entityID = entityID;
|
|
||||||
},
|
|
||||||
createTargetBlocks: function(arrangement) {
|
|
||||||
var created = [];
|
|
||||||
print('BLOCKY create target blocks')
|
|
||||||
|
|
||||||
var created = [];
|
createPlayableBlocks: function(arrangement) {
|
||||||
var success = Clipboard.importEntities(arrangement.target);
|
print('BLOCKY creating playable blocks' + arrangement.blocks.length);
|
||||||
if (success === true) {
|
arrangement.blocks.forEach(function(block) {
|
||||||
created = Clipboard.pasteEntities(TARGET_BLOCKS_POSITION)
|
print('BLOCKY in a block loop')
|
||||||
print('created ' + created);
|
var blockProps = {
|
||||||
}
|
name: "home_model_blocky_block",
|
||||||
|
type: 'Model',
|
||||||
this.targetBlocks = created;
|
collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
||||||
print('BLOCKY TARGET BLOCKS:: ' + this.targetBlocks);
|
dynamic: true,
|
||||||
},
|
collisionless: false,
|
||||||
createPlayableBlocks: function(arrangement) {
|
gravity: {
|
||||||
print('BLOCKY creating playable blocks' + arrangement.blocks.length);
|
x: 0,
|
||||||
arrangement.blocks.forEach(function(block) {
|
y: -9.8,
|
||||||
print('BLOCKY in a block loop')
|
z: 0
|
||||||
var blockProps = {
|
},
|
||||||
name: "home_model_blocky_block",
|
userData: JSON.stringify({
|
||||||
type: 'Model',
|
grabbableKey: {
|
||||||
collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
grabbable: true
|
||||||
dynamic: true,
|
},
|
||||||
collisionless: false,
|
hifiHomeKey: {
|
||||||
gravity: {
|
reset: true
|
||||||
x: 0,
|
|
||||||
y: -9.8,
|
|
||||||
z: 0
|
|
||||||
},
|
|
||||||
userData: JSON.stringify({
|
|
||||||
grabbableKey: {
|
|
||||||
grabbable: true
|
|
||||||
},
|
|
||||||
hifiHomeKey: {
|
|
||||||
reset: true
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
dimensions: block.dimensions,
|
|
||||||
modelURL: block.url,
|
|
||||||
shapeType: 'box',
|
|
||||||
velocity: {
|
|
||||||
x: 0,
|
|
||||||
y: -0.01,
|
|
||||||
z: 0,
|
|
||||||
},
|
|
||||||
position: PLAYABLE_BLOCKS_POSITION
|
|
||||||
}
|
}
|
||||||
var newBlock = Entities.addEntity(blockProps);
|
}),
|
||||||
print('BLOCKY made a playable block' + newBlock)
|
dimensions: block.dimensions,
|
||||||
_this.playableBlocks.push(newBlock);
|
modelURL: block.url,
|
||||||
print('BLOCKY pushing it into playable blocks');
|
shapeType: 'box',
|
||||||
})
|
velocity: {
|
||||||
|
x: 0,
|
||||||
print('BLOCKY after going through playable arrangement')
|
y: -0.01,
|
||||||
},
|
z: 0,
|
||||||
startNearTrigger: function() {
|
},
|
||||||
print('BLOCKY got a near trigger');
|
position: PLAYABLE_BLOCKS_POSITION
|
||||||
this.advanceRound();
|
|
||||||
},
|
|
||||||
advanceRound: function() {
|
|
||||||
print('BLOCKY advance round');
|
|
||||||
this.cleanup();
|
|
||||||
var arrangement = arrangements[Math.floor(Math.random() * arrangements.length)];
|
|
||||||
this.createTargetBlocks(arrangement);
|
|
||||||
|
|
||||||
if (this.debug === true) {
|
|
||||||
this.debugCreatePlayableBlocks();
|
|
||||||
} else {
|
|
||||||
this.createPlayableBlocks(arrangement);
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
findBlocks: function() {
|
|
||||||
var found = [];
|
|
||||||
var results = Entities.findEntities(MyAvatar.position, 10);
|
|
||||||
results.forEach(function(result) {
|
|
||||||
var properties = Entities.getEntityProperties(result);
|
|
||||||
print('got result props')
|
|
||||||
if (properties.name.indexOf('blocky_block') > -1) {
|
|
||||||
found.push(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return found;
|
|
||||||
},
|
|
||||||
|
|
||||||
cleanup: function() {
|
|
||||||
print('BLOCKY cleanup');
|
|
||||||
var blocks = this.findBlocks();
|
|
||||||
print('BLOCKY cleanup2' + blocks.length)
|
|
||||||
blocks.forEach(function(block) {
|
|
||||||
Entities.deleteEntity(block);
|
|
||||||
})
|
|
||||||
print('BLOCKY after find and delete')
|
|
||||||
this.targetBlocks.forEach(function(block) {
|
|
||||||
Entities.deleteEntity(block);
|
|
||||||
});
|
|
||||||
this.playableBlocks.forEach(function(block) {
|
|
||||||
Entities.deleteEntity(block);
|
|
||||||
});
|
|
||||||
this.targetBlocks = [];
|
|
||||||
this.playableBlocks = [];
|
|
||||||
},
|
|
||||||
debugCreatePlayableBlocks: function() {
|
|
||||||
print('BLOCKY debug create');
|
|
||||||
var howMany = 10;
|
|
||||||
var i;
|
|
||||||
for (i = 0; i < howMany; i++) {
|
|
||||||
var block = blocks[Math.floor(Math.random() * blocks.length)];
|
|
||||||
var blockProps = {
|
|
||||||
name: "home_model_blocky_block",
|
|
||||||
type: 'Model',
|
|
||||||
collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
|
||||||
dynamic: false,
|
|
||||||
collisionless: true,
|
|
||||||
// gravity: {
|
|
||||||
// x: 0,
|
|
||||||
// y: -9.8,
|
|
||||||
// z: 0
|
|
||||||
// },
|
|
||||||
userData: JSON.stringify({
|
|
||||||
grabbableKey: {
|
|
||||||
grabbable: true
|
|
||||||
},
|
|
||||||
hifiHomeKey: {
|
|
||||||
reset: true
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
dimensions: block.dimensions,
|
|
||||||
modelURL: block.url,
|
|
||||||
shapeType: 'box',
|
|
||||||
velocity: {
|
|
||||||
x: 0,
|
|
||||||
y: -0.01,
|
|
||||||
z: 0,
|
|
||||||
},
|
|
||||||
position: PLAYABLE_BLOCKS_POSITION
|
|
||||||
}
|
|
||||||
this.playableBlocks.push(Entities.addEntity(blockProps));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
unload: function() {
|
|
||||||
this.cleanup();
|
|
||||||
},
|
|
||||||
clickReleaseOnEntity: function() {
|
|
||||||
print('BLOCKY click')
|
|
||||||
this.startNearTrigger();
|
|
||||||
}
|
}
|
||||||
}
|
var newBlock = Entities.addEntity(blockProps);
|
||||||
|
print('BLOCKY made a playable block' + newBlock)
|
||||||
|
_this.playableBlocks.push(newBlock);
|
||||||
|
print('BLOCKY pushing it into playable blocks');
|
||||||
|
})
|
||||||
|
|
||||||
return new Blocky();
|
print('BLOCKY after going through playable arrangement')
|
||||||
})
|
},
|
||||||
|
|
||||||
|
startNearTrigger: function() {
|
||||||
|
print('BLOCKY got a near trigger');
|
||||||
|
this.advanceRound();
|
||||||
|
},
|
||||||
|
|
||||||
|
advanceRound: function() {
|
||||||
|
print('BLOCKY advance round');
|
||||||
|
this.busy = true;
|
||||||
|
this.cleanup();
|
||||||
|
var arrangement = arrangements[Math.floor(Math.random() * arrangements.length)];
|
||||||
|
this.createTargetBlocks(arrangement);
|
||||||
|
|
||||||
|
if (this.debug === true) {
|
||||||
|
this.debugCreatePlayableBlocks();
|
||||||
|
} else {
|
||||||
|
this.createPlayableBlocks(arrangement);
|
||||||
|
|
||||||
|
}
|
||||||
|
this.busy = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
findBlocks: function() {
|
||||||
|
var found = [];
|
||||||
|
var results = Entities.findEntities(MyAvatar.position, 10);
|
||||||
|
results.forEach(function(result) {
|
||||||
|
var properties = Entities.getEntityProperties(result);
|
||||||
|
print('got result props')
|
||||||
|
if (properties.name.indexOf('blocky_block') > -1) {
|
||||||
|
found.push(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return found;
|
||||||
|
},
|
||||||
|
|
||||||
|
cleanup: function() {
|
||||||
|
print('BLOCKY cleanup');
|
||||||
|
var blocks = this.findBlocks();
|
||||||
|
print('BLOCKY cleanup2' + blocks.length)
|
||||||
|
blocks.forEach(function(block) {
|
||||||
|
Entities.deleteEntity(block);
|
||||||
|
})
|
||||||
|
print('BLOCKY after find and delete')
|
||||||
|
this.targetBlocks.forEach(function(block) {
|
||||||
|
Entities.deleteEntity(block);
|
||||||
|
});
|
||||||
|
this.playableBlocks.forEach(function(block) {
|
||||||
|
Entities.deleteEntity(block);
|
||||||
|
});
|
||||||
|
this.targetBlocks = [];
|
||||||
|
this.playableBlocks = [];
|
||||||
|
},
|
||||||
|
|
||||||
|
debugCreatePlayableBlocks: function() {
|
||||||
|
print('BLOCKY debug create');
|
||||||
|
var howMany = 10;
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < howMany; i++) {
|
||||||
|
var block = blocks[Math.floor(Math.random() * blocks.length)];
|
||||||
|
var blockProps = {
|
||||||
|
name: "home_model_blocky_block",
|
||||||
|
type: 'Model',
|
||||||
|
collisionSoundURL: "atp:/kineticObjects/blocks/ToyWoodBlock.L.wav",
|
||||||
|
dynamic: false,
|
||||||
|
collisionless: true,
|
||||||
|
userData: JSON.stringify({
|
||||||
|
grabbableKey: {
|
||||||
|
grabbable: true
|
||||||
|
},
|
||||||
|
hifiHomeKey: {
|
||||||
|
reset: true
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
dimensions: block.dimensions,
|
||||||
|
modelURL: block.url,
|
||||||
|
shapeType: 'box',
|
||||||
|
velocity: {
|
||||||
|
x: 0,
|
||||||
|
y: -0.01,
|
||||||
|
z: 0,
|
||||||
|
},
|
||||||
|
position: PLAYABLE_BLOCKS_POSITION
|
||||||
|
}
|
||||||
|
this.playableBlocks.push(Entities.addEntity(blockProps));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unload: function() {
|
||||||
|
this.cleanup();
|
||||||
|
Script.update.disconnect(_this.update);
|
||||||
|
},
|
||||||
|
|
||||||
|
clickReleaseOnEntity: function() {
|
||||||
|
print('BLOCKY click')
|
||||||
|
this.startNearTrigger();
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function() {
|
||||||
|
if (this.busy === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var BEAM_TRIGGER_THRESHOLD = 0.075;
|
||||||
|
|
||||||
|
var BEAM_POSITION = {
|
||||||
|
x: 1098.5159,
|
||||||
|
y: 460.0490,
|
||||||
|
z: -66.3012
|
||||||
|
};
|
||||||
|
|
||||||
|
var leftHandPosition = MyAvatar.getLeftPalmPosition();
|
||||||
|
var rightHandPosition = MyAvatar.getRightPalmPosition();
|
||||||
|
|
||||||
|
var rightDistance = Vec3.distance(leftHandPosition, BEAM_POSITION)
|
||||||
|
var leftDistance = Vec3.distance(rightHandPosition, BEAM_POSITION)
|
||||||
|
|
||||||
|
if (rightDistance < BEAM_TRIGGER_THRESHOLD || leftDistance < BEAM_TRIGGER_THRESHOLD) {
|
||||||
|
_this.startNearTrigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Blocky();
|
||||||
|
})
|
|
@ -11,18 +11,18 @@
|
||||||
|
|
||||||
|
|
||||||
var RESETTER_POSITION = {
|
var RESETTER_POSITION = {
|
||||||
x: 1098.27,
|
x: 1098.5159,
|
||||||
y: 460.43,
|
y: 460.0490,
|
||||||
z: -66.15
|
z: -66.3012
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockyGame = function(spawnPosition, spawnRotation) {
|
BlockyGame = function(spawnPosition, spawnRotation) {
|
||||||
|
|
||||||
var scriptURL ="atp:/blocky/blocky.js";
|
var scriptURL = "atp:/blocky/blocky.js";
|
||||||
|
|
||||||
var blockyProps = {
|
var blockyProps = {
|
||||||
type: 'Box',
|
type: 'Box',
|
||||||
name:'home_box_blocky_resetter',
|
name: 'home_box_blocky_resetter',
|
||||||
color: {
|
color: {
|
||||||
red: 0,
|
red: 0,
|
||||||
green: 0,
|
green: 0,
|
||||||
|
@ -33,6 +33,7 @@ BlockyGame = function(spawnPosition, spawnRotation) {
|
||||||
y: 0.25,
|
y: 0.25,
|
||||||
z: 0.25
|
z: 0.25
|
||||||
},
|
},
|
||||||
|
rotation:Quat.fromPitchYawRollDegrees(-0.0029,32.9983,-0.0021),
|
||||||
script: scriptURL,
|
script: scriptURL,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
"grabbableKey": {
|
"grabbableKey": {
|
||||||
|
|
|
@ -330,7 +330,6 @@
|
||||||
y: 179.0293,
|
y: 179.0293,
|
||||||
z: 89.9698
|
z: 89.9698
|
||||||
});
|
});
|
||||||
print('home before cuckooClock')
|
|
||||||
|
|
||||||
var cuckooClock = new MyCuckooClock({
|
var cuckooClock = new MyCuckooClock({
|
||||||
x: 1105.5237,
|
x: 1105.5237,
|
||||||
|
@ -341,11 +340,11 @@
|
||||||
y: -57.0089,
|
y: -57.0089,
|
||||||
z: -0.0013
|
z: -0.0013
|
||||||
});
|
});
|
||||||
print('home after cuckooClock')
|
|
||||||
var blocky = new BlockyGame({
|
var blocky = new BlockyGame({
|
||||||
x: 1098.27,
|
x: 1098.5159,
|
||||||
y: 460.43,
|
y: 460.0490,
|
||||||
z: -66.15
|
z: -66.3012
|
||||||
})
|
})
|
||||||
|
|
||||||
print('HOME after creating scripted entities')
|
print('HOME after creating scripted entities')
|
||||||
|
|
Loading…
Reference in a new issue