add hover game scripts

This commit is contained in:
James B. Pollack 2016-06-06 09:12:07 -07:00
parent eb3cafb4f9
commit 3603c8cf2e
3 changed files with 165 additions and 0 deletions

View file

@ -0,0 +1,60 @@
(function() {
var _this;
HoverBall = function() {
_this = this;
}
var MIN_DISTANCE_THRESHOLD = 0.075;
var CENTER_POINT_LOCATION = {
x: 0,
y: 0,
z: 0
};
HoverBall.prototype = {
preload: function(entityID) {
this.entityID = entityID;
},
unload: function() {
},
startDistanceGrab: function() {
},
continueDistantGrab: function() {
var position = Entities.getEntityProperties(_this.entityID).position;
var distanceFromCenterPoint = Vec3.distance(position, CENTER_POINT_LOCATION);
if (distanceFromCenterPoint < MIN_DISTANCE_THRESHOLD) {
_this.turnOnGlow();
} else {
_this.turnOffGlow();
}
},
releaseGrab: function() {
_this.turnOffGlow();
},
turnOnGlow: function() {
},
turnOffGlow: function() {
},
findHoverContainer: function() {
var position = Entities.getEntityProperties(_this.entityID).position;
var results = Entities.findEntities(position, 3);
results.forEach(function(item) {
var props = Entities.getEntityProperties(item);
if (props.name.indexOf('hoverGame_container') > -1) {
return item
}
})
},
}
return new HoverBall();
})

View file

@ -0,0 +1,28 @@
(function() {
HoverContainer = function() {
}
HoverContainer.prototype = {
preload: function(entityID) {
this.entityID = entityID;
var data = {
action: 'add',
id: this.entityID
};
Messages.sendLocalMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data))
},
unload: function() {
var data = {
action: 'remove',
id: this.entityID
};
Messages.sendLocalMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data))
}
}
return new HoverContainer();
})

View file

@ -0,0 +1,77 @@
// createPingPongGun.js
//
// Script Type: Entity Spawner
// Created by James B. Pollack on 9/30/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script creates a gun that shoots ping pong balls when you pull the trigger on a hand controller.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
HoverGame = function(spawnPosition, spawnRotation) {
var scriptURL = "atp:/hoverGame/hoverInner.js";
var hoverContainerProps = {
type: 'Model',
modelURL: 'atp:/hoverGame/hover.fbx',
name: 'home_model_hoverGame_container',
dimensions: {
x: 0.2543,
y: 0.3269,
z: 0.4154
},
compoundShapeURL: 'atp:/hoverGame/hoverHull.obj',
rotation: spawnRotation,
script: scriptURL,
userData: JSON.stringify({
"grabbableKey": {
"grabbable":false
},
'hifiHomeKey': {
'reset': true
}
}),
dynamic: true,
position: spawnPosition
};
var hoverBall = {
type: 'Sphere',
name: 'home_model_hoverGame_sphere',
dimensions: {
x: 0.25,
y: 0.25,
z: 0.25,
},
compoundShapeURL: 'atp:/hoverGame/hoverHull.obj',
rotation: spawnRotation,
script: scriptURL,
userData: JSON.stringify({
'hifiHomeKey': {
'reset': true
}
}),
dynamic: true,
gravity:{
x:0,
y:-9.8,
z:0
},
position: spawnPosition
};
var hoverContainer = Entities.addEntity(hoverContainerProps);
function cleanup() {
print('HOVER GAME CLEANUP!')
Entities.deleteEntity(hoverInner);
}
this.cleanup = cleanup;
print('HOME CREATED HOVER GAME')
}