Scripts/smivsTeretrurusScript.js |
"use strict";
// Standard attributes
this.name = "smivsTeretrurusScript.js";
this.author = "Smivs";
this.copyright = "© Smivs";
this.licence = "Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License";
this.version = "3.0";
this.description = "Script to render ship derelict upon ejection of pilot."
this.shipLaunchedEscapePod = function()
{
this.switchFlashersAITimer = new Timer(this, this.$switchFlashersOff,8); // timer to switch off flashers after 8 seconds
this.switchHullTexTimer = new Timer(this, this.$switchHullTex,12); // timer to switch off hull lights emission map after 12 seconds
this.rotateDerelictTimer = new Timer(this, this.$rotateDerelict,25); // timer to start derelict rotation after 25 secondsnds
}
this.$switchFlashersOff = function()
{
this.ship.lightsActive = false; // turns flashers off
}
this.$switchHullTex = function()
{
var $smivsTeretrurusTexture = this.ship.scriptInfo.smivsTeretrurusTexture; // uses scriptInfo key to build ship's default texture name
var $smivsTeretrurusDiffuse = this.ship.scriptInfo.smivsTeretrurusDiffuse; // uses scriptInfo key to build ship's diffuse_map name
var $smivsTeretrurusLighting = this.ship.scriptInfo.smivsTeretrurusLighting; // uses scriptInfo key to build ship's emission_map name
var $smivsTeretrurusDerelict = this.ship.scriptInfo.smivsTeretrurusDerelict; // uses scriptInfo key to build derelict emission_map name
var $smivsTeretrurusNormal = this.ship.scriptInfo.smivsTeretrurusNormal; // uses scriptInfo key to build ship's normal_map name
var $smivsTeretrurusSpecular = this.ship.scriptInfo.smivsTeretrurusSpecular; // uses scriptInfo key to build ship's specular_map name
var material = new Object(); // declare variable
material[$smivsTeretrurusTexture] = {diffuse_map:$smivsTeretrurusDiffuse, emission_map:$smivsTeretrurusDerelict, normal_map:$smivsTeretrurusNormal, specular_map:$smivsTeretrurusSpecular}; // set up material entry
this.ship.setMaterials(material); // apply material
}
this.$rotateDerelict = function()
{
this.rotateVector = Vector3D.randomDirection(); // creates a random axis of rotation.
this.rotateSpeedFactor = (Math.random() * (0.05) + 0.05); // creates a random rotate speed factor between 0.05 and 0.1 - 0.1 will result in a rotation speed of approx 1 full rotation every 63 seconds, 0.05 in a rotation speed of approx 1 full rotation every 126 seconds.
this.rotateDerelictCallBack = addFrameCallback(this.rotateFunction.bind(this)); // create FrameCallback
}
this.rotateFunction = function(delta) // delta is the time in game seconds since the last frame.
{
if (!this.ship.isValid){removeFrameCallback(this.rotateDerelictCallback);delete this.rotateDerelictCallback;return;} // end FrameCallback is ship has died;
if (delta === 0){return;} // do nothing if game is paused;
var newOrientation = this.ship.orientation.rotate(this.rotateVector,delta*this.rotateSpeedFactor); // calculates new orientation, using delta as a factor so that rotation speed is constant across varying frame rates. delta*this.rotateSpeedFactor is a value in radians. There are approx 6.3 radians in a full rotation.
this.ship.orientation = newOrientation; // applies new orientation;
}
this.entityDestroyed = function()
// stop timers
{
if(this.switchFlashersAITimer)
{
if (this.switchFlashersAITimer.isRunning)
{
this.switchFlashersAITimer.stop();
delete this.switchFlashersAITimer;
}
}
if(this.switchHullTexTimer)
{
if (this.switchHullTexTimer.isRunning)
{
this.switchHullTexTimer.stop();
delete this.switchHullTexTimer;
}
}
if(this.rotateDerelictTimer)
{
if (this.rotateDerelictTimer.isRunning)
{
this.rotateDerelictTimer.stop();
delete this.rotateDerelictTimer;
}
}
}
|