If you have an image pasted at x,y and it has a width of width and height of height, then you need to do this check to see if the mouse is clicking on it:
if mouseclick()=1 and mousex()>x and mousey()>y and mousex()<x+width and mousey()<y+height
gosub a_sub_routine
endif
Here's a piece of code that makes two images link to a certain sub routine. It is fully commented, so read through it and try to get it to work with your images - right now the snippet generates two images with a few lines of code.
rem basic starting stuff:
sync on
sync rate 0
cls
rem make a random image that has a size of 100 by 100
lock pixels
for x=1 to 100
for y=1 to 100
ink rgb(0,255,rnd(255)),0
dot x,y
next y
next x
unlock pixels
sync
get image 1,1,1,100,100
rem make a random image that has a size of 100 by 100
lock pixels
for x=1 to 100
for y=1 to 100
ink rgb(rnd(255),0,255),0
dot x,y
next y
next x
unlock pixels
sync
get image 2,1,1,100,100
rem now we have image 1 and image 2. You can replace the previous code with code that loads images from files.
rem main loop:
do
cls
rem paste both images on the screen.
rem The first image is pasted at 0,0. Since it has a width of 100 and height of 100,
rem the right edge of the image is at 100 and the bottom edge of the image is at 100.
paste image 1,0,0
rem the second image is pasted at 200, 50. Since it also has a width of 100 and height of 100,
rem the right edge of the image is at 200+100, or 300, and the bottom edge of the image is at 50+100, or 150.
paste image 2,200,50
if mouseclick()=1
rem if mousex()>left and mousey()>top and mousex()<right and mousey()<bottom
if mousex()>0 and mousey()>0 and mousex()<100 and mousey()<100
rem gosub the sub routine
gosub certain_sub_routine
endif
rem if mousex()>left and mousey()>top and mousex()<right and mousey()<bottom
if mousex()>200 and mousey()>50 and mousex()<300 and mousey()<150
rem gosub the sub routine
gosub certain_sub_routine
endif
endif
rem refresh the screen
sync
loop
rem end of main loop
rem sub routines:
certain_sub_routine:
center text screen width()/2,screen height()/2,"You are in a certain sub routine"
sync
wait 1000
center text screen width()/2,screen height()/2+20,"Returning to main loop now"
sync
wait 1000
return