// // shower-script.js // // created by Liv // Copyright 2018 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 // /* globals AnimationCache, MyAvatar */ (function() { var _this; var CLIMBING_RESOURCE = AnimationCache.prefetch(Script.resolvePath("animations/climbingStruggle.fbx")); var CLIMBING_ANIMATION = AnimationCache.getAnimation(Script.resolvePath("animations/climbingStruggle.fbx")); var CLIMBING_HEIGHT_PROPORTION = 0.8533044; var STAND_RESOURCE = AnimationCache.prefetch(Script.resolvePath("animations/Stand.fbx")); var STAND_ANIMATION = AnimationCache.getAnimation(Script.resolvePath("animations/Stand.fbx")); var FALL_RESOURCE = AnimationCache.prefetch(Script.resolvePath("animations/fall.fbx")); var FALL_ANIMATION = AnimationCache.getAnimation(Script.resolvePath("animations/fall.fbx")); var SPLASH_HIT_SOUND = sound = SoundCache.getSound(Script.resolvePath("Sounds/animationSwap.wav")); var SPLASHING_SOUND = sound = SoundCache.getSound(Script.resolvePath("Sounds/animationSwap.wav")); var ZOMBIE_SOUND = sound = SoundCache.getSound(Script.resolvePath("Sounds/animationSwap.wav")); var FPS = 30; var AUDIO_VOLUME_LEVEL = 0.5; var REPLAY_INTERVAL = 10000; var ONE_SECOND_MS = 1000; var sound; var interval; var ClimbingZombie = function() { _this = this; }; ClimbingZombie.prototype = { preload: function(entityID) { _this.entityID = entityID; interval = Script.setInterval(function() { var properties; var yPosition; Entities.editEntity(_this.entityID, { animation: { url: CLIMBING_RESOURCE.url, currentFrame: 0, firstFrame: 0, lastFrame: CLIMBING_ANIMATION.frames.length, hold: false, fps: 30, loop: false, running: true, allowTranslation: true } }); Script.setTimeout(function() { // properties = Entities.getEntityProperties(_this.entityID, ['position', 'dimensions']); // yPosition = properties.position.y; // yPosition += (CLIMBING_HEIGHT_PROPORTION * properties.dimensions.y); // Entities.editEntity(_this.entityID, { // position: { // x: properties.position.x, // y: yPosition, // z: properties.position.z // } // }); Entities.editEntity(_this.entityID, { animation: { url: STAND_RESOURCE.url, currentFrame: 0, firstFrame: 0, lastFrame: STAND_ANIMATION.frames.length, hold: false, fps: 30, loop: false, running: true, allowTranslation: true } }); Script.setTimeout(function() { Entities.editEntity(_this.entityID, { animation: { url: FALL_RESOURCE.url, currentFrame: 0, firstFrame: 0, lastFrame: 75, hold: false, fps: 30, loop: false, running: true, allowTranslation: true } }); }, 75 / FPS * ONE_SECOND_MS ); }, 148 / FPS * ONE_SECOND_MS ); // yPosition -= (CLIMBING_HEIGHT_PROPORTION * properties.dimensions.y); // Entities.editEntity(_this.entityID, { // position: { // x: properties.position.x, // y: yPosition, // z: properties.position.z // } // }); }, REPLAY_INTERVAL); }, playSound: function(position) { if (sound.downloaded) { Audio.playSound(sound, { position: position, volume: AUDIO_VOLUME_LEVEL }); } }, unload: function() { if (interval) { Script.clearInterval(interval); } } }; return new ClimbingZombie(); });