content/hifi-public/PlanetDropBundle_v2/scripts/pd_player.js
Dale Glass 0d14e5a379 Initial data.
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.
2022-02-13 18:59:11 +01:00

251 lines
6.5 KiB
JavaScript

// Player Class
Script.include(["pd_utils.js", "pd_podMover.js", "pd_radar.js", "pd_scanner.js", "pd_intro.js", "pd_missionControl.js"]);
var playerCreateTime = new Date();
var introDelay = 2000;
var playerResetLocation = {x:0, y:22, z:0};
var Player = function()
{
print("Player Constructor");
this.name = "player";
this.techOverlayUrl = pd_path("images/techOverlay.png");
this.ControlStates = {
GAME_START: 0,
STEER: 1,
SCAN: 2,
INTRO: 3,
MISSION_BRIEF: 4,
MISSION_DEBRIEF: 5,
};
this.podMover = new PodMover();
this.controlState = this.ControlStates.GAME_START;
this.radarDisplay = new RadarDisplay();
this.scanner = new Scanner();
this.intro = new Intro();
this.missionControl = new MissionControl();
this.techOverlay = createImageOverlay(this.techOverlayUrl, {x:Window.innerWidth/2 - 512,y:Window.innerHeight/2 - 407}, false, 1024, 815 );
this.showTechOverlay = function()
{
Overlays.editOverlay(this.techOverlay, {visible:true});
}
this.hideTechOverlay = function()
{
Overlays.editOverlay(this.techOverlay, {visible:false});
}
};
// Called from steer and scan modes
playerCheckForModeChange = function(event)
{
//printDebug("playerGenericCheckControls");
var keyName = event.text;
if (keyName == "m")
{
if (player.controlState == player.ControlStates.STEER)
{
playerChangeControlState(player.ControlStates.SCAN);
player.scanner.activate();
player.hideTechOverlay();
}
else if (player.controlState == player.ControlStates.SCAN)
{
player.scanner.deactivate();
playerChangeControlState(player.ControlStates.STEER);
player.showTechOverlay();
}
}
};
// Handles key press processing when in STEER mode
playerSteerModeOnKeyPress = function(event)
{
var keyName = event.text;
if (event.isShifted)
keyName = "SHIFT+" + keyName;
// Disabling radar functionality
// if (keyName == "v")
// {
// printDebug("Mission Brief...");
// player.missionControl.startNextMission();
// }
if (keyName == "b")
{
MyAvatar.goToLocation(playerResetLocation);
MyAvatar.motorVelocity = {x:0,y:0,z:0};
}
player.podMover.keyPressEvent(event);
};
playerScanModeOnKeyPress = function(event)
{
var keyName = event.text;
if (event.isShifted)
keyName = "SHIFT+" + keyName;
player.scanner.onKeyPress(event);
}
playerScriptEnding = function()
{
//MyAvatar.detachOne(POD_MODEL);
player.scanner.deconstruct();
player.intro.deconstruct();
Overlays.deleteOverlay(player.techOverlay);
}
// putPlayerInPod = function()
// {
// var podScale = 7;
// MyAvatar.attach(POD_MODEL, "Hips", {x:0, y:-0.36, z:0.04}, Quat.fromPitchYawRollDegrees(0,0,0), podScale, false, false);
// }
// Main Game Loop: Generically handles all events based on state
playerOnUpdate = function(deltaTime)
{
//printDebug("Player.playerOnUpdate: " + string_of_enum(player.ControlStates, player.controlState));
if (player.controlState == player.ControlStates.GAME_START)
{
var currentTime = new Date();
if (currentTime - playerCreateTime > introDelay)
{
//printDebug("Starting intro");
playerChangeControlState(player.ControlStates.INTRO);
player.intro.startPresentation();
}
}
else if (player.controlState == player.ControlStates.INTRO)
{
player.intro.scriptUpdate(deltaTime);
}
else if (player.controlState == player.ControlStates.MISSION_BRIEF ||
player.controlState == player.ControlStates.MISSION_DEBRIEF )
{
player.missionControl.scriptUpdate(deltaTime);
}
else if (player.controlState == player.ControlStates.STEER)
{
player.podMover.updateMotor(deltaTime);
}
else if (player.controlState == player.ControlStates.SCAN)
{
player.scanner.scriptUpdate(deltaTime);
}
}
playerOnKeyPress = function(event)
{
// Allow for mode change during STEER and SCAN
if (player.controlState == player.ControlStates.STEER || player.controlState == player.ControlStates.SCAN)
playerCheckForModeChange(event);
if (player.controlState == player.ControlStates.INTRO)
{
player.intro.onKeyPress(event); // Pass control to Intro object
if (player.intro.isFinished)
{
playerChangeControlState(player.ControlStates.MISSION_BRIEF);
player.missionControl.startNextMission();
}
}
else if (player.controlState == player.ControlStates.MISSION_BRIEF)
{
player.missionControl.onKeyPress(event); // Pass control to Intro object
if (player.missionControl.isFinished)
{
playerChangeControlState(player.ControlStates.STEER);
player.showTechOverlay();
}
}
else if (player.controlState == player.ControlStates.MISSION_DEBRIEF)
{
player.missionControl.onKeyPress(event); // Pass control to Intro object
if (player.missionControl.isFinished)
{
playerChangeControlState(player.ControlStates.MISSION_BRIEF);
player.missionControl.startNextMission();
}
}
else if (player.controlState == player.ControlStates.STEER)
{
playerSteerModeOnKeyPress(event);
}
else if (player.controlState == player.ControlStates.SCAN)
{
playerScanModeOnKeyPress(event);
}
}
playerOnKeyRelease = function(event)
{
if (player.controlState == player.ControlStates.INTRO)
{
// No action
}
else if (player.controlState == player.ControlStates.STEER)
{
player.podMover.keyReleaseEvent(event);
}
else if (player.controlState == player.ControlStates.SCAN)
{
// No action
}
}
// Called by Scanner when new item analyzed
playerOnScanNewItem = function()
{
var delayBeforeDebrief = 5000;
var missionComplete = player.missionControl.checkMissionProgress(player.scanner.analyzedDict);
if (missionComplete)
{
Script.setTimeout( function() {
printDebug("MISSION COMPLETE");
player.scanner.deactivate();
playerChangeControlState(player.ControlStates.MISSION_DEBRIEF);
player.missionControl.startDebrief();
}, delayBeforeDebrief );
}
}
playerChangeControlState = function(newState)
{
printDebug("Player.changeState. From " + string_of_enum(player.ControlStates, player.controlState) + " => " +
string_of_enum(player.ControlStates, newState));
player.controlState = newState;
}
onDomainChanged = function()
{
print("Domain changed");
Script.stop();
}
// Connect into game loop
Camera.mode = "first person";
var player = new Player();
player.scanner.scanCallback = playerOnScanNewItem; // Attach scanner callback
// Disabling pod for now
//putPlayerInPod();
MyAvatar.goToLocation(playerResetLocation);
Controller.keyPressEvent.connect(playerOnKeyPress);
Controller.keyReleaseEvent.connect(playerOnKeyRelease);
Script.update.connect(playerOnUpdate);
// Cleanup
Script.scriptEnding.connect(playerScriptEnding);
Window.domainChanged.connect(onDomainChanged);