diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/block.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/block.js new file mode 100644 index 0000000000..8989ba648a --- /dev/null +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/block.js @@ -0,0 +1,23 @@ +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, + dimensions: BLOCK_DIMENSIONS, + dynamic: 1, + gravity: { x: 0.0, y: -9.8, z: 0.0 }, + collisionsWillMove: 1, + lifetime: BLOCK_LIFETIME, + script: Script.resolvePath("destructibleEntity.js") + }; +} diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/destructibleEntity.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/destructibleEntity.js index 3132305b88..2016e1e599 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/destructibleEntity.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/destructibleEntity.js @@ -53,6 +53,7 @@ function parseJSON(json) { var TEXTURE_NAME = "tex.health1"; (function() { + Script.include("block.js"); DestructibleBlock = function() { } DestructibleBlock.prototype = { @@ -138,6 +139,24 @@ var TEXTURE_NAME = "tex.health1"; 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); + }, + startNearTrigger: function () { + print("launch.js | got start near trigger"); + this.growBlock(); + }, + startFarTrigger: function () { + print("launch.js | got start far trigger"); + this.growBlock(); + }, + clickDownOnEntity: function () { + print("launch.js | got click down"); + this.growBlock(); } }; diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/launch.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/launch.js index 41988397e0..af40423b1b 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/launch.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/launch.js @@ -12,6 +12,8 @@ (function () { + Script.include("block.js"); + var BLOCK_MODEL_URL = Script.resolvePath("assets/block.fbx"); var BLOCK_DIMENSIONS = { x: 1, @@ -44,22 +46,12 @@ muzzleVelocity = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0.0, Math.random() * 360.0, 0.0), muzzleVelocity); muzzleVelocity = Vec3.multiplyQbyV(cylinder.rotation, muzzleVelocity); - Entities.addEntity({ - type: "Model", - name: "TD.block", - 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, - script: Script.resolvePath("destructibleEntity.js") - }); + 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, diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/towerDefense.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/towerDefense.js index 66f1cf526b..2a55212b59 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/towerDefense.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/towerDefense.js @@ -158,8 +158,10 @@ function cleanup() { var t = teamEntities[i]; Entities.deleteEntity(t.targetID); Entities.deleteEntity(t.spawnerID); - for (var j = 0; j < t.bowIDs.length; ++j) { - Entities.deleteEntity(t.bowIDs[j]); + 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);