I manage with your program to have good effect with set sound pan and set sound volume.
I have one problem.
As I told , I have one noisy object and when I go around to this object , I want to hear the sound left or right or slower when I get far away from my noisy object.
In my game for example I have one door for example as a noisy object.
When I am opening my door , I hear the creak sound of the door , in fact my door is a slide door and when it opens you hear some wooden sound.
Well , I have the data of my door in one type.
For example the code describe my data type to keep my data of my door.
type my_doors
delay as integer `delay time of frames
updater as integer `update timer
state as integer `1=closed 2=opened 3=opening 4=closing 5=locked 6=jammed
x as integer
y as integer
frame as integer `door sprite
mech as integer `mechanism 1=horizontal 2=vertical
graphic as string `the graphic of the door
sound_volume as integer
sound_pan as integer
endtype
dim doors(10,100) as my_doors
The code above is exactly the code I use to store my data of my door.
In fact my array doors keeps all data of my door mechanism.
(levels,number_of_doors) this means in my 10 levels of my game , each level have 100 doors.
And there is another one data type which I store the data of my players as (party)
type my_party
x as integer `my party x on the map
y as integer `my party y on the map
direction as integer `my party direction 1:North 2:south 3:East 4:West
level as integer `my party is on the level
ENDTYPE
global party as my_party
The above code is exactly the data type code to keep my party position , direction and level of my party.
So , now I am comparing the party position with my door position to see if I am near or far from my doors or if there is door at the left or at the right accourding to my direction.
I use this kind of code:
for all_doors=1 to 100
if party.direction=1 `NORTH
if party.y-1=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=90
GOTO AFTER_DOOR_SOUNDS
endif
if party.y-2=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=80
GOTO AFTER_DOOR_SOUNDS
endif
if party.y-3=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=70
GOTO AFTER_DOOR_SOUNDS
endif
if party.y-4=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=60
GOTO AFTER_DOOR_SOUNDS
endif
if party.y-4>doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=0
GOTO AFTER_DOOR_SOUNDS
endif
if party.y+1=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=90
GOTO AFTER_DOOR_SOUNDS
endif
if party.y+2=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=80
GOTO AFTER_DOOR_SOUNDS
endif
if party.y+3=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=70
GOTO AFTER_DOOR_SOUNDS
endif
if party.y+4=doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=60
GOTO AFTER_DOOR_SOUNDS
endif
if party.y+4<doors(party.level,all_doors).y
doors(party.level,all_doors).sound_volume=0
GOTO AFTER_DOOR_SOUNDS
endif
`DOOR_PAN_SOUNDS:
if party.x-1=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=90
doors(party.level,all_doors).sound_pan=-1000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x-2=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=80
doors(party.level,all_doors).sound_pan=-2000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x-3=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=70
doors(party.level,all_doors).sound_pan=-3000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x-4=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=60
doors(party.level,all_doors).sound_pan=-4000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x-4>doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=0
GOTO AFTER_DOOR_SOUNDS
endif
if party.x+1=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=90
doors(party.level,all_doors).sound_pan=1000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x+2=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=80
doors(party.level,all_doors).sound_pan=2000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x+3=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=70
doors(party.level,all_doors).sound_pan=3000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x+4=doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=60
doors(party.level,all_doors).sound_pan=4000
GOTO AFTER_DOOR_SOUNDS
endif
if party.x+4<doors(party.level,all_doors).x
doors(party.level,all_doors).sound_volume=0
GOTO AFTER_DOOR_SOUNDS
endif
endif
next
AFTER_DOOR_SOUNDS:
The above code scans all of my doors in my currect level I am , from my party.level variable.
So we assume , I have 100 unique doors in my map.
If I want to initialize one of my doors I write this code:
doors(1,1).x=5
doors(1,1).y=4
doors(1,1).graphic="01"
doors(1,1).frame=0
doors(1,1).mech=1
doors(1,1).state=1
The above code tells my game , I have one door , in level 1 and the door is number 1 from whole 100 doors I have.
The position of specific door is 5,4 squares on the map.
The graphic variable is the graphic of the door (wooden , metal , glass etc)
The frame variable is the frame sprite animation of my door.
The mech variable is the mechanism of the door , you will get confused but you don't care about this
and the State variable means , what is the state of the specific door , is locked , is unlocked , is closed , is opened , is opening (in middle of opening animation) or is closing (in middle of closing animation).
From all of these we care only about x and y variables because I use these variables only to compare my party position , with my door position.
If my party.x+1 square there is one door.
Pseudo code
if party.x+1=doors(1,1).x then (play some sound with pan right)
if party.x-1=doors(1,1).x then (play some sound with pan left)
if party.y-1=doors(1,1).y then (play some sound with volume 90) the door is far in front of you
if party.y-2=doors(1,1).y then (play some sound with volume 70) the door is even more far in front of you
if party.y+1=doors(1,1).y then (play some sound with volume 90) the door is far behind you
if party.y+2=doors(1,1).y then (play some sound with volume 70) the door is even more far behind you
blah
blah
(The front and behind is calculated accourding to party direction , north , south , east , west.
I don't want to confuse you very much , but the problem is.
When I am in front of my door , I mean the party.x=door(1,1).x
but I am far the y variable of my party if bigger or smaller , I hear my door far (set sound valume slower)
When I am at the left of my door or the right of my door I hear the sound from my left or my right.
How to describe my problem.
When I am horizontal or vertical from my door , I hear my sound well
but when I am diagonal from my door , the all variables get confused.
For example , doors().x=5 and doors.y=5 but the party.x=4 and party.y=6
I have one picture to illustrate the idea.
When I am in front of my door , or the door is behind me or at the left or right , I hear the sound and pan effect well.
But when I am diagonal , or my door is behind me , but not opposite behind me but behind and at left or behind and right or in front left or in front and right , or far front and far right then the sound confusing , in fact I hear the sound pan correct but not the sound volume correct. (Now you got confused very much)
I thing I described the problem well.
If you didn't understand , I will post my game to see...
If few words , even I am horizontal , vertical or diagonal , 1 or more squares far , to hear my door far or at the left or right correct.
Like I am in some sound range from my door...
Did you get the point?