added reference to correct zombie game script

This commit is contained in:
ericrius1 2015-07-16 18:30:24 -07:00
parent 66154d20e0
commit 220b54e5f7

View file

@ -30,14 +30,20 @@ var dimensions = {
}; };
var BUTTON_SIZE = 32; var BUTTON_SIZE = 32;
var health = 100;
var healthLossOnHit = 10;
var swordModel = "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.fbx"; var swordModel = "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.fbx";
// var swordCollisionShape = "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.obj"; // var swordCollisionShape = "https://hifi-public.s3.amazonaws.com/ozan/props/sword/sword.obj";
var swordCollisionShape = "https://hifi-public.s3.amazonaws.com/eric/models/noHandleSwordCollisionShape.obj?=v1"; var swordCollisionShape = "https://hifi-public.s3.amazonaws.com/eric/models/noHandleSwordCollisionShape.obj?=v2";
var swordCollisionSoundURL = "http://public.highfidelity.io/sounds/Collisions-hitsandslaps/swordStrike1.wav"; var swordCollisionSoundURL = "http://public.highfidelity.io/sounds/Collisions-hitsandslaps/swordStrike1.wav";
var avatarCollisionSoundURL = "https://s3.amazonaws.com/hifi-public/sounds/Collisions-hitsandslaps/airhockey_hit1.wav"; var avatarCollisionSoundURL = "https://hifi-public.s3.amazonaws.com/eric/sounds/blankSound.wav"; //Just to avoid no collision callback bug
var zombieGameScriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/zombieFight.js";
var whichModel = "sword"; var whichModel = "sword";
var originalAvatarCollisionSound; var originalAvatarCollisionSound;
var avatarCollisionSounds = [SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/avatarHit.wav"), SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/avatarHit2.wav?=v2")];
var toolBar = new ToolBar(0, 0, ToolBar.vertical, "highfidelity.sword.toolbar", function() { var toolBar = new ToolBar(0, 0, ToolBar.vertical, "highfidelity.sword.toolbar", function() {
return { return {
x: 100, x: 100,
@ -45,6 +51,8 @@ var toolBar = new ToolBar(0, 0, ToolBar.vertical, "highfidelity.sword.toolbar",
}; };
}); });
var gameStarted = false;
var SWORD_IMAGE = "https://hifi-public.s3.amazonaws.com/images/sword/sword.svg"; // Toggle between brandishing/sheathing sword (creating if necessary) var SWORD_IMAGE = "https://hifi-public.s3.amazonaws.com/images/sword/sword.svg"; // Toggle between brandishing/sheathing sword (creating if necessary)
var TARGET_IMAGE = "https://hifi-public.s3.amazonaws.com/images/sword/dummy2.svg"; // Create a target dummy var TARGET_IMAGE = "https://hifi-public.s3.amazonaws.com/images/sword/dummy2.svg"; // Create a target dummy
var CLEANUP_IMAGE = "http://s3.amazonaws.com/hifi-public/images/delete.png"; // Remove sword and all target dummies.f var CLEANUP_IMAGE = "http://s3.amazonaws.com/hifi-public/images/delete.png"; // Remove sword and all target dummies.f
@ -109,7 +117,7 @@ function flash(color) {
flasher.timer = Script.setTimeout(clearFlash, 500); flasher.timer = Script.setTimeout(clearFlash, 500);
} }
var health = 100;
var display2d, display3d; var display2d, display3d;
function trackAvatarWithText() { function trackAvatarWithText() {
@ -126,7 +134,6 @@ function trackAvatarWithText() {
function updateDisplay() { function updateDisplay() {
var text = health.toString(); var text = health.toString();
if (!display2d) { if (!display2d) {
health = 100;
display2d = Overlays.addOverlay("text", { display2d = Overlays.addOverlay("text", {
text: text, text: text,
font: { font: {
@ -190,7 +197,24 @@ function removeDisplay() {
function gotHit(collision) { function gotHit(collision) {
health -= 1; Audio.playSound(avatarCollisionSounds[randInt(0, avatarCollisionSounds.length)], {
position: MyAvatar.position,
volume: 0.5
});
health -= healthLossOnHit;
if (health <= 30) {
Overlays.editOverlay(display2d, {
color: {
red: 200,
green: 10,
blue: 10
}
});
}
if (health <= 0 && zombieFight) {
zombieFight.loseGame();
}
flash({ flash({
red: 255, red: 255,
green: 0, green: 0,
@ -239,6 +263,7 @@ function cleanUp(leaveButtons) {
toolBar.cleanup(); toolBar.cleanup();
} }
removeSword(); removeSword();
gameStarted = false;
zombieFight.cleanup(); zombieFight.cleanup();
} }
@ -265,7 +290,7 @@ function makeSword() {
SoundCache.getSound(avatarCollisionSoundURL); // Interface does not currently "preload" this? (Bug?) SoundCache.getSound(avatarCollisionSoundURL); // Interface does not currently "preload" this? (Bug?)
} }
if(!isControllerActive()) { if (!isControllerActive()) {
grabSword("right"); grabSword("right");
} }
MyAvatar.collisionSoundURL = avatarCollisionSoundURL; MyAvatar.collisionSoundURL = avatarCollisionSoundURL;
@ -277,6 +302,10 @@ function makeSword() {
function grabSword(hand) { function grabSword(hand) {
if (!swordID) {
print("Create a sword by clicking on sword icon!")
return;
}
var handRotation; var handRotation;
if (hand === "right") { if (hand === "right") {
handRotation = MyAvatar.getRightPalmRotation(); handRotation = MyAvatar.getRightPalmRotation();
@ -292,7 +321,7 @@ function grabSword(hand) {
y: 0.0, y: 0.0,
z: -dimensions.z * 0.5 z: -dimensions.z * 0.5
}, },
relativeRotation:offsetRotation, relativeRotation: offsetRotation,
hand: hand, hand: hand,
timeScale: 0.05 timeScale: 0.05
}); });
@ -358,7 +387,11 @@ randInt = function(low, high) {
function positionSword(swordOrientation) { function positionSword(swordOrientation) {
var reorient = Quat.fromPitchYawRollDegrees(0, -90, 0); var reorient = Quat.fromPitchYawRollDegrees(0, -90, 0);
var baseOffset = {x: -dimensions.z * 0.8, y: 0, z: 0}; var baseOffset = {
x: -dimensions.z * 0.8,
y: 0,
z: 0
};
var offset = Vec3.multiplyQbyV(reorient, baseOffset); var offset = Vec3.multiplyQbyV(reorient, baseOffset);
swordOrientation = Quat.multiply(reorient, swordOrientation); swordOrientation = Quat.multiply(reorient, swordOrientation);
inHand = false; inHand = false;
@ -368,6 +401,7 @@ function positionSword(swordOrientation) {
hand: "right" hand: "right"
}); });
} }
function resetToHand() { // For use with controllers, puts the sword in contact with the hand. function resetToHand() { // For use with controllers, puts the sword in contact with the hand.
// Maybe coordinate with positionSword? // Maybe coordinate with positionSword?
if (inHand) { // Optimization: bail if we're already inHand. if (inHand) { // Optimization: bail if we're already inHand.
@ -375,10 +409,18 @@ function resetToHand() { // For use with controllers, puts the sword in contact
} }
print('Reset to hand'); print('Reset to hand');
Entities.updateAction(swordID, actionID, { Entities.updateAction(swordID, actionID, {
relativePosition: {x: 0.0, y: 0.0, z: -dimensions.z * 0.5}, relativePosition: {
relativeRotation: Quat.fromVec3Degrees({x: 45.0, y: 0.0, z: 0.0}), x: 0.0,
hand: "right", // It should not be necessary to repeat these two, but there seems to be a bug in that that y: 0.0,
timeScale: 0.05 // they do not retain their earlier values if you don't repeat them. z: -dimensions.z * 0.5
},
relativeRotation: Quat.fromVec3Degrees({
x: 45.0,
y: 0.0,
z: 0.0
}),
hand: "right", // It should not be necessary to repeat these two, but there seems to be a bug in that that
timeScale: 0.05 // they do not retain their earlier values if you don't repeat them.
}); });
inHand = true; inHand = true;
} }
@ -411,9 +453,14 @@ function onClick(event) {
} }
break; break;
case targetButton: case targetButton:
Script.include("zombieFight.js?v1"); if (gameStarted) {
return;
}
Script.include("https://hifi-public.s3.amazonaws.com/eric/scripts/zombieFight.js");
zombieFight = new ZombieFight(); zombieFight = new ZombieFight();
zombieFight.initiateZombieApocalypse(); zombieFight.initiateZombieApocalypse();
gameStarted = true;
break; break;
case cleanupButton: case cleanupButton:
cleanUp('leaveButtons'); cleanUp('leaveButtons');