From 3603c8cf2ec2d0067dc22112203563e88d7ae983 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 6 Jun 2016 09:12:07 -0700 Subject: [PATCH] add hover game scripts --- .../DomainContent/Home/hoverGame/hoverBall.js | 60 +++++++++++++++ .../Home/hoverGame/hoverContainer.js | 28 +++++++ .../DomainContent/Home/hoverGame/wrapper.js | 77 +++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 unpublishedScripts/DomainContent/Home/hoverGame/hoverBall.js create mode 100644 unpublishedScripts/DomainContent/Home/hoverGame/hoverContainer.js create mode 100644 unpublishedScripts/DomainContent/Home/hoverGame/wrapper.js diff --git a/unpublishedScripts/DomainContent/Home/hoverGame/hoverBall.js b/unpublishedScripts/DomainContent/Home/hoverGame/hoverBall.js new file mode 100644 index 0000000000..b4072d4b69 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/hoverGame/hoverBall.js @@ -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(); + +}) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/hoverGame/hoverContainer.js b/unpublishedScripts/DomainContent/Home/hoverGame/hoverContainer.js new file mode 100644 index 0000000000..3391879793 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/hoverGame/hoverContainer.js @@ -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(); + +}) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/hoverGame/wrapper.js b/unpublishedScripts/DomainContent/Home/hoverGame/wrapper.js new file mode 100644 index 0000000000..d38d4d47c3 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/hoverGame/wrapper.js @@ -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') + +} \ No newline at end of file