Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them has been replaced with a symlink. Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still be present.
105 lines
3.4 KiB
JavaScript
105 lines
3.4 KiB
JavaScript
(function() {
|
|
var self = this;
|
|
|
|
var DEFAULT_ACCELERATION = { x: 0, y: -10, z: 0 };
|
|
var BOOST_ACCELERATION = { x: 0, y: 1, z: 0 };
|
|
var STATE_IDLE = 0;
|
|
var STATE_BOOSTING = 1;
|
|
var STATE_LAUNCHING = 2;
|
|
|
|
self.state = STATE_IDLE;
|
|
|
|
self.entityID = null;
|
|
self.launching = false;
|
|
|
|
self.preload = function(entityID) {
|
|
self.entityID = entityID;
|
|
}
|
|
|
|
self.startBoost = function() {
|
|
if (self.state === STATE_IDLE) {
|
|
self.state = STATE_BOOSTING;
|
|
self.setParticlesOn(true);
|
|
Entities.editEntity(self.entityID, { gravity: BOOST_ACCELERATION });
|
|
}
|
|
}
|
|
self.stopBoost = function() {
|
|
if (self.state === STATE_BOOSTING) {
|
|
self.state = STATE_IDLE;
|
|
self.setParticlesOn(false);
|
|
Entities.editEntity(self.entityID, { gravity: DEFAULT_ACCELERATION });
|
|
}
|
|
}
|
|
|
|
self.launch = function() {
|
|
print("here");
|
|
if (self.state === STATE_LAUNCHING) {
|
|
return;
|
|
}
|
|
|
|
print("here2");
|
|
|
|
self.state = STATE_LAUNCHING;
|
|
self.setParticlesOn(true);
|
|
|
|
Script.setTimeout(function() {
|
|
Entities.editEntity(self.entityID, { gravity: { x: 0, y: 1.0, z: 0 } });
|
|
}, 500);
|
|
Script.setTimeout(function() {
|
|
Entities.editEntity(self.entityID, { gravity: { x: 0, y: 0.4, z: 0 } });
|
|
}, 2000);
|
|
Script.setTimeout(function() {
|
|
Entities.editEntity(self.entityID, { velocity: { x: 0, y: 20 + Math.random() * 80, z: 0 }, gravity: DEFAULT_ACCELERATION });
|
|
}, 3000);
|
|
Script.setTimeout(function() {
|
|
print("Done");
|
|
//Entities.editEntity(self.entityID, { gravity: DEFAULT_ACCELERATION });
|
|
self.setParticlesOn(false);
|
|
self.state = STATE_IDLE;
|
|
}, 4000);
|
|
}
|
|
|
|
self.setParticlesOn = function(on) {
|
|
var childrenIDs = Entities.getChildrenIDs(self.entityID);
|
|
for (var i = 0; i < childrenIDs.length; ++i) {
|
|
var entityID = childrenIDs[i];
|
|
if (Entities.getEntityProperties(entityID, 'type').type === 'ParticleEffect') {
|
|
Entities.editEntity(entityID, { emitRate: (on ? 200 : 0) });
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//self.clickDownOnEntity = self.launch;
|
|
Messages.subscribe('RocketChair');
|
|
Messages.messageReceived.connect(this, function(channel, message, sender) {
|
|
if (channel === 'RocketChair') {
|
|
if (message === 'startBoost') {
|
|
self.startBoost();
|
|
} else if (message === 'stopBoost') {
|
|
self.stopBoost();
|
|
} else if (message === 'launch') {
|
|
self.launch();
|
|
}
|
|
}
|
|
});
|
|
|
|
var timerID = Script.setInterval(function() {
|
|
var props = Entities.getEntityProperties(self.entityID, ['velocity', 'rotation']);
|
|
if (Vec3.length(props.velocity) < 0.1) {
|
|
var up = Vec3.multiplyQbyV(props.rotation, { x: 0, y: 1, z: 0 });
|
|
var angleFromUp = Math.acos(Vec3.dot(up, { x: 0, y: 1, z: 0 }));
|
|
print("Angle is ", angleFromUp);
|
|
if (angleFromUp > Math.PI / 4) {
|
|
Entities.editEntity(self.entityID, { rotation: { x: 0, y: 0, z: 0, w: 1 } });
|
|
}
|
|
|
|
}
|
|
}, 2000);
|
|
|
|
Script.scriptEnding.connect(function() {
|
|
Messages.messageReceived.disconnect(this);
|
|
Script.clearInterval(timerID);
|
|
});
|
|
return self;
|
|
})
|