Howdy. The first thing I would have changed, was how the code was laid out.
Rem Project: Vampire Ball
Rem Created: Sunday, February 19, 2012
Rem ***** Main Source File *****
`define the sprite structure
type SPRITET
x as integer
y as integer
speedx as integer
speedy as integer
alpha as integer
endtype
global NUM as integer = 5
dim ball(NUM) as SPRITET
sync on
sync rate 40
hide mouse
randomize timer()
`load the background image
load image "woodgrain.bmp", 100
`load the animated ball
set image colorkey 255, 0, 255
create animated sprite 1, "ball.bmp", 8, 8, 1
`clone the additional sprites
for n = 2 to NUM
clone sprite 1, n
next n
`randomize the balls
for n = 1 to NUM
ball(n).x = rnd(screen width() - sprite width(1))
ball(n).y = rnd(screen height() - sprite height(1))
ball(n).speedx = rnd(4) + 2
ball(n).speedy = rnd(4) + 2
ball(n).alpha = 255
next n
`slow down the first sprite
ball(1).speedx = 2
ball(1).speedy = 2
`main loop
repeat
`draw the background
paste image 100, 0, 0
`move the balls
for n = 1 to NUM
`update the ball's X position
w = screen width() - sprite width(1)
ball(n).x = ball(n).x + ball(n).speedx
`This is where it checks if the ball has gone too far on x.
if ball(n).x > w or ball(n).x < 0
`This is where it changes Direction on x.
ball(n).speedx = ball(n).speedx * -1
ball(n).x = ball(n).x + ball(n).speedx
endif
`update the ball's Y position
h = screen height() - sprite height(1)
ball(n).y = ball(n).y + ball(n).speedy
`This is where it checks if the ball has gone too far on y.
if ball(n).y > h or ball(n).y < 0
`This is where it changes Direction on y.
ball(n).speedy = ball(n).speedy * -1
ball(n).y = ball(n).y + ball(n).speedy
endif
next n
`perform collision testing with sprite 1
for n = 2 to NUM
if sprite collision(1, n)
`suck the life out of this poor ball!
ball(n).x = ball(n).x + ball(n).speedx * 2
ball(n).y = ball(n).y + ball(n).speedy * 2
ball(n).alpha = ball(n).alpha - 1
if ball(n).alpha < 0 then ball(n).alpha = 0
set sprite alpha n, ball(n).alpha
`give more life to the vampire ball
ball(1).alpha = ball(1).alpha - 1
if ball(1).alpha > 0 then ball(1).alpha = 0
set sprite diffuse 1, ball(n).alpha, ball(n).alpha, 255
`***************************
`I would do the change here.
`***************************
endif
next n
`draw the balls
for n = 1 to NUM
play sprite n, 1, 64, 30
sprite n, ball(n).x, ball(n).y, n
next n
sync
until (escapekey() = 1)
Don't know if that's how you received it, or if that's how it was copied and pasted, but it is always easier to look and see what the code is doing when it is spaced a little cleaner.
Since you already have code to check whether a ball has gone off the screen in any given direction and change accordingly, you already have the code needed to perform the operation of changing the Vampire's direction when it is hit.
You also have the code needed to check the collision on whether the Vampire is hitting another ball. I added some comments to show where this is all taking place.
This should get you on the right track. Good luck and comment back if you don't get it!
Edit: I don't have the media used ("woodgrain.bmp" and "ball.bmp") So I didn't run the program. But using the logic above, you should be able to get it.