mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 10:02:24 +02:00
Add launcher to tower defense
This commit is contained in:
parent
fa2fc83d38
commit
44389bcad6
4 changed files with 114 additions and 0 deletions
BIN
unpublishedScripts/tower-defense/assets/air_gun_1_converted.wav
Normal file
BIN
unpublishedScripts/tower-defense/assets/air_gun_1_converted.wav
Normal file
Binary file not shown.
BIN
unpublishedScripts/tower-defense/assets/block.fbx
Normal file
BIN
unpublishedScripts/tower-defense/assets/block.fbx
Normal file
Binary file not shown.
35
unpublishedScripts/tower-defense/createLauncher.js
Normal file
35
unpublishedScripts/tower-defense/createLauncher.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
function findSurfaceBelowPosition(pos) {
|
||||
var result = Entities.findRayIntersection({
|
||||
origin: pos,
|
||||
direction: { x: 0, y: -1, z: 0 }
|
||||
});
|
||||
if (result.intersects) {
|
||||
return result.intersection;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
LAUNCHER_DIMENSIONS = {
|
||||
x: 0.5,
|
||||
y: 0.5,
|
||||
z: 0.5
|
||||
}
|
||||
|
||||
createLauncherAtMyAvatar = function() {
|
||||
var launcherPos = Vec3.sum(MyAvatar.position, Vec3.multiply(10, Quat.getFront(MyAvatar.orientation)));
|
||||
launcherPos = findSurfaceBelowPosition(launcherPos);
|
||||
launcherPos.y += LAUNCHER_DIMENSIONS.y / 2;
|
||||
createLaucnher(launcherPos);
|
||||
}
|
||||
|
||||
createLauncher = function(position) {
|
||||
Entities.addEntity({
|
||||
position: position,
|
||||
type: "Model",
|
||||
type: "Box",
|
||||
//modelURL: 'http://hifi-content.s3.amazonaws.com/alan/dev/EZ-Tube.fbx',
|
||||
//compoundShapeURL: 'http://hifi-content.s3.amazonaws.com/alan/dev/EZ-Tube3.obj',
|
||||
//shapeType: 'compound'
|
||||
dimensions: LAUNCHER_DIMENSIONS,
|
||||
script: Script.resolvePath("launch.js")
|
||||
});
|
||||
}
|
79
unpublishedScripts/tower-defense/launch.js
Normal file
79
unpublishedScripts/tower-defense/launch.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// cylinderBlock.js
|
||||
//
|
||||
// Created by David Rowe on 25 Oct 2016.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This script displays a progress download indicator when downloads are in progress.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function () {
|
||||
|
||||
var BLOCK_MODEL_URL = Script.resolvePath("assets/block.fbx");
|
||||
var BLOCK_DIMENSIONS = {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
};
|
||||
var BLOCK_LIFETIME = 10;
|
||||
|
||||
var MUZZLE_SOUND_URL = Script.resolvePath("air_gun_1_converted.wav");
|
||||
var MUZZLE_SOUND_VOLUME = 0.5;
|
||||
var MUZZLE_SPEED = 6.0; // m/s
|
||||
var MUZZLE_ANGLE = 5.0; // Degrees off-center to discourage blocks falling back inside cylinder.
|
||||
var muzzleSound;
|
||||
|
||||
var cylinderID;
|
||||
|
||||
this.preload = function (entityID) {
|
||||
print("launch.js | preload");
|
||||
cylinderID = entityID;
|
||||
muzzleSound = SoundCache.getSound(MUZZLE_SOUND_URL);
|
||||
}
|
||||
|
||||
this.launchBlock = function () {
|
||||
var cylinder = Entities.getEntityProperties(cylinderID, ["position", "rotation", "dimensions"]);
|
||||
var muzzlePosition = Vec3.sum(cylinder.position,
|
||||
Vec3.multiplyQbyV(cylinder.rotation, { x: 0.0, y: 0.5 * (cylinder.dimensions.y + BLOCK_DIMENSIONS.y), Z: 0.0 }));
|
||||
var muzzleVelocity = Vec3.multiply(MUZZLE_SPEED, Vec3.UNIT_Y);
|
||||
muzzleVelocity = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(MUZZLE_ANGLE, 0.0, 0.0), muzzleVelocity);
|
||||
muzzleVelocity = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0.0, Math.random() * 360.0, 0.0), muzzleVelocity);
|
||||
muzzleVelocity = Vec3.multiplyQbyV(cylinder.rotation, muzzleVelocity);
|
||||
|
||||
Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: BLOCK_MODEL_URL,
|
||||
shapeType: "compound",
|
||||
//compoundShapeURL: BLOCK_COMPOUND_SHAPE_URL,
|
||||
dimensions: BLOCK_DIMENSIONS,
|
||||
dynamic: 1,
|
||||
gravity: { x: 0.0, y: -9.8, z: 0.0 },
|
||||
collisionsWillMove: 1,
|
||||
position: muzzlePosition,
|
||||
rotation: Quat.multiply(cylinder.rotation, Quat.fromPitchYawRollDegrees(0.0, Math.random() * 360.0, 0.0)),
|
||||
velocity: muzzleVelocity,
|
||||
lifetime: BLOCK_LIFETIME
|
||||
});
|
||||
|
||||
Audio.playSound(muzzleSound, {
|
||||
position: cylinder.muzzlePosition,
|
||||
orientation: cylinder.rotation,
|
||||
volume: MUZZLE_SOUND_VOLUME
|
||||
});
|
||||
}
|
||||
|
||||
this.clickDownOnEntity = function () {
|
||||
this.launchBlock();
|
||||
}
|
||||
|
||||
this.startNearTrigger = function () {
|
||||
this.launchBlock();
|
||||
}
|
||||
|
||||
this.startFarTrigger = function () {
|
||||
this.launchBlock();
|
||||
}
|
||||
})
|
Loading…
Reference in a new issue