mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:47:11 +02:00
Fix coding standard issues in shortbow
This commit is contained in:
parent
dd895dc04a
commit
c8ec5cbf5d
9 changed files with 100 additions and 83 deletions
|
@ -110,8 +110,8 @@ function getControllerLocation(controllerHand) {
|
||||||
z: 0.93
|
z: 0.93
|
||||||
};
|
};
|
||||||
|
|
||||||
const MIN_ARROW_SPEED = 3;
|
const MIN_ARROW_SPEED = 3.0;
|
||||||
const MAX_ARROW_SPEED = 30;
|
const MAX_ARROW_SPEED = 30.0;
|
||||||
|
|
||||||
const ARROW_TIP_OFFSET = 0.47;
|
const ARROW_TIP_OFFSET = 0.47;
|
||||||
const ARROW_GRAVITY = {
|
const ARROW_GRAVITY = {
|
||||||
|
@ -128,9 +128,9 @@ function getControllerLocation(controllerHand) {
|
||||||
const BOTTOM_NOTCH_OFFSET = 0.6;
|
const BOTTOM_NOTCH_OFFSET = 0.6;
|
||||||
|
|
||||||
const LINE_DIMENSIONS = {
|
const LINE_DIMENSIONS = {
|
||||||
x: 5,
|
x: 5.0,
|
||||||
y: 5,
|
y: 5.0,
|
||||||
z: 5
|
z: 5.0
|
||||||
};
|
};
|
||||||
|
|
||||||
const DRAW_STRING_THRESHOLD = 0.80;
|
const DRAW_STRING_THRESHOLD = 0.80;
|
||||||
|
@ -147,10 +147,10 @@ function getControllerLocation(controllerHand) {
|
||||||
const NOTCH_OFFSET_UP = 0.035;
|
const NOTCH_OFFSET_UP = 0.035;
|
||||||
|
|
||||||
const SHOT_SCALE = {
|
const SHOT_SCALE = {
|
||||||
min1: 0,
|
min1: 0.0,
|
||||||
max1: 0.6,
|
max1: 0.6,
|
||||||
min2: 1,
|
min2: 1.0,
|
||||||
max2: 15
|
max2: 15.0
|
||||||
};
|
};
|
||||||
|
|
||||||
const USE_DEBOUNCE = false;
|
const USE_DEBOUNCE = false;
|
||||||
|
@ -450,12 +450,10 @@ function getControllerLocation(controllerHand) {
|
||||||
|
|
||||||
var stringProps = Entities.getEntityProperties(this.stringID, ['position', 'rotation']);
|
var stringProps = Entities.getEntityProperties(this.stringID, ['position', 'rotation']);
|
||||||
var handPositionLocal = Vec3.subtract(this.arrowRearPosition, stringProps.position);
|
var handPositionLocal = Vec3.subtract(this.arrowRearPosition, stringProps.position);
|
||||||
//handPositionLocal = Vec3.subtract(handPositionLocal, { x: 0, y: 0.6, z: 0 });
|
|
||||||
handPositionLocal = Vec3.multiplyQbyV(Quat.inverse(stringProps.rotation), handPositionLocal);
|
handPositionLocal = Vec3.multiplyQbyV(Quat.inverse(stringProps.rotation), handPositionLocal);
|
||||||
|
|
||||||
var linePoints = [
|
var linePoints = [
|
||||||
{ x: 0, y: 0, z: 0 },
|
{ x: 0, y: 0, z: 0 },
|
||||||
//{ x: 0, y: -0.6, z: 1 },
|
|
||||||
handPositionLocal,
|
handPositionLocal,
|
||||||
{ x: 0, y: -1.2, z: 0 },
|
{ x: 0, y: -1.2, z: 0 },
|
||||||
];
|
];
|
||||||
|
@ -491,7 +489,6 @@ function getControllerLocation(controllerHand) {
|
||||||
Controller.triggerHapticPulse(1, 20, backHand);
|
Controller.triggerHapticPulse(1, 20, backHand);
|
||||||
this.pullBackDistance = pullBackDistance;
|
this.pullBackDistance = pullBackDistance;
|
||||||
}
|
}
|
||||||
// this.changeStringPullSoundVolume(pullBackDistance);
|
|
||||||
|
|
||||||
if (pullBackDistance > DRAW_STRING_MAX_DRAW) {
|
if (pullBackDistance > DRAW_STRING_MAX_DRAW) {
|
||||||
pullBackDistance = DRAW_STRING_MAX_DRAW;
|
pullBackDistance = DRAW_STRING_MAX_DRAW;
|
||||||
|
@ -582,8 +579,6 @@ function getControllerLocation(controllerHand) {
|
||||||
// play the sound of a shooting arrow
|
// play the sound of a shooting arrow
|
||||||
this.playShootArrowSound();
|
this.playShootArrowSound();
|
||||||
|
|
||||||
// Controller.triggerShortHapticPulse(1, backHand);
|
|
||||||
|
|
||||||
Entities.addAction("travel-oriented", this.arrow, {
|
Entities.addAction("travel-oriented", this.arrow, {
|
||||||
forward: { x: 0, y: 0, z: -1 },
|
forward: { x: 0, y: 0, z: -1 },
|
||||||
angularTimeScale: 0.1,
|
angularTimeScale: 0.1,
|
||||||
|
@ -596,8 +591,9 @@ function getControllerLocation(controllerHand) {
|
||||||
},
|
},
|
||||||
|
|
||||||
scaleArrowShotStrength: function(value) {
|
scaleArrowShotStrength: function(value) {
|
||||||
var pct = (value - MIN_ARROW_DISTANCE_FROM_BOW_REST) / (MAX_ARROW_DISTANCE_FROM_BOW_REST - MIN_ARROW_DISTANCE_FROM_BOW_REST);
|
var percentage = (value - MIN_ARROW_DISTANCE_FROM_BOW_REST)
|
||||||
return MIN_ARROW_SPEED + (pct * (MAX_ARROW_SPEED - MIN_ARROW_SPEED)) ;
|
/ (MAX_ARROW_DISTANCE_FROM_BOW_REST - MIN_ARROW_DISTANCE_FROM_BOW_REST);
|
||||||
|
return MIN_ARROW_SPEED + (percentage * (MAX_ARROW_SPEED - MIN_ARROW_SPEED)) ;
|
||||||
},
|
},
|
||||||
|
|
||||||
playStringPullSound: function() {
|
playStringPullSound: function() {
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals utils */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include('utils.js');
|
Script.include('utils.js');
|
||||||
|
|
||||||
Enemy = function() {
|
function Enemy() {
|
||||||
};
|
}
|
||||||
Enemy.prototype = {
|
Enemy.prototype = {
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals utils */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include('utils.js');
|
Script.include('utils.js');
|
||||||
|
|
||||||
Enemy = function() {
|
function Enemy() {
|
||||||
};
|
}
|
||||||
Enemy.prototype = {
|
Enemy.prototype = {
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
@ -32,7 +34,7 @@
|
||||||
},
|
},
|
||||||
unload: function() {
|
unload: function() {
|
||||||
Script.clearInterval(this.heartbeatTimerID);
|
Script.clearInterval(this.heartbeatTimerID);
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Enemy();
|
return new Enemy();
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals SHORTBOW_ENTITIES:true */
|
||||||
|
|
||||||
// This is a copy of the data in shortbow.json, which is an export of the shortbow
|
// This is a copy of the data in shortbow.json, which is an export of the shortbow
|
||||||
// scene.
|
// scene.
|
||||||
//
|
//
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals ShortbowGameManager:true, utils */
|
||||||
|
|
||||||
Script.include('utils.js');
|
Script.include('utils.js');
|
||||||
|
|
||||||
// +--------+ +-----------+ +-----------------+
|
// +--------+ +-----------+ +-----------------+
|
||||||
|
@ -24,7 +26,7 @@ var GAME_STATES = {
|
||||||
IDLE: 0,
|
IDLE: 0,
|
||||||
PLAYING: 1,
|
PLAYING: 1,
|
||||||
BETWEEN_WAVES: 2,
|
BETWEEN_WAVES: 2,
|
||||||
GAME_OVER: 3,
|
GAME_OVER: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load the sounds that we will be using in the game so they are ready to be
|
// Load the sounds that we will be using in the game so they are ready to be
|
||||||
|
@ -36,6 +38,10 @@ var EXPLOSION_SOUND = SoundCache.getSound(Script.resolvePath("sounds/explosion.w
|
||||||
var TARGET_HIT_SOUND = SoundCache.getSound(Script.resolvePath("sounds/targetHit.wav"));
|
var TARGET_HIT_SOUND = SoundCache.getSound(Script.resolvePath("sounds/targetHit.wav"));
|
||||||
var ESCAPE_SOUND = SoundCache.getSound(Script.resolvePath("sounds/escape.wav"));
|
var ESCAPE_SOUND = SoundCache.getSound(Script.resolvePath("sounds/escape.wav"));
|
||||||
|
|
||||||
|
const STARTING_NUMBER_OF_LIVES = 6;
|
||||||
|
const ENEMIES_PER_WAVE_MULTIPLIER = 2;
|
||||||
|
const POINTS_PER_KILL = 100;
|
||||||
|
|
||||||
// Encode a set of key-value pairs into a param string. Does NOT do any URL escaping.
|
// Encode a set of key-value pairs into a param string. Does NOT do any URL escaping.
|
||||||
function encodeURLParams(params) {
|
function encodeURLParams(params) {
|
||||||
var paramPairs = [];
|
var paramPairs = [];
|
||||||
|
@ -56,27 +62,27 @@ function sendAndUpdateHighScore(entityID, score, wave, numPlayers, onResposeRece
|
||||||
numPlayers: numPlayers
|
numPlayers: numPlayers
|
||||||
});
|
});
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
req.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
print("ready state: ", req.readyState, req.status, req.readyState === req.DONE, req.response);
|
print("ready state: ", request.readyState, request.status, request.readyState === request.DONE, request.response);
|
||||||
if (req.readyState === req.DONE && req.status === 200) {
|
if (request.readyState === request.DONE && request.status === 200) {
|
||||||
print("Got response for high score: ", req.response);
|
print("Got response for high score: ", request.response);
|
||||||
var response = JSON.parse(req.responseText);
|
var response = JSON.parse(request.responseText);
|
||||||
if (response.highScore !== undefined) {
|
if (response.highScore !== undefined) {
|
||||||
onResposeReceived(response.highScore);
|
onResposeReceived(response.highScore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
req.open('GET', URL + "?" + paramString);
|
request.open('GET', URL + "?" + paramString);
|
||||||
req.timeout = 10000;
|
request.timeout = 10000;
|
||||||
req.send();
|
request.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseEnemyProperties = {
|
var baseEnemyProperties = {
|
||||||
name: "WG.Enemy",
|
"name": "SB.Enemy",
|
||||||
damping: 0,
|
"damping": 0,
|
||||||
linearDamping: 0,
|
"linearDamping": 0,
|
||||||
angularDamping: 0,
|
"angularDamping": 0,
|
||||||
"acceleration": {
|
"acceleration": {
|
||||||
"x": 0,
|
"x": 0,
|
||||||
"y": -9,
|
"y": -9,
|
||||||
|
@ -100,10 +106,9 @@ var baseEnemyProperties = {
|
||||||
"y": -15,
|
"y": -15,
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
lifetime: 60,
|
"lifetime": 60,
|
||||||
"id": "{ed8f7339-8bbd-4750-968e-c3ceb9d64721}",
|
"id": "{ed8f7339-8bbd-4750-968e-c3ceb9d64721}",
|
||||||
"modelURL": Script.resolvePath("models/Amber.fbx"),
|
"modelURL": Script.resolvePath("models/Amber.fbx"),
|
||||||
"name": "SB.Enemy",
|
|
||||||
"owningAvatarID": "{00000000-0000-0000-0000-000000000000}",
|
"owningAvatarID": "{00000000-0000-0000-0000-000000000000}",
|
||||||
"queryAACube": {
|
"queryAACube": {
|
||||||
"scale": 1.0999215841293335,
|
"scale": 1.0999215841293335,
|
||||||
|
@ -119,13 +124,13 @@ var baseEnemyProperties = {
|
||||||
},
|
},
|
||||||
"shapeType": "sphere",
|
"shapeType": "sphere",
|
||||||
"type": "Model",
|
"type": "Model",
|
||||||
velocity: {
|
"velocity": {
|
||||||
x: 0,
|
"x": 0,
|
||||||
y: 0,
|
"y": 0,
|
||||||
z: -3
|
"z": -3
|
||||||
},
|
},
|
||||||
script: Script.resolvePath('enemyClientEntity.js'),
|
"script": Script.resolvePath('enemyClientEntity.js'),
|
||||||
serverScripts: Script.resolvePath('enemyServerEntity.js')
|
"serverScripts": Script.resolvePath('enemyServerEntity.js')
|
||||||
};
|
};
|
||||||
|
|
||||||
function searchForChildren(parentID, names, callback, timeoutMs) {
|
function searchForChildren(parentID, names, callback, timeoutMs) {
|
||||||
|
@ -157,11 +162,11 @@ function searchForChildren(parentID, names, callback, timeoutMs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (names.length == 0 || check >= maxChecks) {
|
if (names.length === 0 || check >= maxChecks) {
|
||||||
Script.clearInterval(intervalID);
|
Script.clearInterval(intervalID);
|
||||||
callback(foundEntities);
|
callback(foundEntities);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, CHECK_EVERY_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
||||||
|
@ -183,6 +188,8 @@ ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
||||||
const LIVES_DISPLAY_NAME = 'SB.DisplayLives';
|
const LIVES_DISPLAY_NAME = 'SB.DisplayLives';
|
||||||
const HIGH_SCORE_DISPLAY_NAME = 'SB.DisplayHighScore';
|
const HIGH_SCORE_DISPLAY_NAME = 'SB.DisplayHighScore';
|
||||||
|
|
||||||
|
const SEARCH_FOR_CHILDREN_TIMEOUT = 5000;
|
||||||
|
|
||||||
searchForChildren(rootEntityID, [
|
searchForChildren(rootEntityID, [
|
||||||
START_BUTTON_NAME,
|
START_BUTTON_NAME,
|
||||||
WAVE_DISPLAY_NAME,
|
WAVE_DISPLAY_NAME,
|
||||||
|
@ -190,7 +197,6 @@ ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
||||||
LIVES_DISPLAY_NAME,
|
LIVES_DISPLAY_NAME,
|
||||||
HIGH_SCORE_DISPLAY_NAME
|
HIGH_SCORE_DISPLAY_NAME
|
||||||
], function(children) {
|
], function(children) {
|
||||||
print("ENTITES FOUND");
|
|
||||||
self.loadedChildren = true;
|
self.loadedChildren = true;
|
||||||
self.startButtonID = children[START_BUTTON_NAME];
|
self.startButtonID = children[START_BUTTON_NAME];
|
||||||
self.waveDisplayID = children[WAVE_DISPLAY_NAME];
|
self.waveDisplayID = children[WAVE_DISPLAY_NAME];
|
||||||
|
@ -201,11 +207,11 @@ ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
||||||
sendAndUpdateHighScore(self.rootEntityID, self.score, self.waveNumber, 1, self.setHighScore.bind(self));
|
sendAndUpdateHighScore(self.rootEntityID, self.score, self.waveNumber, 1, self.setHighScore.bind(self));
|
||||||
|
|
||||||
self.reset();
|
self.reset();
|
||||||
}, 5000);
|
}, SEARCH_FOR_CHILDREN_TIMEOUT);
|
||||||
|
|
||||||
// Gameplay state
|
// Gameplay state
|
||||||
this.waveNumber = 0;
|
this.waveNumber = 0;
|
||||||
this.livesLeft = 5;
|
this.livesLeft = STARTING_NUMBER_OF_LIVES;
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
this.nextWaveTimer = null;
|
this.nextWaveTimer = null;
|
||||||
this.spawnEnemyTimers = [];
|
this.spawnEnemyTimers = [];
|
||||||
|
@ -220,7 +226,7 @@ ShortbowGameManager = function(rootEntityID, bowPositions, spawnPositions) {
|
||||||
Messages.messageReceived.connect(this, this.onReceivedMessage);
|
Messages.messageReceived.connect(this, this.onReceivedMessage);
|
||||||
print("Listening on: ", this.commChannelName);
|
print("Listening on: ", this.commChannelName);
|
||||||
Messages.sendMessage(this.commChannelName, 'hi');
|
Messages.sendMessage(this.commChannelName, 'hi');
|
||||||
}
|
};
|
||||||
ShortbowGameManager.prototype = {
|
ShortbowGameManager.prototype = {
|
||||||
reset: function() {
|
reset: function() {
|
||||||
Entities.editEntity(this.startButtonID, { visible: true });
|
Entities.editEntity(this.startButtonID, { visible: true });
|
||||||
|
@ -238,7 +244,7 @@ ShortbowGameManager.prototype = {
|
||||||
Entities.deleteEntity(this.bowIDs[i]);
|
Entities.deleteEntity(this.bowIDs[i]);
|
||||||
}
|
}
|
||||||
this.bowIDs = [];
|
this.bowIDs = [];
|
||||||
for (var i = 0; i < this.remainingEnemies.length; i++) {
|
for (i = 0; i < this.remainingEnemies.length; i++) {
|
||||||
Entities.deleteEntity(this.remainingEnemies[i].id);
|
Entities.deleteEntity(this.remainingEnemies[i].id);
|
||||||
}
|
}
|
||||||
this.remainingEnemies = [];
|
this.remainingEnemies = [];
|
||||||
|
@ -267,7 +273,7 @@ ShortbowGameManager.prototype = {
|
||||||
const bowPosition = Vec3.sum(this.rootPosition, this.bowPositions[i]);
|
const bowPosition = Vec3.sum(this.rootPosition, this.bowPositions[i]);
|
||||||
Vec3.print("Creating bow: " + i, this.bowPositions[i]);
|
Vec3.print("Creating bow: " + i, this.bowPositions[i]);
|
||||||
this.bowIDs.push(Entities.addEntity({
|
this.bowIDs.push(Entities.addEntity({
|
||||||
position: bowPosition,
|
"position": bowPosition,
|
||||||
"collisionsWillMove": 1,
|
"collisionsWillMove": 1,
|
||||||
"compoundShapeURL": Script.resolvePath("bow/bow_collision_hull.obj"),
|
"compoundShapeURL": Script.resolvePath("bow/bow_collision_hull.obj"),
|
||||||
"created": "2016-09-01T23:57:55Z",
|
"created": "2016-09-01T23:57:55Z",
|
||||||
|
@ -300,7 +306,7 @@ ShortbowGameManager.prototype = {
|
||||||
// Initialize game state
|
// Initialize game state
|
||||||
this.waveNumber = 0;
|
this.waveNumber = 0;
|
||||||
this.setScore(0);
|
this.setScore(0);
|
||||||
this.setLivesLeft(6);
|
this.setLivesLeft(STARTING_NUMBER_OF_LIVES);
|
||||||
|
|
||||||
this.nextWaveTimer = Script.setTimeout(this.startNextWave.bind(this), 100);
|
this.nextWaveTimer = Script.setTimeout(this.startNextWave.bind(this), 100);
|
||||||
this.spawnEnemyTimers = [];
|
this.spawnEnemyTimers = [];
|
||||||
|
@ -321,8 +327,6 @@ ShortbowGameManager.prototype = {
|
||||||
volume: 1.0,
|
volume: 1.0,
|
||||||
position: this.rootPosition
|
position: this.rootPosition
|
||||||
});
|
});
|
||||||
|
|
||||||
var self = this;
|
|
||||||
},
|
},
|
||||||
startNextWave: function() {
|
startNextWave: function() {
|
||||||
if (this.gameState !== GAME_STATES.BETWEEN_WAVES) {
|
if (this.gameState !== GAME_STATES.BETWEEN_WAVES) {
|
||||||
|
@ -338,7 +342,7 @@ ShortbowGameManager.prototype = {
|
||||||
|
|
||||||
Entities.editEntity(this.waveDisplayID, { text: this.waveNumber});
|
Entities.editEntity(this.waveDisplayID, { text: this.waveNumber});
|
||||||
|
|
||||||
var numberOfEnemiesLeftToSpawn = this.waveNumber * 2;
|
var numberOfEnemiesLeftToSpawn = this.waveNumber * ENEMIES_PER_WAVE_MULTIPLIER;
|
||||||
var delayBetweenSpawns = 2000 / Math.max(1, Math.log(this.waveNumber));
|
var delayBetweenSpawns = 2000 / Math.max(1, Math.log(this.waveNumber));
|
||||||
var currentDelay = 2000;
|
var currentDelay = 2000;
|
||||||
|
|
||||||
|
@ -416,8 +420,9 @@ ShortbowGameManager.prototype = {
|
||||||
});
|
});
|
||||||
this.spawnQueue.splice(0, 1);
|
this.spawnQueue.splice(0, 1);
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
|
const JUMP_SPEED = 5.0;
|
||||||
var velocity = Entities.getEntityProperties(entityID, 'velocity').velocity;
|
var velocity = Entities.getEntityProperties(entityID, 'velocity').velocity;
|
||||||
velocity.y += 5;
|
velocity.y += JUMP_SPEED;
|
||||||
Entities.editEntity(entityID, { velocity: velocity });
|
Entities.editEntity(entityID, { velocity: velocity });
|
||||||
|
|
||||||
}, 500 + Math.random() * 4000);
|
}, 500 + Math.random() * 4000);
|
||||||
|
@ -426,19 +431,23 @@ ShortbowGameManager.prototype = {
|
||||||
// Check the list of remaining enemies to see if any are too far away
|
// 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.
|
// or haven't been heard from in awhile - if so, delete them.
|
||||||
var enemiesEscaped = false;
|
var enemiesEscaped = false;
|
||||||
|
const MAX_UNHEARD_TIME_BEFORE_DESTROYING_ENTITY_MS = 5000;
|
||||||
|
const MAX_DISTANCE_FROM_GAME_BEFORE_DESTROYING_ENTITY = 200;
|
||||||
for (var i = this.remainingEnemies.length - 1; i >= 0; --i) {
|
for (var i = this.remainingEnemies.length - 1; i >= 0; --i) {
|
||||||
var enemy = this.remainingEnemies[i];
|
var enemy = this.remainingEnemies[i];
|
||||||
var timeSinceLastHeartbeat = Date.now() - enemy.lastHeartbeat;
|
var timeSinceLastHeartbeat = Date.now() - enemy.lastHeartbeat;
|
||||||
var distance = Vec3.distance(enemy.lastKnownPosition, this.rootPosition);
|
var distance = Vec3.distance(enemy.lastKnownPosition, this.rootPosition);
|
||||||
if (timeSinceLastHeartbeat > 5000 || distance > 500) {
|
if (timeSinceLastHeartbeat > MAX_UNHEARD_TIME_BEFORE_DESTROYING_ENTITY_MS
|
||||||
|
|| distance > MAX_DISTANCE_FROM_GAME_BEFORE_DESTROYING_ENTITY) {
|
||||||
|
|
||||||
print("EXPIRING: ", enemy.id);
|
print("EXPIRING: ", enemy.id);
|
||||||
Entities.deleteEntity(enemy.id);
|
Entities.deleteEntity(enemy.id);
|
||||||
this.remainingEnemies.splice(i, 1);
|
this.remainingEnemies.splice(i, 1);
|
||||||
Audio.playSound(TARGET_HIT_SOUND, {
|
Audio.playSound(TARGET_HIT_SOUND, {
|
||||||
volume: 1.0,
|
volume: 1.0,
|
||||||
position: this.rootPosition,
|
position: this.rootPosition
|
||||||
});
|
});
|
||||||
this.setScore(this.score + 100);
|
this.setScore(this.score + POINTS_PER_KILL);
|
||||||
enemiesEscaped = true;
|
enemiesEscaped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -469,7 +478,8 @@ ShortbowGameManager.prototype = {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
Script.clearTimeout(this.nextWaveTimer);
|
Script.clearTimeout(this.nextWaveTimer);
|
||||||
this.nextWaveTimer = null;
|
this.nextWaveTimer = null;
|
||||||
for (var i = 0; i < this.spawnEnemyTimers.length; ++i) {
|
var i;
|
||||||
|
for (i = 0; i < this.spawnEnemyTimers.length; ++i) {
|
||||||
Script.clearTimeout(this.spawnEnemyTimers[i]);
|
Script.clearTimeout(this.spawnEnemyTimers[i]);
|
||||||
}
|
}
|
||||||
this.spawnEnemyTimers = [];
|
this.spawnEnemyTimers = [];
|
||||||
|
@ -478,11 +488,11 @@ ShortbowGameManager.prototype = {
|
||||||
this.checkEnemiesTimer = null;
|
this.checkEnemiesTimer = null;
|
||||||
|
|
||||||
|
|
||||||
for (var i = this.bowIDs.length - 1; i >= 0; i--) {
|
for (i = this.bowIDs.length - 1; i >= 0; i--) {
|
||||||
var id = this.bowIDs[i];
|
var id = this.bowIDs[i];
|
||||||
print("Checking bow: ", id);
|
print("Checking bow: ", id);
|
||||||
var userData = utils.parseJSON(Entities.getEntityProperties(id, 'userData').userData);
|
var userData = utils.parseJSON(Entities.getEntityProperties(id, 'userData').userData);
|
||||||
var bowIsHeld = userData.grabKey !== undefined && userData.grabKey !== undefined && userData.grabKey.refCount > 0
|
var bowIsHeld = userData.grabKey !== undefined && userData.grabKey !== undefined && userData.grabKey.refCount > 0;
|
||||||
print("Held: ", bowIsHeld);
|
print("Held: ", bowIsHeld);
|
||||||
if (!bowIsHeld) {
|
if (!bowIsHeld) {
|
||||||
Entities.deleteEntity(id);
|
Entities.deleteEntity(id);
|
||||||
|
@ -490,19 +500,20 @@ ShortbowGameManager.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.setTimeout(function() {
|
for (i = 0; i < this.remainingEnemies.length; i++) {
|
||||||
Entities.editEntity(this.startButtonID, { visible: true });
|
|
||||||
this.gameState = GAME_STATES.IDLE;
|
|
||||||
}.bind(this), 3000);
|
|
||||||
|
|
||||||
for (var i = 0; i < this.remainingEnemies.length; i++) {
|
|
||||||
Entities.deleteEntity(this.remainingEnemies[i].id);
|
Entities.deleteEntity(this.remainingEnemies[i].id);
|
||||||
}
|
}
|
||||||
this.remainingEnemies = [];
|
this.remainingEnemies = [];
|
||||||
|
|
||||||
|
// Wait a short time before showing the start button so that any current sounds
|
||||||
|
// can finish playing.
|
||||||
|
const WAIT_TO_REENABLE_GAME_TIMEOUT_MS = 3000;
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
Entities.editEntity(this.startButtonID, { visible: true });
|
||||||
|
this.gameState = GAME_STATES.IDLE;
|
||||||
|
}.bind(this), WAIT_TO_REENABLE_GAME_TIMEOUT_MS);
|
||||||
},
|
},
|
||||||
onReceivedMessage: function(channel, messageJSON, senderID) {
|
onReceivedMessage: function(channel, messageJSON, senderID) {
|
||||||
//print("shortbowGameManager.js | Recieved: " + messageJSON + " from " + senderID, channel, this.commChannelName);
|
|
||||||
|
|
||||||
if (channel === this.commChannelName) {
|
if (channel === this.commChannelName) {
|
||||||
var message = utils.parseJSON(messageJSON);
|
var message = utils.parseJSON(messageJSON);
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
|
@ -539,11 +550,11 @@ ShortbowGameManager.prototype = {
|
||||||
this.remainingEnemies.splice(i, 1);
|
this.remainingEnemies.splice(i, 1);
|
||||||
Audio.playSound(TARGET_HIT_SOUND, {
|
Audio.playSound(TARGET_HIT_SOUND, {
|
||||||
volume: 1.0,
|
volume: 1.0,
|
||||||
position: this.rootPosition,
|
position: this.rootPosition
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update score
|
// Update score
|
||||||
this.setScore(this.score + 100);
|
this.setScore(this.score + POINTS_PER_KILL);
|
||||||
print("SCORE: ", this.score);
|
print("SCORE: ", this.score);
|
||||||
|
|
||||||
this.checkWaveComplete();
|
this.checkWaveComplete();
|
||||||
|
@ -559,7 +570,7 @@ ShortbowGameManager.prototype = {
|
||||||
var enemiesEscaped = false;
|
var enemiesEscaped = false;
|
||||||
for (var i = this.remainingEnemies.length - 1; i >= 0; --i) {
|
for (var i = this.remainingEnemies.length - 1; i >= 0; --i) {
|
||||||
var enemy = this.remainingEnemies[i];
|
var enemy = this.remainingEnemies[i];
|
||||||
if (enemy.id == entityID) {
|
if (enemy.id === entityID) {
|
||||||
Entities.deleteEntity(enemy.id);
|
Entities.deleteEntity(enemy.id);
|
||||||
this.remainingEnemies.splice(i, 1);
|
this.remainingEnemies.splice(i, 1);
|
||||||
this.setLivesLeft(this.livesLeft - 1);
|
this.setLivesLeft(this.livesLeft - 1);
|
||||||
|
@ -579,11 +590,11 @@ ShortbowGameManager.prototype = {
|
||||||
onEnemyHeartbeat: function(entityID, position) {
|
onEnemyHeartbeat: function(entityID, position) {
|
||||||
for (var i = 0; i < this.remainingEnemies.length; i++) {
|
for (var i = 0; i < this.remainingEnemies.length; i++) {
|
||||||
var enemy = this.remainingEnemies[i];
|
var enemy = this.remainingEnemies[i];
|
||||||
if (enemy.id == entityID) {
|
if (enemy.id === entityID) {
|
||||||
enemy.lastHeartbeat = Date.now();
|
enemy.lastHeartbeat = Date.now();
|
||||||
enemy.lastKnownPosition = position;
|
enemy.lastKnownPosition = position;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals TEMPLATES:true, SHORTBOW_ENTITIES, ShortbowGameManager */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include('utils.js');
|
Script.include('utils.js');
|
||||||
Script.include('shortbow.js');
|
Script.include('shortbow.js');
|
||||||
|
@ -18,8 +20,6 @@
|
||||||
this.preload = function(entityID) {
|
this.preload = function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
|
||||||
var rootPosition = Entities.getEntityProperties(entityID, 'position').position;
|
|
||||||
|
|
||||||
var bowPositions = [];
|
var bowPositions = [];
|
||||||
var spawnPositions = [];
|
var spawnPositions = [];
|
||||||
for (var i = 0; i < TEMPLATES.length; ++i) {
|
for (var i = 0; i < TEMPLATES.length; ++i) {
|
||||||
|
|
|
@ -105,7 +105,7 @@ function createLocalGame() {
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
wantsTrigger: true
|
wantsTrigger: true
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
entityIDs.push(buttonID);
|
entityIDs.push(buttonID);
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ function createLocalGame() {
|
||||||
parentID: scoreboardID,
|
parentID: scoreboardID,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
displayType: "wave"
|
displayType: "wave"
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
entityIDs.push(waveDisplayID);
|
entityIDs.push(waveDisplayID);
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ function createLocalGame() {
|
||||||
parentID: scoreboardID,
|
parentID: scoreboardID,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
displayType: "score"
|
displayType: "score"
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
entityIDs.push(scoreDisplayID);
|
entityIDs.push(scoreDisplayID);
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ function createLocalGame() {
|
||||||
parentID: scoreboardID,
|
parentID: scoreboardID,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
displayType: "lives"
|
displayType: "lives"
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
entityIDs.push(livesDisplayID);
|
entityIDs.push(livesDisplayID);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ function createLocalGame() {
|
||||||
parentID: scoreboardID,
|
parentID: scoreboardID,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
displayType: "highscore"
|
displayType: "highscore"
|
||||||
}),
|
})
|
||||||
});
|
});
|
||||||
entityIDs.push(highScoreDisplayID);
|
entityIDs.push(highScoreDisplayID);
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals utils */
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include('utils.js');
|
Script.include('utils.js');
|
||||||
|
|
||||||
StartButton = function() {
|
function StartButton() {
|
||||||
};
|
}
|
||||||
StartButton.prototype = {
|
StartButton.prototype = {
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/* globals utils:true */
|
||||||
|
|
||||||
if (!Function.prototype.bind) {
|
if (!Function.prototype.bind) {
|
||||||
Function.prototype.bind = function(oThis) {
|
Function.prototype.bind = function(oThis) {
|
||||||
if (typeof this !== 'function') {
|
if (typeof this !== 'function') {
|
||||||
|
|
Loading…
Reference in a new issue