You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.
Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.
sync rate 60
#constant STEPSIZE 10
` Draw a shape and capture it to an image
get image 1,0,0,16,16
` Set up the sprite to display it
offset sprite 1,7,7
` If the mouse button has been pressed ...
if mouseclick() > 0
` Get the target coordinates
` Work out how many steps are required to get there
Steps=sqrt( ((TargetX-sprite x(1))^2) + ((TargetY-sprite y(1))^2) )/STEPSIZE
` Work out the angle to get there
Angle=atanfull( TargetX-sprite x(1), sprite y(1)-TargetY )
` Rotate the sprite to that angle
rotate sprite 1, Angle
` If the bullet still has steps to make ...
if Steps > 0
if Steps > 1
` and it's not the final step, just move it
move sprite 1, 10
` otherwise position the sprite at the final coordinates
sprite 1, TargetX, TargetY, sprite image(1)
` reduce the number of steps still to take
text 0,0,"Sprite X : " + str$( sprite x(1) ) + ", Sprite Y : " + str$( sprite y(1) )
Login to post a reply