From ecb849097853096168d8d55e6e90fccb2c18c778 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 2 Feb 2017 09:31:31 -0800 Subject: [PATCH] Rename shortbow files and cleanup several names --- .../marketplace/shortbow/README.md | 4 + ...eboardEntity.js => displayServerEntity.js} | 0 .../{enemyEntity.js => enemyClientEntity.js} | 12 +- .../marketplace/shortbow/shortbow.js | 7 +- .../shortbow/shortbowGameManager.js | 269 ++++++------------ .../shortbow/shortbowServerEntity.js | 31 +- .../marketplace/shortbow/spawnShortbow.js | 16 +- ...tton.js => startGameButtonClientEntity.js} | 5 +- .../marketplace/shortbow/utils.js | 20 -- 9 files changed, 125 insertions(+), 239 deletions(-) create mode 100644 unpublishedScripts/marketplace/shortbow/README.md rename unpublishedScripts/marketplace/shortbow/{scoreboardEntity.js => displayServerEntity.js} (100%) rename unpublishedScripts/marketplace/shortbow/{enemyEntity.js => enemyClientEntity.js} (83%) rename unpublishedScripts/marketplace/shortbow/{startGameButton.js => startGameButtonClientEntity.js} (81%) diff --git a/unpublishedScripts/marketplace/shortbow/README.md b/unpublishedScripts/marketplace/shortbow/README.md new file mode 100644 index 0000000000..027e3593bf --- /dev/null +++ b/unpublishedScripts/marketplace/shortbow/README.md @@ -0,0 +1,4 @@ +Shortbow +======== + +Shortbow is a wave-based archery game. diff --git a/unpublishedScripts/marketplace/shortbow/scoreboardEntity.js b/unpublishedScripts/marketplace/shortbow/displayServerEntity.js similarity index 100% rename from unpublishedScripts/marketplace/shortbow/scoreboardEntity.js rename to unpublishedScripts/marketplace/shortbow/displayServerEntity.js diff --git a/unpublishedScripts/marketplace/shortbow/enemyEntity.js b/unpublishedScripts/marketplace/shortbow/enemyClientEntity.js similarity index 83% rename from unpublishedScripts/marketplace/shortbow/enemyEntity.js rename to unpublishedScripts/marketplace/shortbow/enemyClientEntity.js index 4174f91ff3..ad300f93d8 100644 --- a/unpublishedScripts/marketplace/shortbow/enemyEntity.js +++ b/unpublishedScripts/marketplace/shortbow/enemyClientEntity.js @@ -5,18 +5,20 @@ }; Enemy.prototype = { preload: function(entityID) { - print("Loaded enemy entity"); this.entityID = entityID; - Script.addEventHandler(entityID, "collisionWithEntity", this.onCollide.bind(this)); + // To avoid sending extraneous messages and checking entities that we've already + // seen, we keep track of which entities we've collided with previously. this.entityIDsThatHaveCollidedWithMe = []; + Script.addEventHandler(entityID, "collisionWithEntity", this.onCollide.bind(this)); + var userData = Entities.getEntityProperties(this.entityID, 'userData').userData; var data = utils.parseJSON(userData); if (data !== undefined && data.gameChannel !== undefined) { this.gameChannel = data.gameChannel; } else { - print("targetEntity.js | ERROR: userData does not contain a game channel and/or team number"); + print("enemyEntity.js | ERROR: userData does not contain a game channel and/or team number"); } }, onCollide: function(entityA, entityB, collision) { @@ -26,12 +28,8 @@ this.entityIDsThatHaveCollidedWithMe.push(entityB); var colliderName = Entities.getEntityProperties(entityB, 'name').name; - print("Hit: ", entityB); - // If the other entity's name includes 'projectile' and we haven't hit it before, - // continue on. if (colliderName.indexOf("projectile") > -1) { - print("Collided with: ", entityB); Messages.sendMessage(this.gameChannel, JSON.stringify({ type: "enemy-killed", entityID: this.entityID, diff --git a/unpublishedScripts/marketplace/shortbow/shortbow.js b/unpublishedScripts/marketplace/shortbow/shortbow.js index eff26ecf71..4124872998 100644 --- a/unpublishedScripts/marketplace/shortbow/shortbow.js +++ b/unpublishedScripts/marketplace/shortbow/shortbow.js @@ -1,4 +1,9 @@ -SHORTBOW_ENTITIES = +// This is a copy of the data in shortbow.json, which is an export of the shortbow +// scene. +// +// Because .json can't be Script.include'd directly, the contents are copied over +// to here and exposed as a global variable. +SHORTBOW_ENTITIES = { "Entities": [ { diff --git a/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js b/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js index c8d9d97275..257bf4005e 100644 --- a/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js +++ b/unpublishedScripts/marketplace/shortbow/shortbowGameManager.js @@ -1,14 +1,5 @@ Script.include('utils.js'); -// Load the sounds that we will be using in the game so they are ready to be -// used when we need them. -var BEGIN_BUILDING_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/gameOn.wav")); -var GAME_OVER_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/gameOver.wav")); -var WAVE_COMPLETE_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/waveComplete.wav")); -var EXPLOSION_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/explosion.wav")); -var TARGET_HIT_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/targetHit.wav")); -var ESCAPE_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/escape.wav")); - // +--------+ +-----------+ +-----------------+ // | | | |<-----+ | // | IDLE +----->| PLAYING | | BETWEEN_WAVES | @@ -28,6 +19,15 @@ var GAME_STATES = { GAME_OVER: 3, }; +// Load the sounds that we will be using in the game so they are ready to be +// used when we need them. +var BEGIN_BUILDING_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/gameOn.wav")); +var GAME_OVER_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/gameOver.wav")); +var WAVE_COMPLETE_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/waveComplete.wav")); +var EXPLOSION_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/explosion.wav")); +var TARGET_HIT_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/targetHit.wav")); +var ESCAPE_SOUND = SoundCache.getSound(Script.resolvePath("assets/sounds/escape.wav")); + // Encode a set of key-value pairs into a param string. Does NOT do any URL escaping. function encodeURLParams(params) { var paramPairs = []; @@ -56,9 +56,6 @@ function sendAndUpdateHighScore(highScoreChannel, entityID, score, wave, numPlay var response = JSON.parse(req.responseText); if (response.highScore !== undefined) { Messages.sendMessage(highScoreChannel, response.highScore); - //Entities.editEntity(highScoreDisplayID, { - //text: response.highScore - //}); } } }; @@ -67,24 +64,6 @@ function sendAndUpdateHighScore(highScoreChannel, entityID, score, wave, numPlay req.send(); } -// The method of checking the local entity for the high score is currently disabled. -// As of 1/9/2017 we don't have support for getting nearby entity data in server entity scripts, -// so until then we have to rely on a remote source to store and retrieve that information. -function getHighScoreFromDisplay(entityID) { - var highScore = parseInt(Entities.getEntityProperties(entityID, 'text').text); - print("High score is: ", entityID, highScore); - if (highScore === NaN) { - return -1; - } - return highScore; -} -function setHighScoreOnDisplay(entityID, highScore) { - print("Setting high score to: ", entityID, highScore); - Entities.editEntity(entityID, { - text: highScore - }); -} - var baseEnemyProperties = { name: "WG.Enemy", damping: 0, @@ -124,7 +103,6 @@ var baseEnemyProperties = { "y": -0.54996079206466675, "z": -0.54996079206466675 }, - //"restitution": 0.99000000953674316, "rotation": { "w": 0.52459806203842163, "x": 0.3808099627494812, @@ -138,25 +116,19 @@ var baseEnemyProperties = { y: 0, z: -3 }, - script: Script.resolvePath('enemyEntity.js'), + script: Script.resolvePath('enemyClientEntity.js'), serverScripts: Script.resolvePath('enemyServerEntity.js') }; -ShortbowGameManager = function(rootPosition, gatePosition, bowPositions, spawnPositions, rootEntityID, startButtonID, waveDisplayID, scoreDisplayID, livesDisplayID, highScoreDisplayID) { +ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) { print("Starting game manager"); this.gameState = GAME_STATES.IDLE; - this.bowPositions = bowPositions; - this.rootPosition = rootPosition; - this.spawnPositions = spawnPositions; - this.gatePosition = gatePosition; this.rootEntityID = rootEntityID; - //this.startButtonID = startButtonID; - //this.waveDisplayID = waveDisplayID; - //this.scoreDisplayID = scoreDisplayID; - //this.livesDisplayID = livesDisplayID; - //this.highScoreDisplayID = highScoreDisplayID; + this.bowPositions = bowPositions; + this.rootPosition = null; + this.spawnPositions = spawnPositions; // Gameplay state this.waveNumber = 0; @@ -164,41 +136,34 @@ ShortbowGameManager = function(rootPosition, gatePosition, bowPositions, spawnPo this.score = 0; this.nextWaveTimer = null; this.spawnEnemyTimers = []; - //this.enemyIDs = []; this.remainingEnemies = []; - this.entityIDs = []; this.bowIDs = []; - this.commChannelName = "shortbow-" + this.rootEntityID; - print("Listening on: ", this.commChannelName); - - //this.scoreChannelName = "score-" + this.rootEntityID; this.highscoreChannelName = "highscore-" + this.rootEntityID; - //this.waveChannelName = "wave-" + this.rootEntityID; - //this.livesChannelName = "lives-" + this.rootEntityID; this.startButtonChannelName = 'button-' + this.rootEntityID; + // Entity client and server scripts will send messages to this channel + this.commChannelName = "shortbow-" + this.rootEntityID; Messages.subscribe(this.commChannelName); Messages.messageReceived.connect(this, this.onReceivedMessage); + print("Listening on: ", this.commChannelName); this.reset(); sendAndUpdateHighScore(this.highscoreChannelName, this.rootEntityID, this.score, this.waveNumber, 1); } ShortbowGameManager.prototype = { reset: function() { - //Entities.editEntity(this.startButtonID, { - //visible: true - //}); Messages.sendMessage(this.startButtonChannelName, 'show'); }, cleanup: function() { Messages.unsubscribe(this.commChannelName); Messages.messageReceived.disconnect(this, this.onReceivedMessage); - for (var i = 0; i < this.entityIDs.length; i++) { - Entities.deleteEntity(this.entityIDs[i]); + if (this.checkEnemiesTimer) { + Script.clearInterval(this.checkEnemiesTimer); + this.checkEnemiesTimer = null; } - this.entityIDs = []; + for (var i = this.bowIDs.length - 1; i >= 0; i--) { Entities.deleteEntity(this.bowIDs[i]); } @@ -207,57 +172,24 @@ ShortbowGameManager.prototype = { Entities.deleteEntity(this.remainingEnemies[i].id); } this.remainingEnemies = []; - }, - onReceivedMessage: function(channel, messageJSON, senderID) { - print("playWaveGame.js | Recieved: " + messageJSON + " from " + senderID, channel, this.commChannelName); - if (channel === this.commChannelName) { - var message = utils.parseJSON(messageJSON); - if (message === undefined) { - print("playWaveGame.js | Received non-json message:", JSON.stringify(messageJSON)); - return; - } - switch (message.type) { - case 'start-game': - this.startGame(); - break; - case 'enemy-killed': - this.onEnemyKilled(message.entityID, message.position); - break; - case 'enemy-escaped': - this.onEnemyEscaped(message.entityID); - break; - case 'enemy-heartbeat': - for (var i = 0; i < this.remainingEnemies.length; i++) { - var enemy = this.remainingEnemies[i]; - if (enemy.id == message.entityID) { - enemy.lastHeartbeat = Date.now(); - enemy.lastKnownPosition = message.position; - break; - } - } - break; - default: - print("playWaveGame.js | Ignoring unknown message type: ", message.type); - break; - } - } + this.gameState = GAME_STATES.IDLE; }, startGame: function() { if (this.gameState !== GAME_STATES.IDLE) { - print("playWaveGameManager.js | Error, trying to start game when not in idle state"); + print("shortbowGameManagerManager.js | Error, trying to start game when not in idle state"); return; } print("Game started!!"); - //Entities.editEntity(this.startButtonID, { visible: false }); - Messages.sendMessage(this.startButtonChannelName, 'hide'); + this.rootPosition = Entities.getEntityProperties(this.rootEntityID, 'position').position; + Messages.sendMessage(this.startButtonChannelName, 'hide'); // Spawn bows for (var i = 0; i < this.bowPositions.length; ++i) { - const bowPosition = this.bowPositions[i]; + const bowPosition = Vec3.sum(this.rootPosition, this.bowPositions[i]); Vec3.print("Creating bow: ", bowPosition); this.bowIDs.push(Entities.addEntity({ position: bowPosition, @@ -297,8 +229,7 @@ ShortbowGameManager.prototype = { this.nextWaveTimer = Script.setTimeout(this.startNextWave.bind(this), 100); this.spawnEnemyTimers = []; - this.checkEnemyPositionsTimer = null; - //this.enemyIDs = []; + this.checkEnemiesTimer = null; this.remainingEnemies = []; // SpawnQueue is a list of enemies left to spawn. Each entry looks like: @@ -309,7 +240,7 @@ ShortbowGameManager.prototype = { // to spawn the enemy. The list is sorted by spawnAt, ascending. this.spawnQueue = []; - this.gameState = GAME_STATES.PLAYING; + this.gameState = GAME_STATES.BETWEEN_WAVES; Audio.playSound(BEGIN_BUILDING_SOUND, { volume: 1.0, @@ -317,30 +248,25 @@ ShortbowGameManager.prototype = { }); var self = this; - //Script.setInterval(function() { - //print("Remaining enemies:"); - //for (var i = 0; i < self.remainingEnemies.length; ++i) { - //print(" ", i, self.remainingEnemies[i].id); - //} - //}, 3000); - }, + // Set the display text of one of the numbers on the scoreboard. + // Types: highscore, score, wave, lives setDisplayText: function(type, value) { var channel = type + '-' + this.rootEntityID; Messages.sendMessage(channel, value); }, startNextWave: function() { + if (this.gameState !== GAME_STATES.BETWEEN_WAVES) { + return; + } + print("Starting next wave"); this.gameState = GAME_STATES.PLAYING; this.waveNumber++; - //this.enemyIDs = []; this.remainingEnemies= []; this.spawnQueue = []; this.spawnStartTime = Date.now(); - //Entities.editEntity(this.waveDisplayID, { - //text: this.waveNumber - //}); this.setDisplayText('wave', this.waveNumber); var numberOfEnemiesLeftToSpawn = this.waveNumber * 2; @@ -348,12 +274,12 @@ ShortbowGameManager.prototype = { var currentDelay = 2000; print("Number of enemies:", numberOfEnemiesLeftToSpawn); - this.checkEnemyPositionsTimer = Script.setInterval(this.checkForEscapedEnemies.bind(this), 100); + this.checkEnemiesTimer = Script.setInterval(this.checkEnemies.bind(this), 100); for (var i = 0; i < numberOfEnemiesLeftToSpawn; ++i) { print("Adding enemy"); var idx = Math.floor(Math.random() * this.spawnPositions.length); - this.spawnQueue.push({ spawnAt: currentDelay, position: this.spawnPositions[idx] }); + this.spawnQueue.push({ spawnAt: currentDelay, position: Vec3.sum(this.rootPosition, this.spawnPositions[idx]) }); currentDelay += delayBetweenSpawns; } @@ -365,12 +291,12 @@ ShortbowGameManager.prototype = { return; } - if (this.spawnQueue.length <= 0 && this.remainingEnemies.length === 0) { + if (this.spawnQueue.length === 0 && this.remainingEnemies.length === 0) { this.gameState = GAME_STATES.BETWEEN_WAVES; Script.setTimeout(this.startNextWave.bind(this), 5000); - Script.clearInterval(this.checkEnemyPositionsTimer); - this.checkEnemyPositionsTimer = null; + Script.clearInterval(this.checkEnemiesTimer); + this.checkEnemiesTimer = null; // Play after 1.5s to let other sounds finish playing var self = this; @@ -385,19 +311,19 @@ ShortbowGameManager.prototype = { setLivesLeft: function(lives) { lives = Math.max(0, lives); this.livesLeft = lives; - //Entities.editEntity(this.livesDisplayID, { - //text: this.livesLeft - //}); this.setDisplayText('lives', this.livesLeft); }, setScore: function(score) { this.score = score; - //Entities.editEntity(this.scoreDisplayID, { - //text: utils.formatNumberWithCommas(this.score) - //}); this.setDisplayText('score', this.score); }, - checkSpawnQueue: function() { + checkEnemies: function() { + if (this.gameState !== GAME_STATES.PLAYING) { + return; + } + + // Check the spawn queueu to see if there are any enemies that need to + // be spawned var waveElapsedTime = Date.now() - this.spawnStartTime; while (this.spawnQueue.length > 0 && waveElapsedTime > this.spawnQueue[0].spawnAt) { baseEnemyProperties.position = this.spawnQueue[0].position; @@ -410,7 +336,6 @@ ShortbowGameManager.prototype = { }); var entityID = Entities.addEntity(baseEnemyProperties); - //this.enemyIDs.push(entityID); this.remainingEnemies.push({ id: entityID, lastKnownPosition: baseEnemyProperties.position, @@ -424,14 +349,9 @@ ShortbowGameManager.prototype = { }, 500 + Math.random() * 4000); } - //print("Spawn queue size: ", this.spawnQueue.length, "Elapsed time: ", waveElapsedTime, "Number of enemies:", this.enemyIDs.length); - }, - checkForEscapedEnemies: function() { - // Move this somewhere else? - this.checkSpawnQueue(); - - //return; + // Check the list of remaining enemies to see if any are too far away + // or haven't been heard from in awhile - if so, delete them. var enemiesEscaped = false; for (var i = this.remainingEnemies.length - 1; i >= 0; --i) { var enemy = this.remainingEnemies[i]; @@ -440,7 +360,6 @@ ShortbowGameManager.prototype = { if (timeSinceLastHeartbeat > 5000 || distance > 500) { print("EXPIRING: ", enemy.id); Entities.deleteEntity(enemy.id); - //this.enemyIDs.splice(i, 1); this.remainingEnemies.splice(i, 1); Audio.playSound(TARGET_HIT_SOUND, { volume: 1.0, @@ -449,31 +368,9 @@ ShortbowGameManager.prototype = { this.setScore(this.score + 100); enemiesEscaped = true; } - - //var position = Entities.getEntityProperties(this.enemyIDs[i], 'position').position; - //if (position === undefined || Vec3.distance(position, this.rootPosition) > 100) { - // If the enemy can no longer be found, assume it was hit - //this.enemyIDs.splice(i, 1); - //Audio.playSound(TARGET_HIT_SOUND, { - //volume: 1.0, - //position: this.rootPosition, - //}); - //this.setScore(this.score + 100); - //enemiesEscaped = true; - //} else if (position.z < this.gatePosition.z) { - //Entities.deleteEntity(this.enemyIDs[i]); - //this.enemyIDs.splice(i, 1); - //this.setLivesLeft(this.livesLeft - 1); - //Audio.playSound(ESCAPE_SOUND, { - //volume: 1.0, - //position: this.rootPosition - //}); - //enemiesEscaped = true; } - //print("LIVES LEFT: ", this.livesLeft, this.numberOfEntitiesLeftForWave); - if (this.livesLeft <= 0) { - this.endGame(); - } else if (enemiesEscaped) { + + if (enemiesEscaped) { this.checkWaveComplete(); } }, @@ -490,7 +387,6 @@ ShortbowGameManager.prototype = { }); }, 1500); - //Entities.editEntity(this.livesDisplayID, { text: "GAME OVER" }); this.gameState = GAME_STATES.GAME_OVER; print("GAME OVER"); @@ -505,8 +401,8 @@ ShortbowGameManager.prototype = { } this.spawnEnemyTimers = []; - Script.clearInterval(this.checkEnemyPositionsTimer); - this.checkEnemyPositionsTimer = null; + Script.clearInterval(this.checkEnemiesTimer); + this.checkEnemiesTimer = null; for (var i = this.bowIDs.length - 1; i >= 0; i--) { @@ -522,7 +418,6 @@ ShortbowGameManager.prototype = { } Script.setTimeout(function() { - //Entities.editEntity(this.startButtonID, { visible: true }); Messages.sendMessage(this.startButtonChannelName, 'show'); this.gameState = GAME_STATES.IDLE; }.bind(this), 3000); @@ -532,6 +427,34 @@ ShortbowGameManager.prototype = { } this.remainingEnemies = []; }, + onReceivedMessage: function(channel, messageJSON, senderID) { + print("shortbowGameManager.js | Recieved: " + messageJSON + " from " + senderID, channel, this.commChannelName); + + if (channel === this.commChannelName) { + var message = utils.parseJSON(messageJSON); + if (message === undefined) { + print("shortbowGameManager.js | Received non-json message:", JSON.stringify(messageJSON)); + return; + } + switch (message.type) { + case 'start-game': + this.startGame(); + break; + case 'enemy-killed': + this.onEnemyKilled(message.entityID, message.position); + break; + case 'enemy-escaped': + this.onEnemyEscaped(message.entityID); + break; + case 'enemy-heartbeat': + this.onEnemyHeartbeat(message.entityID, message.position); + break; + default: + print("shortbowGameManager.js | Ignoring unknown message type: ", message.type); + break; + } + } + }, onEnemyKilled: function(entityID, position) { if (this.gameState !== GAME_STATES.PLAYING) { return; @@ -543,7 +466,6 @@ ShortbowGameManager.prototype = { this.remainingEnemies.splice(i, 1); Audio.playSound(TARGET_HIT_SOUND, { volume: 1.0, - //position: position, position: this.rootPosition, }); @@ -555,24 +477,12 @@ ShortbowGameManager.prototype = { break; } } - - //var idx = this.enemyIDs.indexOf(entityID); - //if (idx >= 0) { - // this.enemyIDs.splice(idx, 1); - // Audio.playSound(TARGET_HIT_SOUND, { - // volume: 1.0, - // //position: position, - // position: this.rootPosition, - // }); - - // // Update score - // this.setScore(this.score + 100); - // print("SCORE: ", this.score); - - // this.checkWaveComplete(); - //} }, onEnemyEscaped: function(entityID, position) { + if (this.gameState !== GAME_STATES.PLAYING) { + return; + } + var enemiesEscaped = false; for (var i = this.remainingEnemies.length - 1; i >= 0; --i) { var enemy = this.remainingEnemies[i]; @@ -587,11 +497,20 @@ ShortbowGameManager.prototype = { enemiesEscaped = true; } } - //print("LIVES LEFT: ", this.livesLeft, this.numberOfEntitiesLeftForWave); if (this.livesLeft <= 0) { this.endGame(); } else if (enemiesEscaped) { this.checkWaveComplete(); } }, + onEnemyHeartbeat: function(entityID, position) { + for (var i = 0; i < this.remainingEnemies.length; i++) { + var enemy = this.remainingEnemies[i]; + if (enemy.id == entityID) { + enemy.lastHeartbeat = Date.now(); + enemy.lastKnownPosition = position; + break; + } + } + }, }; diff --git a/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js b/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js index 7f700705df..85e41e5383 100644 --- a/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js +++ b/unpublishedScripts/marketplace/shortbow/shortbowServerEntity.js @@ -1,6 +1,6 @@ (function() { Script.include('utils.js?' + Date.now()); - Script.include('playWaveGame.js?' + Date.now()); + Script.include('spawnShortbow.js?' + Date.now()); Script.include('shortbowGameManager.js?' + Date.now()); this.entityID = null; @@ -17,37 +17,22 @@ var rootPosition = props.position; - // 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; - - var platformID = data.platformID; - var buttonID = data.buttonID; - var waveDisplayID = data.waveDisplayID; - var livesDisplayID = data.livesDisplayID; - var scoreDisplayID = data.scoreDisplayID; - var highScoreDisplayID = data.highScoreDisplayID; - - const BASES_SIZE = 15; - var goalPositionFront = Vec3.sum(goalPosition, { x: 0, y: 0, z: BASES_SIZE / 2 }); - var bowPositions = []; var spawnPositions = []; for (var i = 0; i < TEMPLATES.length; ++i) { var template = TEMPLATES[i]; if (template.name === "SB.BowSpawn") { - bowPositions.push(Vec3.sum(rootPosition, template.localPosition)); - Vec3.print("Pushing bow position", Vec3.sum(rootPosition, template.localPosition)); + //bowPositions.push(Vec3.sum(rootPosition, template.localPosition)); + bowPositions.push(template.localPosition); + //Vec3.print("Pushing bow position", Vec3.sum(rootPosition, template.localPosition)); } else if (template.name === "SB.EnemySpawn") { - spawnPositions.push(Vec3.sum(rootPosition, template.localPosition)); - Vec3.print("Pushing spawnposition", Vec3.sum(rootPosition, template.localPosition)); + //spawnPositions.push(Vec3.sum(rootPosition, template.localPosition)); + spawnPositions.push(template.localPosition); + //Vec3.print("Pushing spawnposition", template.localPosition)); } } - gameManager = new ShortbowGameManager(rootPosition, goalPositionFront, bowPositions, spawnPositions, this.entityID, buttonID, waveDisplayID, scoreDisplayID, livesDisplayID, highScoreDisplayID); + gameManager = new ShortbowGameManager(this.entityID, bowPositions, spawnPositions); }; this.unload = function() { if (gameManager) { diff --git a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js index aea037f156..d8ca561df2 100644 --- a/unpublishedScripts/marketplace/shortbow/spawnShortbow.js +++ b/unpublishedScripts/marketplace/shortbow/spawnShortbow.js @@ -101,13 +101,12 @@ function createLocalGame() { // Create start button buttonID = spawnTemplate("SB.StartButton", { parentID: scoreboardID, - script: Script.resolvePath("startGameButton.js"), + script: Script.resolvePath("startGameButtonClientEntity.js"), serverScripts: Script.resolvePath("startGameButtonServerEntity.js"), userData: JSON.stringify({ grabbableKey: { wantsTrigger: true - }, - gameChannel: 'shortbow-' + scoreboardID + } }), }); entityIDs.push(buttonID); @@ -125,7 +124,7 @@ function createLocalGame() { userData: JSON.stringify({ displayType: "wave" }), - serverScripts: Script.resolvePath("scoreboardEntity.js") + serverScripts: Script.resolvePath("displayServerEntity.js") }); entityIDs.push(waveDisplayID); @@ -134,7 +133,7 @@ function createLocalGame() { userData: JSON.stringify({ displayType: "score" }), - serverScripts: Script.resolvePath("scoreboardEntity.js") + serverScripts: Script.resolvePath("displayServerEntity.js") }); entityIDs.push(scoreDisplayID); @@ -143,7 +142,7 @@ function createLocalGame() { userData: JSON.stringify({ displayType: "lives" }), - serverScripts: Script.resolvePath("scoreboardEntity.js") + serverScripts: Script.resolvePath("displayServerEntity.js") }); entityIDs.push(livesDisplayID); @@ -152,7 +151,7 @@ function createLocalGame() { userData: JSON.stringify({ displayType: "highscore" }), - serverScripts: Script.resolvePath("scoreboardEntity.js") + serverScripts: Script.resolvePath("displayServerEntity.js") }); entityIDs.push(highScoreDisplayID); @@ -191,9 +190,6 @@ function createLocalGame() { Vec3.print("Pushing spawnposition", Vec3.sum(rootPosition, template.localPosition)); } } - - const BASES_SIZE = 15; - goalPositionFront = Vec3.sum(goalPosition, { x: 0, y: 0, z: BASES_SIZE / 2 }); } if (Script.isClientScript()) { diff --git a/unpublishedScripts/marketplace/shortbow/startGameButton.js b/unpublishedScripts/marketplace/shortbow/startGameButtonClientEntity.js similarity index 81% rename from unpublishedScripts/marketplace/shortbow/startGameButton.js rename to unpublishedScripts/marketplace/shortbow/startGameButtonClientEntity.js index 331df15c72..aae6b4ad86 100644 --- a/unpublishedScripts/marketplace/shortbow/startGameButton.js +++ b/unpublishedScripts/marketplace/shortbow/startGameButtonClientEntity.js @@ -12,9 +12,8 @@ }, signalAC: function() { print("Button pressed"); - var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData; - print("Sending message to: ", JSON.parse(userData).gameChannel); - Messages.sendMessage(JSON.parse(userData).gameChannel, JSON.stringify({ + print("Sending message to: ", this.commChannel); + Messages.sendMessage(this.commChannel, JSON.stringify({ type: 'start-game' })); }, diff --git a/unpublishedScripts/marketplace/shortbow/utils.js b/unpublishedScripts/marketplace/shortbow/utils.js index 0c0c7d6761..53b3fc7655 100644 --- a/unpublishedScripts/marketplace/shortbow/utils.js +++ b/unpublishedScripts/marketplace/shortbow/utils.js @@ -43,25 +43,5 @@ utils = { return result.intersection; } return pos; - }, - formatNumberWithCommas: function(number) { - return number + ""; - if (number === 0) { - return "0"; - } - - var str = ""; - - while (number > 0) { - // Grab the digits in the - var belowThousand = number % 1000; - if (str !== "") { - str = "," + str; - } - str = belowThousand + str; - number = Math.floor(number / 1000); - } - - return str; } };