Revert "A new try at sound panning with walking."
This reverts commit 58ab5aa854
.
This commit is contained in:
parent
58ab5aa854
commit
0ef11785ec
55
__init__.py
55
__init__.py
@ -173,42 +173,47 @@ def cut_scene(sounds, soundName):
|
|||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
pygame.event.pump()
|
pygame.event.pump()
|
||||||
|
|
||||||
def obj_play(sounds, sound_name, player_pos, obj_pos):
|
def obj_play(sounds, soundName, playerPos, objPos):
|
||||||
distance = player_pos - obj_pos
|
distance = playerPos - objPos
|
||||||
if abs(distance) > 9:
|
if distance > 9 or distance < -9:
|
||||||
# The item is out of range, so play it at 0
|
# The item is out of range, so play it at 0
|
||||||
left = 0
|
left = 0
|
||||||
right = 0
|
right = 0
|
||||||
|
elif distance == 0:
|
||||||
|
left = 0.9
|
||||||
|
right = 0.9
|
||||||
else:
|
else:
|
||||||
# Calculate the panning based on the distance
|
angle = math.radians(distance * 5)
|
||||||
left = max(0, 1 - (distance / 9))
|
left = math.sqrt(2)/2.0 * (math.cos(angle) + math.sin(angle))
|
||||||
right = max(0, 1 + (distance / 9))
|
right = math.sqrt(2)/2.0 * (math.cos(angle) - math.sin(angle))
|
||||||
left = min(1, left)
|
if left < 0: left *= -1
|
||||||
right = min(1, right)
|
if right < 0: right *= -1
|
||||||
# Play the sound on a new channel
|
# x is the channel for the sound
|
||||||
channel = sounds[sound_name].play(-1)
|
x = sounds[soundName].play(-1)
|
||||||
# Apply the position information to the channel
|
# Apply the position information to the channel
|
||||||
channel.set_volume(left, right)
|
x.set_volume(left, right)
|
||||||
# Return the channel so that it can be used in the update and stop functions.
|
# return the channel so that it can be used in the update and stop functions.
|
||||||
return channel
|
return x
|
||||||
|
|
||||||
def obj_update(channel, player_pos, obj_pos):
|
def obj_update(x, playerPos, objPos):
|
||||||
distance = player_pos - obj_pos
|
distance = playerPos - objPos
|
||||||
if abs(distance) > 9:
|
if distance > 9 or distance < -9:
|
||||||
left = 0
|
left = 0
|
||||||
right = 0
|
right = 0
|
||||||
|
elif distance == 0:
|
||||||
|
left = 0.9
|
||||||
|
right = 0.9
|
||||||
else:
|
else:
|
||||||
# Calculate the panning based on the distance
|
angle = math.radians(distance * 5)
|
||||||
left = max(0, 1 - (distance / 9))
|
left = math.sqrt(2)/2.0 * (math.cos(angle) + math.sin(angle))
|
||||||
right = max(0, 1 + (distance / 9))
|
right = math.sqrt(2)/2.0 * (math.cos(angle) - math.sin(angle))
|
||||||
left = min(1, left)
|
if left < 0: left *= -1
|
||||||
right = min(1, right)
|
if right < 0: right *= -1
|
||||||
# Apply the position information to the channel
|
# Apply the position information to the channel
|
||||||
channel.set_volume(left, right)
|
x.set_volume(left, right)
|
||||||
# Return the channel
|
# return the channel
|
||||||
return channel
|
return x
|
||||||
|
|
||||||
soundData
|
|
||||||
def obj_stop(x):
|
def obj_stop(x):
|
||||||
# Tries to stop a playing object channel
|
# Tries to stop a playing object channel
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user