News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

2d move on distance

Started by ATLUS, September 13, 2009, 05:14:20 AM

Previous topic - Next topic

ATLUS

PlayBASIC Code: [Select]
; PROJECT : Project2
; AUTHOR : ATLUS
; CREATED : 13.09.2009
; EDITED : 13.09.2009
; ---------------------------------------------------------------------

setfps 59
sx#=400
sy#=300


spd#=2
do
cls rgb(0,0,0)
ex#=mousex()
ey#=mousey()
dist#=getdistance2d(sx#,sy#,ex#,ey#)
time#=dist#/spd#
stepx#=(sx#-ex#)/time#
stepy#=(sy#-ey#)/time#

if curposx#<ex#
sx#=sx#-stepx#
else
sx#=sx#+stepx#
endif

if curposy#<ey#
sy#=sy#-stepy#
else
sy#=sy#+stepy#
endif



circle sx#,sy#,20,1
text 10,10,sx#
text 10,20,sy#
sync
loop





PlayBASIC Code: [Select]
; PROJECT : Project2
; AUTHOR : ATLUS
; CREATED : 13.09.2009
; EDITED : 13.09.2009
; ---------------------------------------------------------------------

setfps 59
sx#=400
sy#=300


spd#=2
do

cls rgb(0,0,0)
color=rgb(255,255,255)
ex#=mousex()
ey#=mousey()
dist#=getdistance2d(sx#,sy#,ex#,ey#)
time#=dist#/spd#
stepx#=(sx#-ex#)/time#
stepy#=(sy#-ey#)/time#

if curposx#<ex#
sx#=sx#-stepx#
else
sx#=sx#+stepx#
endif

if curposy#<ey#
sy#=sy#-stepy#
else
sy#=sy#+stepy#
endif

if dist#<=300 then color=rgb(0,255,0)
if dist#<=200 then color=rgb(0,0,255)
if dist#<=100 then color=rgb(255,0,0)
if dist#<=10 then color=rgb(255,255,0)


circleC sx#,sy#,20,1,color
text 10,10,sx#
text 10,20,sy#
text 10,30,"distance "+str$(dist#)
sync
loop






kevin

#1
 Here's another way of doing the same thing.

PlayBASIC Code: [Select]
setfps 59
sx#=400
sy#=300


spd#=2


do

cls rgb(0,0,0)

color=rgb(255,255,255)

ex#=mousex()
ey#=mousey()
dist#=getdistance2d(sx#,sy#,ex#,ey#)

if Dist#>=1

normalx#=(ex#-sx#)/dist#
normaly#=(ey#-sy#)/dist#

sx#=sx#+(NormalX#*spd#)
sy#=sy#+(NormalY#*spd#)

endif


if dist#<=10
color=rgb(255,255,0)
elseif dist#<=100
color=rgb(255,0,0)
elseif dist#<=200
color=rgb(0,0,255)
elseif dist#<=300
color=rgb(0,255,0)
endif


circleC sx#,sy#,20,1,color
text 10,10,sx#
text 10,20,sy#
text 10,30,"distance "+str$(dist#)

sync
loop





ATLUS

#2
not bad ;) now circle move only distance<350
PlayBASIC Code: [Select]
setfps 59
sx#=400
sy#=300


spd#=2


do

cls rgb(0,0,0)

color=rgb(255,255,255)

ex#=mousex()
ey#=mousey()
dist#=getdistance2d(sx#,sy#,ex#,ey#)

if Dist#<=350

normalx#=(ex#-sx#)/dist#
normaly#=(ey#-sy#)/dist#

sx#=sx#+(NormalX#*spd#)
sy#=sy#+(NormalY#*spd#)

endif


if dist#<=10
color=rgb(255,255,0)
elseif dist#<=100
color=rgb(255,0,0)
elseif dist#<=200
color=rgb(0,0,255)
elseif dist#<=300
color=rgb(0,255,0)
endif


circleC sx#,sy#,20,1,color
text 10,10,sx#
text 10,20,sy#
text 10,30,"distance "+str$(dist#)

sync
loop







kevin

#3
 Here's another variation, this one is using 'Polar coordinates'

PlayBASIC Code: [Select]
setfps 59
sx#=400
sy#=300


spd#=2


do

cls rgb(0,0,0)


ex#=mousex()
ey#=mousey()
dist#=getdistance2d(sx#,sy#,ex#,ey#)


if Dist#<=350
if Dist#>=1
Angle#=GetAngle2d(sx#,sy#,ex#,ey#)
sx#=sx#+CosRadius(Angle#,spd#)
sy#=sy#+SinRadius(Angle#,spd#)

endif
endif


if dist#<=10
color=rgb(255,255,0)
elseif dist#<=100
color=rgb(255,0,0)
elseif dist#<=200
color=rgb(0,0,255)
elseif dist#<=300
color=rgb(0,255,0)
else
color=rgb(255,255,255)
endif


circleC sx#,sy#,20,1,color
text 10,10,sx#
text 10,20,sy#
text 10,30,"distance "+str$(dist#)

sync
loop





ATLUS

sin and cos very powerfull function  ;)