I saw some code
here.
That thread is too old to post on now.
I was reminded of Ultima 6 and 7, where the mouse cursor would rotate around the character, changing directions depending on how it was oriented on screen.
I hacked this out of it.
But I wonder if there is a better way? I do not understand the math in the function (math is not my thing) and atan produces 3 sets of 0 values, two of which have to be taken care of by extra code (otherwise the sprite mouse cursor shows "north" even though it's west or east of the character).
I've already done the best I know to do.
Graphics are attached.
sync on
set text opaque
backdrop on
color backdrop rgb(0,0,0)
hide mouse
load image "n.png",1
load image "e.png",2
load image "s.png",3
load image "w.png",4
load image "ne.png",5
load image "se.png",6
load image "nw.png",7
load image "sw.png",8
load image "hero.png",9
sprite 1,0,0,1
sprite 2,0,0,2
sprite 3,0,0,3
sprite 4,0,0,4
sprite 5,0,0,5
sprite 6,0,0,6
sprite 7,0,0,7
sprite 8,0,0,8
sprite 9,0,0,9
characterx#=screen width()/2
charactery#=screen height()/2
specialcase=0
hide all sprites
do
set cursor 0,0
paste sprite 9, characterx#, charactery#
a#=Find_Angle(characterx#,charactery#,mousex(),mousey())
print a#
if a#=0 and charactery# = mousey() and mousex() < characterx#
specialcase = 1 ` needed because of the way the atan function works
print "West. Special case value: " + str$(specialcase)
paste sprite 4,mousex(),mousey()
endif
if a#=0 and charactery# = mousey() and mousex() > characterx#
specialcase = 1
print "East. Special case value: " + str$(specialcase)
paste sprite 2,mousex(),mousey()
endif
if specialcase <> 1 and a#<25 or a#>=335
paste sprite 1,mousex(),mousey()
print "North "
endif
if a#=>25 and a#<65
paste sprite 7,mousex(),mousey()
print "North West "
endif
if a#=>65 and a#<115
paste sprite 4,mousex(),mousey()
print "West "
endif
if a#=>115 and a#<155
paste sprite 8,mousex(),mousey()
print "South West "
endif
if a#=>155 and a#<205
paste sprite 3,mousex(),mousey()
print "South "
endif
if a#=>205 and a#<245
paste sprite 6,mousex(),mousey()
print "South East "
endif
if a#=>245 and a#<295
paste sprite 2,mousex(),mousey()
print "East "
endif
if a#=>295 and a#<335
paste sprite 5,mousex(),mousey()
print "North East "
endif
specialcase=0
sync
loop
function Find_Angle(px1#,py1#,px2#,py2#)
angle#=atan((px2#-px1#)/(py2#-py1#))+((py2#-py1#)>0)*180+((py2#-py1#)<0)*((px2#-px1#)>0)*360
endfunction angle#