content/hifi-public/PlanetDropBundle_v1/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

196 lines
4.5 KiB
JavaScript

// Player Class
Script.include(["pd_utils.js", "pd_podMover.js", "pd_radar.js", "pd_scanner.js", "pd_intro.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 = "http://nerdchallenge.com/hifi/images/techOverlay.png";
this.ControlStates = {
STEER: 0,
SCAN: 1,
INTRO: 2,
WAIT: 3
};
this.podMover = new PodMover();
this.controlState = this.ControlStates.WAIT;
this.radarDisplay = new RadarDisplay();
this.scanner = new Scanner();
this.intro = new Intro();
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)
{
player.controlState = player.ControlStates.SCAN;
player.scanner.activate();
player.hideTechOverlay();
print("SCAN mode active");
}
else if (player.controlState == player.ControlStates.SCAN)
{
player.scanner.deactivate();
player.controlState = player.ControlStates.STEER;
player.showTechOverlay();
print("STEER mode active");
} else if (player.controlState = player.ControlStates.INTRO)
{
printDebug("INTRO State");
}
}
};
playerSteerModeOnKeyPress = function(event)
{
var keyName = event.text;
if (event.isShifted)
keyName = "SHIFT+" + keyName;
// Disabling radar functionality
// if (keyName == "r")
// {
// print("Radar pinging...");
// print (player.name);
// player.radarDisplay.firePing();
// }
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);
// }
// Generically handles all events based on state
playerOnUpdate = function(deltaTime)
{
if (player.controlState == player.ControlStates.WAIT)
{
var currentTime = new Date();
if (currentTime - playerCreateTime > introDelay)
{
printDebug("Starting intro");
player.controlState = player.ControlStates.INTRO;
player.intro.startPresentation();
}
}
else if (player.controlState == player.ControlStates.INTRO)
{
player.intro.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)
{
if (player.controlState != player.ControlStates.INTRO)
playerCheckForModeChange(event);
if (player.controlState == player.ControlStates.INTRO)
{
player.intro.onKeyPress(event);
if (player.intro.isFinished)
{
player.controlState = player.ControlStates.STEER;
player.showTechOverlay();
}
}
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
}
}
// Connect into game loop
Camera.mode = "first person";
var player = new Player();
// 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);