Hi guys
I've updated the code from the other thread (
http://forum.thegamecreators.com/?m=forum_view&t=102880&b=4)
sync on
sync rate 60
box 0,0,31,31,rgb(255,128,128),rgb(128,255,128),rgb(128,128,255),rgb(255,128,128)
for y=0 to 20
ink 0,0
line 0,y,14,0
line 16,0,31,y
next y
get image 1,0,0,31,31,0
playerx# = 600
playery# = 350
speed = 4
angle = 0
lclick = 0
sprite 1,playerx#,playery#,1
rotate sprite 1, angle
offset sprite 1,15,15
do
cls
print "Player X ";playerx#
print "Player Y ";playery#
print "Distance X ";distx#
print "Distance Y ";disty#
print "Distance R ";dist
sprite 1,playerx#,playery#,1
rotate sprite 1, angle
` Detect mouse press
if lclick < 2 and mouseclick() = 1
inc lclick
else
if mouseclick() = 0 then lclick = 0
endif
if lclick = 1
` Calculate distance vectors from mouse
distx# = mousex() - playerx#
disty# = mousey() - playery#
angle = atanfull(distx#,0 - disty#)
` Check if further than allowed by speed
if abs(distx#) > speed or abs(disty#) > speed
` Store max distance and scale distance vectors down
if abs(distx#) > abs(disty#)
dist = abs(distx#)
disty# = disty# / abs(distx#)
distx# = distx# / abs(distx#)
else
dist = abs(disty#)
distx# = distx# / abs(disty#)
disty# = disty# / abs(disty#)
endif
endif
endif
` Move player and decrease max distance
if dist > 0
playerx# = playerx# + speed * distx#
playery# = playery# + speed * disty#
dec dist, speed
else
playerx# = int(playerx#)
playery# = int(playery#)
endif
sync
loop
end
Hope this helps