I'm making a lock-picking game and I want to generate some sounds for it. I've tried but I don't understand how sound works so it's been trial and error.
Also the first time I play the sound it sounds different to subsequent plays: why is this?
set display mode 1024, 768, 32
hide mouse
randomize timer()
sync rate 60
gosub make_sound
col_pin = rgb(160, 140, 50)
col_rider = rgb(80, 40, 40)
apin = 0 :`active pin
tpin = 4 :`total pins
dim pin(tpin, 1) :`(x, 0) = length of pin x, (x, 1) current vertical position of pin x.
dim rider(tpin, 1) :`(x, 0) state of rider x 0=free 1=set, (x, 1) current vertical position of rider on pin x.
for x = 0 to tpin
pin(x, 0) = rnd(16) + 64
rider(x, 1) = pin(x, 0) + 2
next x
rem Make sure we have the shortest and longest possible pins for testing.
pin(0, 0) = 64
pin(1, 0) = 80
sync on
my = mousey()
do
ink rgb(40,60,75),0
endx = 190+(tpin+2)*20
box 180, 246, endx, 364
gosub mouse_controls
rem Manage pins
pins_picked=-1
for i = 0 to tpin
rem success?
inc pins_picked, rider(i,0)
if pins_picked = tpin
text 200, 350, "Lock Picked!"
endif
rem pin drop
y = pin(i, 1)
if y > 0 and (i ! apin)
dec y, 8
if (y < 0) then y = 0
pin(i, 1) = y
endif
rem rider drop if not on ledge
piny = pin(i, 1) + pin(i, 0)
if rider(i, 0) = 0 or piny>=100
rider(i, 0)=0
y = rider(i, 1)
if y > piny then dec y, 6
if y < piny then y = piny
rider(i, 1) = y
if y = 100
rider(i, 0)=1
text 200, 80, "*CLICK!*"
if sound playing(1)=0 then play sound 1 else stop sound 1
endif
endif
rem draw pins
ix1 = 200 + (i * 20)
ix2 = ix1 + 10
iy2 = 300 - pin(i, 1)
iy1 = iy2 - pin(i, 0)
ink col_pin, 0
box ix1, iy1, ix2, iy2
rem riders
ink col_rider, 0
iy2 = 300-rider(i, 1)
iy1 = iy2-64
box ix1, iy1, ix2, iy2
rem springs
inc ix1, 2
dec ix2, 2
q = 211 - rider(i, 1)-64
for s = 0 to 19
u# = q/20.0
y1 = 90 + u#*s
y2 = y1 + u#
if s&1
ink rgb(190,190,190),0
line ix1, y1, ix2, y2
else
ink rgb(160,160,160),0
line ix2, y1, ix1, y2
endif
next s
next i
gosub hud
sync:cls
loop
`=== Subroutines ==========================================
hud:
endx = 190+(tpin+2)*20
rem lock cover
if shiftkey()=0
ink rgb(90,110,125),0
box 180, 90, endx, 246
endif
rem line markers
ink -2, 0
line 180, 364, endx, 364 :`bottom of plug
line 180, 300, endx, 300 :`gutter
line 180, 246, endx, 246 :`plug
line 180, 200, endx, 200 :`sheer line
line 180, 90, endx, 90 :`housing
pntx = 205+(apin*20)
line pntx-7, 320, pntx, 314
line pntx+7, 320, pntx, 314
rem display
print "Pin: "; apin
print "L: "; pin(apin, 0); " Pos: "; pin(apin, 1)
return
`//
mouse_controls:
rem Switching Pins
omw = mw :`old mousewheel position
mw = mousemovez() :`mousewheel position
if (mw ! omw)
newpin = (mw > omw) - (omw > mw)
inc apin, newpin
if (apin > tpin) then apin = tpin
if (apin < 0) then apin = 0
pin(apin, 1) = pin(apin-newpin, 1)
endif
rem Pin Manipulation
omy = my
my = mousey()
if (my ! omy)
y = pin(apin, 1)
inc y, (my - omy)
if y < 0 then y = 0
if y > 50 then y = 50
pin(apin, 1) = y
endif
return
`//
make_sound:
samps = 200
bitq = 8
f = 900
make memblock 1, 12 + samps * bitq
write memblock dword 1, 0, bitq :`bits per sample
write memblock dword 1, 4, 900 :`frequency
write memblock dword 1, 8, f :`number of samples
for s = 0 to samps-1 step 2
write memblock byte 1, 12+s*bitq, (s*rnd(128))/(samps+.)
next s
for p = 1 to tpin+1
make sound from memblock p,1
next p
play sound 1
return
`//
I want clicking sounds for when the pins pop into place, and another sound for when the lock is successfully picked.
Shh... you're pretty.