mirror of
https://github.com/overte-org/overte.git
synced 2025-07-25 20:10:00 +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);
|
||||||
|
@ -199,6 +214,8 @@ function setupTrail(entityID, position) {
|
||||||
function Baseball(position, velocity, ballScale) {
|
function Baseball(position, velocity, ballScale) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
this.state = BASEBALL_STATE.PITCHING;
|
||||||
|
|
||||||
// Setup entity properties
|
// Setup entity properties
|
||||||
var properties = shallowCopy(BASEBALL_PROPERTIES);
|
var properties = shallowCopy(BASEBALL_PROPERTIES);
|
||||||
properties.position = position;
|
properties.position = position;
|
||||||
|
@ -251,6 +268,7 @@ 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") {
|
||||||
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
print("HIT");
|
print("HIT");
|
||||||
|
|
||||||
// Update ball velocity
|
// Update ball velocity
|
||||||
|
@ -275,11 +293,32 @@ Baseball.prototype = {
|
||||||
volume: 1.0
|
volume: 1.0
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 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") {
|
||||||
|
if (this.state == BASEBALL_STATE.PITCHING) {
|
||||||
|
this.state = BASEBALL_STATE.STRIKE;
|
||||||
print("STRIKE");
|
print("STRIKE");
|
||||||
|
playRandomSound(AUDIO.strike, {
|
||||||
|
position: myPosition,
|
||||||
|
volume: 2.0
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,4 +388,3 @@ Script.scriptEnding.connect(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
Script.setInterval(pitchBall, PITCH_RATE);
|
Script.setInterval(pitchBall, PITCH_RATE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue