Have you checked carefully that each "bounce" actually gives you a direction inside the area? It isn't obvious to me that "-165" always works - although it might.
Incidentally, does your code bounce three times when two of the collisions are true - and, if so, is that intentional?
Edit I think it would help if you posted code that fails - not much point posting the working parts of your code. The following simple demo works fine for me (OK, to be honest, I got bored waiting for it to fail):
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
box 0, 0, 100, desktop height(), rgb(255,0,0), rgb(0,255,0), rgb(0,0,255), rgb(255,255,255)
get image 1, 0, 0, 100, desktop height(), 1
sprite 1, 0, 0, 1
sprite 2, desktop width()-100, 0, 1
box 0, 0, desktop width()-200, 100, rgb(0,255,0), rgb(255,0,0),rgb(255,255,255),rgb(0,0,255)
get image 2, 0, 0, desktop width()-200, 100, 1
sprite 3, 100, 0, 2
sprite 4, 100, desktop height()-100, 2
box 0, 0, 16, 16, rgb(255,255,0), rgb(255,255,0), rgb(255,255,0), rgb(255,255,0)
get image 3, 0, 0, 16, 16, 1
sprite 5, desktop width()/2, desktop height()/2, 3
rotate sprite 5, rnd(360)
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
repeat
move sprite 5, 5
if sprite collision(1, 5) or sprite collision(2, 5) or sprite collision(3, 5) or sprite collision(4, 5)
Bounce(5)
endif
sync
until spacekey()
end
function Bounce(spritenum)
move sprite spritenum, -40
rotate sprite spritenum,sprite angle(spritenum)-165
endfunction