Move addition of localPosition to template data to shortbow.js

This commit is contained in:
Ryan Huffman 2017-02-02 16:34:20 -08:00
parent 0cc137d26b
commit 280ea7b2c0
5 changed files with 25 additions and 15 deletions

View file

@ -23,7 +23,6 @@
}
var self = this;
this.heartbeatTimerID = Script.setInterval(function() {
print("Sending heartbeat", self.gameChannel);
Messages.sendMessage(self.gameChannel, JSON.stringify({
type: "enemy-heartbeat",
entityID: self.entityID,

View file

@ -832,3 +832,21 @@ SHORTBOW_ENTITIES =
],
"Version": 65
}
// Add LocalPosition to entity data if parent properties are available
var entities = SHORTBOW_ENTITIES.Entities;
var entitiesByID = {}
for (var i = 0; i < entities.length; ++i) {
var entity = entities[i];
entitiesByID[entity.id] = entity;
}
for (var i = 0; i < entities.length; ++i) {
var entity = entities[i];
if (entity.parentID !== undefined) {
var parent = entitiesByID[entity.parentID];
if (parent !== undefined) {
entity.localPosition = Vec3.subtract(entity.position, parent.position);
delete entity.position;
}
}
}

View file

@ -198,7 +198,7 @@ ShortbowGameManager.prototype = {
// Spawn bows
for (var i = 0; i < this.bowPositions.length; ++i) {
const bowPosition = Vec3.sum(this.rootPosition, this.bowPositions[i]);
Vec3.print("Creating bow: ", bowPosition);
Vec3.print("Creating bow: " + i, this.bowPositions[i]);
this.bowIDs.push(Entities.addEntity({
position: bowPosition,
"collisionsWillMove": 1,

View file

@ -8,9 +8,11 @@
(function() {
Script.include('utils.js?' + Date.now());
Script.include('spawnShortbow.js?' + Date.now());
Script.include('shortbow.js?' + Date.now());
Script.include('shortbowGameManager.js?' + Date.now());
TEMPLATES = SHORTBOW_ENTITIES.Entities;
this.entityID = null;
var gameManager = null;
this.preload = function(entityID) {

View file

@ -86,8 +86,6 @@ for (var i = 0; i < TEMPLATES.length; ++i) {
var entityIDs = [];
var rootPosition = null;
var goalPosition = null;
var scoreboardID = null;
var buttonID = null;
var waveDisplayID = null;
@ -96,7 +94,7 @@ var highScoreDisplayID = null;
var livesDisplayID = null;
var platformID = null;
function createLocalGame() {
rootPosition = utils.findSurfaceBelowPosition(MyAvatar.position);
var rootPosition = utils.findSurfaceBelowPosition(MyAvatar.position);
rootPosition.y += 6.11;
scoreboardID = spawnTemplate("SB.Scoreboard", {
@ -110,7 +108,7 @@ function createLocalGame() {
script: Script.resolvePath("startGameButtonClientEntity.js"),
serverScripts: Script.resolvePath("startGameButtonServerEntity.js"),
userData: JSON.stringify({
grabbableKey: {
grabbableKey: {
wantsTrigger: true
}
}),
@ -118,13 +116,6 @@ function createLocalGame() {
entityIDs.push(buttonID);
// Generate goal that the enemies try to get to
goalPosition = Vec3.sum(rootPosition, { x: 0, y: -10, z: -20 });
const BASES_HEIGHT = 16;
const ROOF_HEIGHT = 0.2;
goalPosition.y += BASES_HEIGHT - ROOF_HEIGHT;
waveDisplayID = spawnTemplate("SB.DisplayWave", {
parentID: scoreboardID,
userData: JSON.stringify({
@ -200,7 +191,7 @@ function createLocalGame() {
if (Script.isClientScript()) {
createLocalGame();
//var gameManager = new ShortbowGameManager(rootPosition, goalPositionFront, bowPositions, spawnPositions, scoreboardID, buttonID, waveDisplayID, scoreDisplayID, livesDisplayID, highScoreDisplayID);
//var gameManager = new ShortbowGameManager(scoreboardID, bowPositions, spawnPositions);
function cleanup() {
for (var i = 0; i < entityIDs.length; ++i) {