mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:38:27 +02:00
Added shootable blocks on platform, grenade, buttons for making grid of targets
This commit is contained in:
parent
e02e0088af
commit
6567fcfe0b
1 changed files with 126 additions and 88 deletions
|
@ -112,6 +112,25 @@ var offButton = Overlays.addOverlay("image", {
|
||||||
alpha: 1
|
alpha: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var platformButton = Overlays.addOverlay("image", {
|
||||||
|
x: screenSize.x - 48,
|
||||||
|
y: 130,
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
imageURL: HIFI_PUBLIC_BUCKET + "images/city.png",
|
||||||
|
color: { red: 255, green: 255, blue: 255},
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
var gridButton = Overlays.addOverlay("image", {
|
||||||
|
x: screenSize.x - 48,
|
||||||
|
y: 164,
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
imageURL: HIFI_PUBLIC_BUCKET + "images/blocks.png",
|
||||||
|
color: { red: 255, green: 255, blue: 255},
|
||||||
|
alpha: 1
|
||||||
|
});
|
||||||
|
|
||||||
if (showScore) {
|
if (showScore) {
|
||||||
var text = Overlays.addOverlay("text", {
|
var text = Overlays.addOverlay("text", {
|
||||||
x: screenSize.x / 2 - 100,
|
x: screenSize.x / 2 - 100,
|
||||||
|
@ -126,26 +145,30 @@ if (showScore) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function printVector(string, vector) {
|
var BULLET_VELOCITY = 10.0;
|
||||||
print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
var BULLET_VELOCITY = 15.0;
|
function shootBullet(position, velocity, grenade) {
|
||||||
|
var BULLET_SIZE = 0.10;
|
||||||
function shootBullet(position, velocity) {
|
|
||||||
var BULLET_SIZE = 0.07;
|
|
||||||
var BULLET_LIFETIME = 10.0;
|
var BULLET_LIFETIME = 10.0;
|
||||||
var BULLET_GRAVITY = -0.25;
|
var BULLET_GRAVITY = -0.25;
|
||||||
|
var GRENADE_VELOCITY = 15.0;
|
||||||
|
var GRENADE_SIZE = 0.35;
|
||||||
|
var GRENADE_GRAVITY = -9.8;
|
||||||
|
|
||||||
|
var bVelocity = grenade ? Vec3.multiply(GRENADE_VELOCITY, Vec3.normalize(velocity)) : velocity;
|
||||||
|
var bSize = grenade ? GRENADE_SIZE : BULLET_SIZE;
|
||||||
|
var bGravity = grenade ? GRENADE_GRAVITY : BULLET_GRAVITY;
|
||||||
|
|
||||||
bulletID = Entities.addEntity(
|
bulletID = Entities.addEntity(
|
||||||
{ type: "Sphere",
|
{ type: "Sphere",
|
||||||
position: position,
|
position: position,
|
||||||
dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE },
|
dimensions: { x: bSize, y: bSize, z: bSize },
|
||||||
color: { red: 255, green: 0, blue: 0 },
|
color: { red: 255, green: 0, blue: 0 },
|
||||||
velocity: velocity,
|
velocity: bVelocity,
|
||||||
lifetime: BULLET_LIFETIME,
|
lifetime: BULLET_LIFETIME,
|
||||||
gravity: { x: 0, y: BULLET_GRAVITY, z: 0 },
|
gravity: { x: 0, y: bGravity, z: 0 },
|
||||||
damping: 0.01,
|
damping: 0.01,
|
||||||
density: 10000,
|
density: 8000,
|
||||||
ignoreCollisions: false,
|
ignoreCollisions: false,
|
||||||
collisionsWillMove: true
|
collisionsWillMove: true
|
||||||
});
|
});
|
||||||
|
@ -168,51 +191,6 @@ function shootBullet(position, velocity) {
|
||||||
MyAvatar.setJointData("LeftForeArm", armRotation);
|
MyAvatar.setJointData("LeftForeArm", armRotation);
|
||||||
elbowKickAngle = KICKBACK_ANGLE;
|
elbowKickAngle = KICKBACK_ANGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeGrid(type, gravity, scale, size) {
|
|
||||||
var separation = scale * 2;
|
|
||||||
var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation())));
|
|
||||||
pos.y -= separation * size;
|
|
||||||
var x, y, z;
|
|
||||||
var GRID_LIFE = 60.0;
|
|
||||||
var dimensions;
|
|
||||||
|
|
||||||
for (x = 0; x < size; x++) {
|
|
||||||
for (y = 0; y < size; y++) {
|
|
||||||
for (z = 0; z < size; z++) {
|
|
||||||
if (gravity == 0) {
|
|
||||||
dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 };
|
|
||||||
} else {
|
|
||||||
dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/4.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) };
|
|
||||||
}
|
|
||||||
|
|
||||||
Entities.addEntity(
|
|
||||||
{ type: type,
|
|
||||||
position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation },
|
|
||||||
dimensions: dimensions,
|
|
||||||
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
|
|
||||||
velocity: { x: 0, y: 0, z: 0 },
|
|
||||||
gravity: { x: 0, y: gravity, z: 0 },
|
|
||||||
lifetime: GRID_LIFE,
|
|
||||||
rotation: Camera.getOrientation(),
|
|
||||||
damping: 0.1,
|
|
||||||
density: 100.0,
|
|
||||||
collisionsWillMove: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gravity < 0) {
|
|
||||||
// Make a floor for this stuff to fall onto
|
|
||||||
Entities.addEntity({
|
|
||||||
type: "Box",
|
|
||||||
position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z },
|
|
||||||
dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size },
|
|
||||||
color: { red: 128, green: 128, blue: 128 },
|
|
||||||
lifetime: GRID_LIFE
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function shootTarget() {
|
function shootTarget() {
|
||||||
var TARGET_SIZE = 0.50;
|
var TARGET_SIZE = 0.50;
|
||||||
var TARGET_GRAVITY = 0.0;
|
var TARGET_GRAVITY = 0.0;
|
||||||
|
@ -222,7 +200,7 @@ function shootTarget() {
|
||||||
var DISTANCE_TO_LAUNCH_FROM = 5.0;
|
var DISTANCE_TO_LAUNCH_FROM = 5.0;
|
||||||
var ANGLE_RANGE_FOR_LAUNCH = 20.0;
|
var ANGLE_RANGE_FOR_LAUNCH = 20.0;
|
||||||
var camera = Camera.getPosition();
|
var camera = Camera.getPosition();
|
||||||
//printVector("camera", camera);
|
|
||||||
var targetDirection = Quat.angleAxis(getRandomFloat(-ANGLE_RANGE_FOR_LAUNCH, ANGLE_RANGE_FOR_LAUNCH), { x:0, y:1, z:0 });
|
var targetDirection = Quat.angleAxis(getRandomFloat(-ANGLE_RANGE_FOR_LAUNCH, ANGLE_RANGE_FOR_LAUNCH), { x:0, y:1, z:0 });
|
||||||
targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection);
|
targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection);
|
||||||
var forwardVector = Quat.getFront(targetDirection);
|
var forwardVector = Quat.getFront(targetDirection);
|
||||||
|
@ -253,6 +231,78 @@ function shootTarget() {
|
||||||
Audio.playSound(targetLaunchSound, audioOptions);
|
Audio.playSound(targetLaunchSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeGrid(type, scale, size) {
|
||||||
|
var separation = scale * 2;
|
||||||
|
var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation())));
|
||||||
|
var x, y, z;
|
||||||
|
var GRID_LIFE = 60.0;
|
||||||
|
var dimensions;
|
||||||
|
|
||||||
|
for (x = 0; x < size; x++) {
|
||||||
|
for (y = 0; y < size; y++) {
|
||||||
|
for (z = 0; z < size; z++) {
|
||||||
|
|
||||||
|
dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 };
|
||||||
|
|
||||||
|
Entities.addEntity(
|
||||||
|
{ type: type,
|
||||||
|
position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation },
|
||||||
|
dimensions: dimensions,
|
||||||
|
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
|
||||||
|
velocity: { x: 0, y: 0, z: 0 },
|
||||||
|
gravity: { x: 0, y: 0, z: 0 },
|
||||||
|
lifetime: GRID_LIFE,
|
||||||
|
rotation: Camera.getOrientation(),
|
||||||
|
damping: 0.1,
|
||||||
|
density: 100.0,
|
||||||
|
collisionsWillMove: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function makePlatform(gravity, scale, size) {
|
||||||
|
var separation = scale * 2;
|
||||||
|
var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation())));
|
||||||
|
pos.y -= separation * size;
|
||||||
|
var x, y, z;
|
||||||
|
var TARGET_LIFE = 60.0;
|
||||||
|
var INITIAL_GAP = 0.5;
|
||||||
|
var dimensions;
|
||||||
|
|
||||||
|
for (x = 0; x < size; x++) {
|
||||||
|
for (y = 0; y < size; y++) {
|
||||||
|
for (z = 0; z < size; z++) {
|
||||||
|
|
||||||
|
dimensions = { x: separation/2.0, y: separation, z: separation/2.0 };
|
||||||
|
|
||||||
|
Entities.addEntity(
|
||||||
|
{ type: "Box",
|
||||||
|
position: { x: pos.x - (separation * size / 2.0) + x * separation,
|
||||||
|
y: pos.y + y * (separation + INITIAL_GAP),
|
||||||
|
z: pos.z - (separation * size / 2.0) + z * separation },
|
||||||
|
dimensions: dimensions,
|
||||||
|
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
|
||||||
|
velocity: { x: 0, y: 0, z: 0 },
|
||||||
|
gravity: { x: 0, y: gravity, z: 0 },
|
||||||
|
lifetime: TARGET_LIFE,
|
||||||
|
damping: 0.1,
|
||||||
|
density: 100.0,
|
||||||
|
collisionsWillMove: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a floor for this stuff to fall onto
|
||||||
|
Entities.addEntity({
|
||||||
|
type: "Box",
|
||||||
|
position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z },
|
||||||
|
dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size },
|
||||||
|
color: { red: 128, green: 128, blue: 128 },
|
||||||
|
lifetime: TARGET_LIFE
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function entityCollisionWithEntity(entity1, entity2, collision) {
|
function entityCollisionWithEntity(entity1, entity2, collision) {
|
||||||
|
|
||||||
if (((entity1.id == bulletID.id) || (entity1.id == targetID.id)) &&
|
if (((entity1.id == bulletID.id) || (entity1.id == targetID.id)) &&
|
||||||
|
@ -281,19 +331,16 @@ function keyPressEvent(event) {
|
||||||
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
|
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
|
||||||
Script.setTimeout(shootTarget, time);
|
Script.setTimeout(shootTarget, time);
|
||||||
} else if ((event.text == ".") || (event.text == "SPACE")) {
|
} else if ((event.text == ".") || (event.text == "SPACE")) {
|
||||||
shootFromMouse();
|
shootFromMouse(false);
|
||||||
|
} else if (event.text == ",") {
|
||||||
|
shootFromMouse(true);
|
||||||
} else if (event.text == "r") {
|
} else if (event.text == "r") {
|
||||||
playLoadSound();
|
playLoadSound();
|
||||||
} else if (event.text == "g") {
|
|
||||||
makeGrid("Box", 0.0, 0.4, 3);
|
|
||||||
} else if (event.text == "f") {
|
|
||||||
makeGrid("Box", -9.8, 0.4, 5);
|
|
||||||
} else if (event.text == "s") {
|
} else if (event.text == "s") {
|
||||||
// Hit this key to dump a posture from hydra to log
|
// Hit this key to dump a posture from hydra to log
|
||||||
Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm"));
|
Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm"));
|
||||||
Quat.print("forearm = ", MyAvatar.getJointRotation("LeftForeArm"));
|
Quat.print("forearm = ", MyAvatar.getJointRotation("LeftForeArm"));
|
||||||
Quat.print("hand = ", MyAvatar.getJointRotation("LeftHand"));
|
Quat.print("hand = ", MyAvatar.getJointRotation("LeftHand"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,18 +386,7 @@ function update(deltaTime) {
|
||||||
if (targetID && !targetID.isKnownID) {
|
if (targetID && !targetID.isKnownID) {
|
||||||
targetID = Entities.identifyEntity(targetID);
|
targetID = Entities.identifyEntity(targetID);
|
||||||
}
|
}
|
||||||
// Check for mouseLook movement, update rotation
|
|
||||||
// rotate body yaw for yaw received from mouse
|
|
||||||
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } ));
|
|
||||||
//MyAvatar.orientation = newOrientation;
|
|
||||||
yawFromMouse = 0;
|
|
||||||
|
|
||||||
// apply pitch from mouse
|
|
||||||
var newPitch = MyAvatar.headPitch + pitchFromMouse;
|
|
||||||
//MyAvatar.headPitch = newPitch;
|
|
||||||
pitchFromMouse = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if (activeControllers == 0) {
|
if (activeControllers == 0) {
|
||||||
if (Controller.getNumberOfSpatialControls() > 0) {
|
if (Controller.getNumberOfSpatialControls() > 0) {
|
||||||
activeControllers = Controller.getNumberOfSpatialControls();
|
activeControllers = Controller.getNumberOfSpatialControls();
|
||||||
|
@ -424,19 +460,19 @@ function update(deltaTime) {
|
||||||
|
|
||||||
var velocity = Vec3.multiply(BULLET_VELOCITY, Vec3.normalize(palmToFingerTipVector));
|
var velocity = Vec3.multiply(BULLET_VELOCITY, Vec3.normalize(palmToFingerTipVector));
|
||||||
|
|
||||||
shootBullet(position, velocity);
|
shootBullet(position, velocity, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shootFromMouse() {
|
function shootFromMouse(grenade) {
|
||||||
var DISTANCE_FROM_CAMERA = 1.0;
|
var DISTANCE_FROM_CAMERA = 1.0;
|
||||||
var camera = Camera.getPosition();
|
var camera = Camera.getPosition();
|
||||||
var forwardVector = Quat.getFront(Camera.getOrientation());
|
var forwardVector = Quat.getFront(Camera.getOrientation());
|
||||||
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA));
|
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA));
|
||||||
var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY);
|
var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY);
|
||||||
shootBullet(newPosition, velocity);
|
shootBullet(newPosition, velocity, grenade);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
|
@ -444,21 +480,23 @@ function mouseReleaseEvent(event) {
|
||||||
isMouseDown = false;
|
isMouseDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
function mousePressEvent(event) {
|
||||||
if (isMouseDown) {
|
var clickedText = false;
|
||||||
var MOUSE_YAW_SCALE = -0.25;
|
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
|
||||||
var MOUSE_PITCH_SCALE = -12.5;
|
if (clickedOverlay == offButton) {
|
||||||
var FIXED_MOUSE_TIMESTEP = 0.016;
|
Script.stop();
|
||||||
yawFromMouse += ((event.x - lastX) * MOUSE_YAW_SCALE * FIXED_MOUSE_TIMESTEP);
|
} else if (clickedOverlay == platformButton) {
|
||||||
pitchFromMouse += ((event.y - lastY) * MOUSE_PITCH_SCALE * FIXED_MOUSE_TIMESTEP);
|
makePlatform(-9.8, 1.0, 5);
|
||||||
lastX = event.x;
|
} else if (clickedOverlay == gridButton) {
|
||||||
lastY = event.y;
|
makeGrid("Box", 1.0, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
Overlays.deleteOverlay(reticle);
|
Overlays.deleteOverlay(reticle);
|
||||||
Overlays.deleteOverlay(offButton);
|
Overlays.deleteOverlay(offButton);
|
||||||
|
Overlays.deleteOverlay(platformButton);
|
||||||
|
Overlays.deleteOverlay(gridButton);
|
||||||
Overlays.deleteOverlay(pointer[0]);
|
Overlays.deleteOverlay(pointer[0]);
|
||||||
Overlays.deleteOverlay(pointer[1]);
|
Overlays.deleteOverlay(pointer[1]);
|
||||||
Overlays.deleteOverlay(text);
|
Overlays.deleteOverlay(text);
|
||||||
|
@ -470,7 +508,7 @@ Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
Controller.keyPressEvent.connect(keyPressEvent);
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue