mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 10:02:24 +02:00
Remove old tower defense game content
This commit is contained in:
parent
da2dd60bec
commit
d9861c2afd
11 changed files with 0 additions and 805 deletions
Binary file not shown.
Binary file not shown.
|
@ -1,28 +0,0 @@
|
|||
var BLOCK_MODEL_URL = Script.resolvePath("assets/block.fbx");
|
||||
var BLOCK_DIMENSIONS = {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
};
|
||||
var BLOCK_LIFETIME = 120;
|
||||
|
||||
getBlockProperties = function() {
|
||||
return {
|
||||
type: "Model",
|
||||
name: "TD.block",
|
||||
modelURL: BLOCK_MODEL_URL,
|
||||
shapeType: "compound",
|
||||
//compoundShapeURL: BLOCK_COMPOUND_SHAPE_URL,
|
||||
//userData: JSON.stringify({
|
||||
// grabbableKey: {
|
||||
// wantsTrigger: true
|
||||
// }
|
||||
//}),
|
||||
dimensions: BLOCK_DIMENSIONS,
|
||||
dynamic: 1,
|
||||
gravity: { x: 0.0, y: -9.8, z: 0.0 },
|
||||
collisionsWillMove: 1,
|
||||
lifetime: BLOCK_LIFETIME,
|
||||
script: Script.resolvePath("destructibleGrowableEntity.js")
|
||||
};
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
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")
|
||||
});
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function(oThis) {
|
||||
if (typeof this !== 'function') {
|
||||
// closest thing possible to the ECMAScript 5
|
||||
// internal IsCallable function
|
||||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1),
|
||||
fToBind = this,
|
||||
fNOP = function() {},
|
||||
fBound = function() {
|
||||
return fToBind.apply(this instanceof fNOP
|
||||
? this
|
||||
: oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
if (this.prototype) {
|
||||
// Function.prototype doesn't have a prototype property
|
||||
fNOP.prototype = this.prototype;
|
||||
}
|
||||
fBound.prototype = new fNOP();
|
||||
|
||||
return fBound;
|
||||
};
|
||||
}
|
||||
|
||||
function parseJSON(json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// The destructible entity is expected to have a few different properties:
|
||||
// It is a model
|
||||
// It has a set of "originalTextures" that follows the format:
|
||||
//
|
||||
// tex.health1: "atp:/..."
|
||||
// tex.health2: "atp:/..."
|
||||
// tex.health3: "atp:/..."
|
||||
// tex.health4: "atp:/..."
|
||||
// ...
|
||||
//
|
||||
// The model can have as many textures as you would like. Each time the entity
|
||||
// is hit, the next texture in the list will be set. If the entity is hit and
|
||||
// it is at the last texture, it will be destroyed. The first texture is always
|
||||
// tex.health1.
|
||||
|
||||
// This is the key used to set the current texture.
|
||||
var TEXTURE_NAME = "tex.health1";
|
||||
|
||||
(function() {
|
||||
Script.include("block.js");
|
||||
DestructibleBlock = function() {
|
||||
}
|
||||
DestructibleBlock.prototype = {
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
Script.addEventHandler(entityID, "collisionWithEntity", this.onCollide.bind(this));
|
||||
|
||||
this.entityIDsThatHaveCollidedWithMe = [];
|
||||
},
|
||||
onCollide: function(entityA, entityB, collision) {
|
||||
print("Collided with: ", entityB);
|
||||
var colliderName = Entities.getEntityProperties(entityB, 'name').name;
|
||||
|
||||
// If the other entity's name includes 'projectile' and we haven't hit it before,
|
||||
// continue on.
|
||||
print('len', this.entityIDsThatHaveCollidedWithMe.length);
|
||||
if (colliderName.indexOf("projectile") > -1
|
||||
&& this.entityIDsThatHaveCollidedWithMe.indexOf(entityB) === -1) {
|
||||
this.entityIDsThatHaveCollidedWithMe.push(entityB);
|
||||
this.decrementHealth();
|
||||
}
|
||||
},
|
||||
decrementHealth: function() {
|
||||
// FIXME This doesn't need to be recalculated, but it can't be done in preload
|
||||
// Textures stores a list of the texture paths that the model contains
|
||||
// The first texture indicates full_health, the next indicates full_health-1,
|
||||
// and so on and so forth.
|
||||
this.textures = [];
|
||||
var originalTextures = parseJSON(
|
||||
Entities.getEntityProperties(this.entityID, 'originalTextures').originalTextures);
|
||||
for (var i = 0;; ++i) {
|
||||
var nextTextureName = "tex.health" + (i + 1);
|
||||
if (nextTextureName in originalTextures) {
|
||||
print(i, originalTextures[nextTextureName]);
|
||||
this.textures.push(originalTextures[nextTextureName]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
print("Decrementing health");
|
||||
|
||||
var texturesJSON = Entities.getEntityProperties(this.entityID, 'textures').textures;
|
||||
var textures = parseJSON(texturesJSON);
|
||||
|
||||
var currentTextureIndex = 0;
|
||||
|
||||
if (textures === undefined) {
|
||||
print("ERROR (tdBlock.js) | Textures contains invalid json");
|
||||
} else {
|
||||
const currentTexture = textures[TEXTURE_NAME];
|
||||
|
||||
var found = false;
|
||||
|
||||
// Go through each of the known textures to see which is currently set
|
||||
for (var i = 0; i < this.textures.length; ++i) {
|
||||
print("tdBlock.js | Checking ", i, this.textures[i], currentTexture);
|
||||
if (this.textures[i].indexOf(currentTexture) > -1) {
|
||||
currentTextureIndex = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
print("ERROR (tdBlock.js) | Could not find current texture index");
|
||||
}
|
||||
}
|
||||
print("tdBlock.js | Current texture index is:", currentTextureIndex);
|
||||
|
||||
// FIXME DELETE ME
|
||||
if (currentTextureIndex === this.textures.length - 1) {
|
||||
//currentTextureIndex = -1;
|
||||
}
|
||||
|
||||
if (currentTextureIndex === this.textures.length - 1) {
|
||||
// We've reached the last texture, let's destroy the entity
|
||||
Entities.deleteEntity(this.entityID);
|
||||
print("tdBlock.js | Destroying entity");
|
||||
} else {
|
||||
var newTextures = {};
|
||||
newTextures[TEXTURE_NAME] = this.textures[currentTextureIndex + 1];
|
||||
var newTexturesJSON = JSON.stringify(newTextures);
|
||||
Entities.editEntity(this.entityID, { textures: newTexturesJSON });
|
||||
print("tdBlock.js | Setting texture to: ", newTexturesJSON);
|
||||
}
|
||||
},
|
||||
growBlock: function() {
|
||||
var props = getBlockProperties();
|
||||
props.position = Entities.getEntityProperties(this.entityID, 'position').position;
|
||||
props.position.y += props.dimensions.y;
|
||||
Entities.addEntity(props);
|
||||
},
|
||||
startDistanceGrab: function () {
|
||||
print("launch.js | got start distance grab");
|
||||
this.startGrabTime = Date.now();
|
||||
},
|
||||
releaseGrab: function() {
|
||||
print("launch.js | release grab");
|
||||
var grabbedForMs = Date.now() - this.startGrabTime;
|
||||
print("launch.js | grab time:", grabbedForMs);
|
||||
if (grabbedForMs < 300) {
|
||||
this.growBlock();
|
||||
}
|
||||
},
|
||||
clickDownOnEntity: function () {
|
||||
print("launch.js | got click down");
|
||||
this.growBlock();
|
||||
}
|
||||
};
|
||||
|
||||
return new DestructibleBlock();
|
||||
});
|
|
@ -1,77 +0,0 @@
|
|||
//
|
||||
// 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 () {
|
||||
|
||||
Script.include("block.js");
|
||||
|
||||
var BLOCK_MODEL_URL = Script.resolvePath("assets/block.fbx");
|
||||
var BLOCK_DIMENSIONS = {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 1
|
||||
};
|
||||
var BLOCK_LIFETIME = 120;
|
||||
|
||||
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 () {
|
||||
print("launch.js | Launching block");
|
||||
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);
|
||||
|
||||
var blockProperties = getBlockProperties();
|
||||
blockProperties.position = muzzlePosition;
|
||||
blockProperties.velocity = muzzleVelocity;
|
||||
blockProperties.rotation = Quat.multiply(cylinder.rotation, Quat.fromPitchYawRollDegrees(0.0, Math.random() * 360.0, 0.0));
|
||||
|
||||
Entities.addEntity(blockProperties);
|
||||
|
||||
Audio.playSound(muzzleSound, {
|
||||
position: cylinder.muzzlePosition,
|
||||
orientation: cylinder.rotation,
|
||||
volume: MUZZLE_SOUND_VOLUME
|
||||
});
|
||||
}
|
||||
|
||||
this.clickDownOnEntity = function () {
|
||||
print("launch.js | got click down");
|
||||
this.launchBlock();
|
||||
}
|
||||
|
||||
this.startNearTrigger = function () {
|
||||
print("launch.js | got start near trigger");
|
||||
this.launchBlock();
|
||||
}
|
||||
|
||||
this.startFarTrigger = function () {
|
||||
print("launch.js | got start far trigger");
|
||||
this.launchBlock();
|
||||
}
|
||||
})
|
|
@ -1,360 +0,0 @@
|
|||
//
|
||||
// towerDefense.js
|
||||
//
|
||||
// Created by Clement on 12/1/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
|
||||
//
|
||||
|
||||
print("============= Script Starting =============");
|
||||
|
||||
function findSurfaceBelowPosition(pos) {
|
||||
var result = Entities.findRayIntersection({
|
||||
origin: pos,
|
||||
direction: { x: 0, y: -1, z: 0 }
|
||||
});
|
||||
if (result.intersects) {
|
||||
return result.intersection;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
var GAME_STATES = {
|
||||
IDLE: 0,
|
||||
BUILD: 1,
|
||||
FIGHT: 2,
|
||||
GAMEOVER: 3,
|
||||
};
|
||||
|
||||
var BASE_POSITION = findSurfaceBelowPosition(MyAvatar.position);
|
||||
var BUILD_TIME_SECONDS = 60;
|
||||
var BUTTON_POSITION = { x: 0, y: 0, z: 0 };
|
||||
var BASES_SIZE = 15;
|
||||
var TARGET_SIZE = 2;
|
||||
var BASES_HEIGHT = 6;
|
||||
var BASES_TRANSPARENCY = 0.2;
|
||||
var BASES = [
|
||||
{
|
||||
position: { x: -15, y: 0, z: 0 },
|
||||
color: { red: 255, green: 0, blue: 0 },
|
||||
spawnerPosition: { x: -15 + BASES_SIZE/2, y: 0, z: -BASES_SIZE/2 },
|
||||
},
|
||||
{
|
||||
position: { x: 15, y: 0, z: 0 },
|
||||
color: { red: 0, green: 255, blue: 0 },
|
||||
spawnerPosition: { x: 15 - BASES_SIZE/2, y: 0, z: BASES_SIZE/2 },
|
||||
},
|
||||
{
|
||||
position: { x: 0, y: 0, z: -15 },
|
||||
color: { red: 0, green: 0, blue: 255 },
|
||||
spawnerPosition: { x: BASES_SIZE/2, y: 0, z: -15 + BASES_SIZE/2 },
|
||||
},
|
||||
{
|
||||
position: { x: 0, y: 0, z: 15 },
|
||||
color: { red: 255, green: 0, blue: 255 },
|
||||
spawnerPosition: { x: -BASES_SIZE/2, y: 0, z: 15 - BASES_SIZE/2 },
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
var CHANNEL_NAME = "tower-defense-" //+ Math.floor(Math.random() * 9999);
|
||||
print(CHANNEL_NAME);
|
||||
|
||||
var QUERY_RADIUS = 200;
|
||||
|
||||
var buttonID;
|
||||
var bases = [];
|
||||
var entityIDs = [];
|
||||
var spawnerIDs = [];
|
||||
|
||||
var teamEntities = {
|
||||
0: {},
|
||||
1: {},
|
||||
2: {},
|
||||
3: {},
|
||||
};
|
||||
|
||||
var currentState = GAME_STATES.IDLE;
|
||||
|
||||
Messages.subscribe(CHANNEL_NAME);
|
||||
|
||||
if (this.EntityViewer) {
|
||||
EntityViewer.setPosition(Vec3.sum(BASE_POSITION, BUTTON_POSITION));
|
||||
EntityViewer.setCenterRadius(QUERY_RADIUS);
|
||||
}
|
||||
|
||||
var BEGIN_BUILDING_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/letTheGamesBegin.wav"));
|
||||
var BEGIN_FIGHTING_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/fight.wav"));
|
||||
var GAME_OVER_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/gameOver.wav"));
|
||||
var TEN_SECONDS_REMAINING_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/tenSecondsRemaining.wav"));
|
||||
|
||||
setup();
|
||||
|
||||
|
||||
function setup() {
|
||||
var buttonProperties = {
|
||||
type: 'Box',
|
||||
name: 'TD.StartButton',
|
||||
position: Vec3.sum(BASE_POSITION, BUTTON_POSITION),
|
||||
dimensions: { x: 1, y: 1, z: 1 },
|
||||
color: { red: 0, green: 255, blue: 0 },
|
||||
script: Script.resolvePath("towerButton.js"),
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
wantsTrigger: true
|
||||
},
|
||||
gameChannel: CHANNEL_NAME
|
||||
}),
|
||||
}
|
||||
buttonID = Entities.addEntity(buttonProperties);
|
||||
|
||||
for (var i in BASES) {
|
||||
var position = Vec3.sum(BASE_POSITION, BASES[i].position);
|
||||
var arenaProperties = {
|
||||
name: 'TD.Arena',
|
||||
type: 'Box',
|
||||
position: position,
|
||||
registrationPoint: { x: 0.5, y: 0, z: 0.5 },
|
||||
dimensions: { x: BASES_SIZE, y: BASES_HEIGHT, z: BASES_SIZE },
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
script: Script.resolvePath("teamAreaEntity.js"),
|
||||
visible: false,
|
||||
collisionless: true,
|
||||
userData: JSON.stringify({
|
||||
gameChannel: CHANNEL_NAME,
|
||||
})
|
||||
};
|
||||
// Base block
|
||||
var arenaID = Entities.addEntity(arenaProperties)
|
||||
bases.push(arenaID);
|
||||
teamEntities[i].arenaID = arenaID;
|
||||
|
||||
|
||||
const ROOF_HEIGHT = 0.2;
|
||||
position.y += BASES_HEIGHT - ROOF_HEIGHT;
|
||||
var roofProperties = {
|
||||
name: 'TD.Roof',
|
||||
type: 'Box',
|
||||
position: position,
|
||||
registrationPoint: { x: 0.5, y: 0, z: 0.5 },
|
||||
dimensions: { x: BASES_SIZE, y: ROOF_HEIGHT, z: BASES_SIZE },
|
||||
color: BASES[i].color,
|
||||
script: Script.resolvePath('roofEntity.js'),
|
||||
userData: JSON.stringify({
|
||||
gameChannel: CHANNEL_NAME,
|
||||
})
|
||||
}
|
||||
// Player area
|
||||
var roofID = Entities.addEntity(roofProperties)
|
||||
bases.push(roofID);
|
||||
teamEntities[i].roofID = roofID;
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
var t = teamEntities[i];
|
||||
Entities.deleteEntity(t.targetID);
|
||||
Entities.deleteEntity(t.spawnerID);
|
||||
if (t.bowIDs !== undefined) {
|
||||
for (var j = 0; j < t.bowIDs.length; ++j) {
|
||||
Entities.deleteEntity(t.bowIDs[j]);
|
||||
}
|
||||
}
|
||||
Entities.deleteEntity(t.roofID);
|
||||
Entities.deleteEntity(t.arenaID);
|
||||
}
|
||||
while (bases.length > 0) {
|
||||
Entities.deleteEntity(bases.pop());
|
||||
}
|
||||
Entities.deleteEntity(buttonID);
|
||||
print("Size of entityIDs:", entityIDs.length);
|
||||
for (var i = 0; i < entityIDs.length; ++i) {
|
||||
print("Deleting: ", entityIDs[i]);
|
||||
Entities.deleteEntity(entityIDs[i]);
|
||||
}
|
||||
entityIDs = [];
|
||||
for (var i = 0; i < spawnerIDs.length; ++i) {
|
||||
Entities.deleteEntity(spawnerIDs[i]);
|
||||
}
|
||||
spawnerIDs = [];
|
||||
|
||||
print("============= Script Stopping =============");
|
||||
Script.stop();
|
||||
}
|
||||
|
||||
function parseJSON(json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Messages.messageReceived.connect(function(channel, messageJSON, senderID) {
|
||||
print("Recieved: " + messageJSON + " from " + senderID);
|
||||
if (channel === CHANNEL_NAME) {
|
||||
var message = parseJSON(messageJSON);
|
||||
if (message === undefined) {
|
||||
print("towerDefense.js | Received non-json message");
|
||||
return;
|
||||
}
|
||||
switch (message.type) {
|
||||
case 'start-game':
|
||||
if (currentState != GAME_STATES.IDLE) {
|
||||
print("Got start message, but not in idle state. Current state: " + currentState);
|
||||
return;
|
||||
}
|
||||
|
||||
Entities.deleteEntity(buttonID);
|
||||
|
||||
for (var i in BASES) {
|
||||
var position = Vec3.sum(BASE_POSITION, BASES[i].position);
|
||||
|
||||
// Create target entity
|
||||
var targetID = Entities.addEntity({
|
||||
name: 'TD.TargetEntity',
|
||||
type: 'Sphere',
|
||||
position: position,
|
||||
dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE },
|
||||
color: BASES[i].color,
|
||||
script: Script.resolvePath("targetEntity.js"),
|
||||
userData: JSON.stringify({
|
||||
gameChannel: CHANNEL_NAME,
|
||||
teamNumber: i
|
||||
}),
|
||||
});
|
||||
entityIDs.push(targetID);
|
||||
teamEntities[i].targetID = targetID;
|
||||
|
||||
// Create box spawner
|
||||
var spawnerID = Entities.addEntity({
|
||||
name: 'TD.BoxSpawner',
|
||||
type: 'Box',
|
||||
position: Vec3.sum(BASE_POSITION, BASES[i].spawnerPosition),
|
||||
dimensions: { x: TARGET_SIZE, y: TARGET_SIZE, z: TARGET_SIZE },
|
||||
color: BASES[i].color,
|
||||
script: Script.resolvePath("launchEntity.js"),
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
wantsTrigger: true
|
||||
},
|
||||
gameChannel: CHANNEL_NAME,
|
||||
})
|
||||
});
|
||||
teamEntities[i].spawnerID = targetID;
|
||||
spawnerIDs.push(spawnerID);
|
||||
Audio.playSound(BEGIN_BUILDING_SOUND, {
|
||||
volume: 1.0,
|
||||
position: BASE_POSITION
|
||||
});
|
||||
}
|
||||
|
||||
currentState = GAME_STATES.BUILD;
|
||||
|
||||
Script.setTimeout(function() {
|
||||
Audio.playSound(TEN_SECONDS_REMAINING_SOUND, {
|
||||
volume: 1.0,
|
||||
position: BASE_POSITION
|
||||
});
|
||||
}, (BUILD_TIME_SECONDS - 10) * 1000);
|
||||
Script.setTimeout(function() {
|
||||
print("============ Done building, FIGHT =============");
|
||||
|
||||
Audio.playSound(BEGIN_FIGHTING_SOUND, {
|
||||
volume: 1.0,
|
||||
position: BASE_POSITION
|
||||
});
|
||||
|
||||
Messages.sendMessage(CHANNEL_NAME, "FIGHT");
|
||||
|
||||
|
||||
// Cleanup spawner cubes
|
||||
currentState = GAME_STATES.FIGHT;
|
||||
for (var i = 0; i < spawnerIDs.length; ++i) {
|
||||
Entities.deleteEntity(spawnerIDs[i]);
|
||||
}
|
||||
|
||||
// Spawn bows
|
||||
for (var i = 0; i < BASES.length; ++i) {
|
||||
var position = Vec3.sum(BASE_POSITION, BASES[i].position);
|
||||
position.y += BASES_HEIGHT + 1;
|
||||
teamEntities[i].bowIDs = [];
|
||||
|
||||
for (var j = 0; j < 4; ++j) {
|
||||
teamEntities[i].bowIDs.push(Entities.addEntity({
|
||||
position: position,
|
||||
"collisionsWillMove": 1,
|
||||
"compoundShapeURL": Script.resolvePath("bow/bow_collision_hull.obj"),
|
||||
"created": "2016-09-01T23:57:55Z",
|
||||
"dimensions": {
|
||||
"x": 0.039999999105930328,
|
||||
"y": 1.2999999523162842,
|
||||
"z": 0.20000000298023224
|
||||
},
|
||||
"dynamic": 1,
|
||||
"gravity": {
|
||||
"x": 0,
|
||||
"y": -1,
|
||||
"z": 0
|
||||
},
|
||||
"modelURL": Script.resolvePath("bow/bow-deadly.fbx"),
|
||||
"name": "TD.Hifi-Bow",
|
||||
"rotation": {
|
||||
"w": 0.9718012809753418,
|
||||
"x": 0.15440607070922852,
|
||||
"y": -0.10469216108322144,
|
||||
"z": -0.14418250322341919
|
||||
},
|
||||
"script": Script.resolvePath("bow/bow.js"),
|
||||
"shapeType": "compound",
|
||||
"type": "Model",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.0813,\"y\":0.0452,\"z\":0.0095},{\"x\":-0.3946,\"y\":-0.6604,\"z\":0.4748,\"w\":-0.4275}],\"LeftHand\":[{\"x\":-0.0881,\"y\":0.0259,\"z\":0.0159},{\"x\":0.4427,\"y\":-0.6519,\"z\":0.4592,\"w\":0.4099}]}}}"
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
}, BUILD_TIME_SECONDS * 1000);
|
||||
break;
|
||||
case 'target-hit':
|
||||
print("Got target-hit for: ", message.teamNumber);
|
||||
if (currentState !== GAME_STATES.FIGHT) {
|
||||
return;
|
||||
}
|
||||
print("game is over");
|
||||
Audio.playSound(GAME_OVER_SOUND, {
|
||||
volume: 1.0,
|
||||
position: BASE_POSITION
|
||||
});
|
||||
currentState = GAME_STATES.GAME_OVER;
|
||||
|
||||
// Delete the entities for the team that lost
|
||||
var t = teamEntities[message.teamNumber];
|
||||
Entities.deleteEntity(t.targetID);
|
||||
Entities.deleteEntity(t.spawnerID);
|
||||
Entities.deleteEntity(t.roofID);
|
||||
Entities.deleteEntity(t.arenaID);
|
||||
|
||||
// TODO If more than 1 team is still alive, don't cleanup
|
||||
// Do a full cleanup after 10 seconds
|
||||
Script.setTimeout(function() {
|
||||
cleanup();
|
||||
currentState = GAME_STATES.IDLE;
|
||||
}, 10 * 1000);
|
||||
break;
|
||||
default:
|
||||
print("towerDefense.js | Ignoring unknown message type: ", message.type);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Script.update.connect(function() {
|
||||
// EntityViewer.queryOctree();
|
||||
// });
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
(function() {
|
||||
return {
|
||||
preload: function(entityID) {
|
||||
Entities.editEntity(entityID, {
|
||||
localRenderAlpha: 0.2
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,49 +0,0 @@
|
|||
(function() {
|
||||
Script.include('utils.js');
|
||||
|
||||
function parseJSON(json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch(e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Target = function() {
|
||||
}
|
||||
Target.prototype = {
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
Script.addEventHandler(entityID, "collisionWithEntity", this.onCollide.bind(this));
|
||||
|
||||
this.entityIDsThatHaveCollidedWithMe = [];
|
||||
|
||||
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
||||
var data = utils.parseJSON(userData);
|
||||
if (data !== undefined && data.gameChannel !== undefined && data.teamNumber !== undefined) {
|
||||
this.gameChannel = data.gameChannel;
|
||||
this.teamNumber = data.teamNumber;
|
||||
} else {
|
||||
print("targetEntity.js | ERROR: userData does not contain a game channel and/or team number");
|
||||
}
|
||||
},
|
||||
onCollide: function(entityA, entityB, collision) {
|
||||
print("Collided with: ", entityB);
|
||||
var colliderName = Entities.getEntityProperties(entityB, 'name').name;
|
||||
|
||||
// If the other entity's name includes 'projectile' and we haven't hit it before,
|
||||
// continue on.
|
||||
if (colliderName.indexOf("projectile") > -1
|
||||
&& this.entityIDsThatHaveCollidedWithMe.indexOf(entityB) === -1) {
|
||||
this.entityIDsThatHaveCollidedWithMe.push(entityB);
|
||||
Messages.sendMessage(this.gameChannel, JSON.stringify({
|
||||
type: "target-hit",
|
||||
entityID: this.entityID,
|
||||
teamNumber: this.teamNumber
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new Target();
|
||||
});
|
|
@ -1,53 +0,0 @@
|
|||
(function() {
|
||||
function parseJSON(json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch(e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
var TeamArea = function() {
|
||||
};
|
||||
TeamArea.prototype = {
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.inEntity = false;
|
||||
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
||||
var data = parseJSON(userData);
|
||||
if (data !== undefined && data.gameChannel) {
|
||||
this.gameChannel = data.gameChannel
|
||||
Messages.subscribe(this.gameChannel);
|
||||
Messages.messageReceived.connect(this, this.onMessageReceived);
|
||||
} else {
|
||||
print("teamAreaEntity.js | ERROR: userData does not contain a game channel");
|
||||
}
|
||||
},
|
||||
onMessageReceived: function(channel, message, sender) {
|
||||
if (channel === this.gameChannel) {
|
||||
print("teamAreaEntity.js | Got game channel message:", message);
|
||||
if (message == "FIGHT" && this.inEntity) {
|
||||
// Set position to top of entity
|
||||
var props = Entities.getEntityProperties(this.entityID, ['position', 'dimensions', 'registrationPoint']);
|
||||
var teleportPoint = MyAvatar.position;
|
||||
teleportPoint.y = props.position.y + (props.dimensions.y * (1 - props.registrationPoint.y)) + 0.5;
|
||||
MyAvatar.position = teleportPoint;
|
||||
}
|
||||
}
|
||||
},
|
||||
enterEntity: function() {
|
||||
print("teamAreaEntity.js | Entered");
|
||||
this.inEntity = true;
|
||||
var props = Entities.getEntityProperties(this.entityID, ['position', 'dimensions', 'registrationPoint']);
|
||||
var teleportPoint = MyAvatar.position;
|
||||
teleportPoint.y = props.position.y + (props.dimensions.y * (1 - props.registrationPoint.y)) + 0.5;
|
||||
MyAvatar.position = teleportPoint;
|
||||
},
|
||||
leaveEntity: function() {
|
||||
print("teamAreaEntity.js | Exited");
|
||||
this.inEntity = false;
|
||||
}
|
||||
};
|
||||
|
||||
return new TeamArea();
|
||||
});
|
|
@ -1,26 +0,0 @@
|
|||
(function() {
|
||||
function parseJSON(json) {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch(e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
var TeamArea = function() {
|
||||
};
|
||||
TeamArea.prototype = {
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
},
|
||||
enterEntity: function() {
|
||||
print("teamAreaEntity.js | Entered");
|
||||
var props = Entities.getEntityProperties(this.entityID, ['position', 'dimensions', 'registrationPoint']);
|
||||
var teleportPoint = props.position;
|
||||
teleportPoint.y += (props.dimensions.y * (1 - props.registrationPoint.y)) + 0.5;
|
||||
MyAvatar.position = teleportPoint;
|
||||
}
|
||||
};
|
||||
|
||||
return new TeamArea();
|
||||
});
|
Loading…
Reference in a new issue