mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 09:23:49 +02:00
Add foul and strike audio to baseball game
This commit is contained in:
parent
b75ad7f254
commit
b46d42889d
1 changed files with 71 additions and 33 deletions
|
@ -14,6 +14,15 @@ var AUDIO = {
|
||||||
SoundCache.getSound("atp:e68661374e2145c480809c26134782aad11e0de456c7802170c7abccc4028873.wav", false),
|
SoundCache.getSound("atp:e68661374e2145c480809c26134782aad11e0de456c7802170c7abccc4028873.wav", false),
|
||||||
SoundCache.getSound("atp:787e3c9af17dd3929527787176ede83d6806260e63ddd5a4cef48cd22e32c6f7.wav", false),
|
SoundCache.getSound("atp:787e3c9af17dd3929527787176ede83d6806260e63ddd5a4cef48cd22e32c6f7.wav", false),
|
||||||
SoundCache.getSound("atp:fc65383431a6238c7a4749f0f6f061f75a604ed5e17d775ab1b2955609e67ebb.wav", false),
|
SoundCache.getSound("atp:fc65383431a6238c7a4749f0f6f061f75a604ed5e17d775ab1b2955609e67ebb.wav", false),
|
||||||
|
],
|
||||||
|
strike: [
|
||||||
|
SoundCache.getSound("atp:2a258076a85fffde4ba04b5ddc1de9034c7ae7d2af8c5d93d4fed0bcdef3472a.wav", false),
|
||||||
|
SoundCache.getSound("atp:518363524af3ed9b9ae4ca2ceee61f01aecd37e266a51c5a5f5487efe2520fd5.wav", false),
|
||||||
|
SoundCache.getSound("atp:d51d38b089574acbdfdf53ef733bfb3ab41d848fb8c0b6659c7790a785240009.wav", false),
|
||||||
|
],
|
||||||
|
foul: [
|
||||||
|
SoundCache.getSound("atp:316fa18ff9eef457f670452b449a8dc5a41ccabd4e948781c50aaafaae63b0ab.wav", false),
|
||||||
|
SoundCache.getSound("atp:c84d88352d38437edd7414b26dc74e567618712caeb59fec70822398b0c5a279.wav", false),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +114,12 @@ var BASEBALL_PROPERTIES = {
|
||||||
z: 0
|
z: 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var BASEBALL_STATE = {
|
||||||
|
PITCHING: 0,
|
||||||
|
HIT: 1,
|
||||||
|
STRIKE: 2,
|
||||||
|
FOUL: 3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var pitchingMachineID = Entities.addEntity(PITCHING_MACHINE_PROPERTIES);
|
var pitchingMachineID = Entities.addEntity(PITCHING_MACHINE_PROPERTIES);
|
||||||
|
@ -159,10 +174,10 @@ function orientationOf(vector) {
|
||||||
var Y_AXIS = { x: 0, y: 1, z: 0 };
|
var Y_AXIS = { x: 0, y: 1, z: 0 };
|
||||||
var X_AXIS = { x: 1, y: 0, z: 0 };
|
var X_AXIS = { x: 1, y: 0, z: 0 };
|
||||||
var direction = Vec3.normalize(vector);
|
var direction = Vec3.normalize(vector);
|
||||||
|
|
||||||
var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
||||||
var pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
var pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
||||||
|
|
||||||
return Quat.multiply(yaw, pitch);
|
return Quat.multiply(yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +191,7 @@ function cleanupTrail() {
|
||||||
if (trail) {
|
if (trail) {
|
||||||
Script.clearInterval(this.trailInterval);
|
Script.clearInterval(this.trailInterval);
|
||||||
trailInterval = null;
|
trailInterval = null;
|
||||||
|
|
||||||
trail.destroy();
|
trail.destroy();
|
||||||
trail = null;
|
trail = null;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +199,7 @@ function cleanupTrail() {
|
||||||
|
|
||||||
function setupTrail(entityID, position) {
|
function setupTrail(entityID, position) {
|
||||||
cleanupTrail();
|
cleanupTrail();
|
||||||
|
|
||||||
var lastPosition = position;
|
var lastPosition = position;
|
||||||
trail = new InfiniteLine(position, { red: 255, green: 128, blue: 89 });
|
trail = new InfiniteLine(position, { red: 255, green: 128, blue: 89 });
|
||||||
trailInterval = Script.setInterval(function() {
|
trailInterval = Script.setInterval(function() {
|
||||||
|
@ -199,7 +214,9 @@ function setupTrail(entityID, position) {
|
||||||
function Baseball(position, velocity, ballScale) {
|
function Baseball(position, velocity, ballScale) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Setup entity properties
|
this.state = BASEBALL_STATE.PITCHING;
|
||||||
|
|
||||||
|
// Setup entity properties
|
||||||
var properties = shallowCopy(BASEBALL_PROPERTIES);
|
var properties = shallowCopy(BASEBALL_PROPERTIES);
|
||||||
properties.position = position;
|
properties.position = position;
|
||||||
properties.velocity = velocity;
|
properties.velocity = velocity;
|
||||||
|
@ -211,7 +228,7 @@ function Baseball(position, velocity, ballScale) {
|
||||||
z: 0.0,
|
z: 0.0,
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Create entity
|
// Create entity
|
||||||
this.entityID = Entities.addEntity(properties);
|
this.entityID = Entities.addEntity(properties);
|
||||||
|
|
||||||
|
@ -242,7 +259,7 @@ Baseball.prototype = {
|
||||||
var myProperties = Entities.getEntityProperties(this.entityID, ['position', 'velocity']);
|
var myProperties = Entities.getEntityProperties(this.entityID, ['position', 'velocity']);
|
||||||
var myPosition = myProperties.position;
|
var myPosition = myProperties.position;
|
||||||
var myVelocity = myProperties.velocity;
|
var myVelocity = myProperties.velocity;
|
||||||
|
|
||||||
// Activate gravity
|
// Activate gravity
|
||||||
Entities.editEntity(self.entityID, {
|
Entities.editEntity(self.entityID, {
|
||||||
gravity: { x: 0, y: -9.8, z: 0 }
|
gravity: { x: 0, y: -9.8, z: 0 }
|
||||||
|
@ -251,35 +268,57 @@ Baseball.prototype = {
|
||||||
var name = Entities.getEntityProperties(entityB, ["name"]).name;
|
var name = Entities.getEntityProperties(entityB, ["name"]).name;
|
||||||
print("Hit: " + name);
|
print("Hit: " + name);
|
||||||
if (name == "Bat") {
|
if (name == "Bat") {
|
||||||
print("HIT");
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
|
print("HIT");
|
||||||
// Update ball velocity
|
|
||||||
Entities.editEntity(self.entityID, {
|
// Update ball velocity
|
||||||
velocity: Vec3.multiply(2, myVelocity),
|
Entities.editEntity(self.entityID, {
|
||||||
});
|
velocity: Vec3.multiply(2, myVelocity),
|
||||||
|
|
||||||
// Setup line update interval
|
|
||||||
setupTrail(self.entityID, myPosition);
|
|
||||||
|
|
||||||
// Setup bat hit sound
|
|
||||||
playRandomSound(AUDIO.batHit, {
|
|
||||||
position: myPosition,
|
|
||||||
volume: 2.0
|
|
||||||
});
|
|
||||||
|
|
||||||
// Setup crowd reaction sound
|
|
||||||
var speed = Vec3.length(myVelocity);
|
|
||||||
Script.setTimeout(function() {
|
|
||||||
playRandomSound((speed < 5.0) ? AUDIO.crowdBoos : AUDIO.crowdCheers, {
|
|
||||||
position: { x: 0 ,y: 0, z: 0 },
|
|
||||||
volume: 1.0
|
|
||||||
});
|
});
|
||||||
}, 500);
|
|
||||||
|
// Setup line update interval
|
||||||
|
setupTrail(self.entityID, myPosition);
|
||||||
|
|
||||||
|
// Setup bat hit sound
|
||||||
|
playRandomSound(AUDIO.batHit, {
|
||||||
|
position: myPosition,
|
||||||
|
volume: 2.0
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup crowd reaction sound
|
||||||
|
var speed = Vec3.length(myVelocity);
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
playRandomSound((speed < 5.0) ? AUDIO.crowdBoos : AUDIO.crowdCheers, {
|
||||||
|
position: { x: 0 ,y: 0, z: 0 },
|
||||||
|
volume: 1.0
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
var yaw = Math.atan2(myVelocity.x, myVelocity.z) * 180 / Math.PI;
|
||||||
|
var foul = yaw > -135 && yaw < 135;
|
||||||
|
if (foul) {
|
||||||
|
print("FOUL ", yaw)
|
||||||
|
this.state = BASEBALL_STATE.FOUL;
|
||||||
|
playRandomSound(AUDIO.foul, {
|
||||||
|
position: myPosition,
|
||||||
|
volume: 2.0
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
print("HIT ", yaw);
|
||||||
|
this.state = BASEBALL_STATE.HIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (name == "stadium") {
|
} else if (name == "stadium") {
|
||||||
print("PARTICLES");
|
print("PARTICLES");
|
||||||
entityCollisionWithGround(entityB, this.entityID, collision);
|
entityCollisionWithGround(entityB, this.entityID, collision);
|
||||||
} else if (name == "backstop") {
|
} else if (name == "backstop") {
|
||||||
print("STRIKE");
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
|
this.state = BASEBALL_STATE.STRIKE;
|
||||||
|
print("STRIKE");
|
||||||
|
playRandomSound(AUDIO.strike, {
|
||||||
|
position: myPosition,
|
||||||
|
volume: 2.0
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +356,7 @@ function entityCollisionWithGround(ground, entity, collision) {
|
||||||
var speed = map(dVelocityMagnitude, 0.05, 3, 0.02, 0.09);
|
var speed = map(dVelocityMagnitude, 0.05, 3, 0.02, 0.09);
|
||||||
var displayTime = 400;
|
var displayTime = 400;
|
||||||
var orientationChange = orientationOf(collision.velocityChange);
|
var orientationChange = orientationOf(collision.velocityChange);
|
||||||
|
|
||||||
var dustEffect = Entities.addEntity({
|
var dustEffect = Entities.addEntity({
|
||||||
type: "ParticleEffect",
|
type: "ParticleEffect",
|
||||||
name: "Dust-Puff",
|
name: "Dust-Puff",
|
||||||
|
@ -349,4 +388,3 @@ Script.scriptEnding.connect(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
Script.setInterval(pitchBall, PITCH_RATE);
|
Script.setInterval(pitchBall, PITCH_RATE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue