View Full Version: source of gravity anywhere on screen

Blitz Basement > BB General Discussions > source of gravity anywhere on screen


Title: source of gravity anywhere on screen


kurtp2003 - January 19, 2006 11:35 PM (GMT)
Hi there, whoever is actually on this. Anyway, I want to knnow how you would make a source of gravity at any point on the screen. This is much more complicated than just having gravity pull you towards the edge of the screen, but obviosly still doable.

Here is the source code for a program demonstrating how I did it:

Const upkey=200,rightkey=205,downkey=208,leftkey=203,space=57,bkey=48,f10=68
Graphics 800,600
SetBuffer BackBuffer()
SeedRnd(MilliSecs())

Type particle
Field x#,y#
Field h#
Field xd#,yd#
Field s#,c#
Field xs#,ys#
Field angle#
End Type

Type gravity
Field x#,y#
End Type

g.gravity=New gravity
g\x=400
g\y=300

While Not KeyDown(1)

Cls

If MouseDown(1)
p.particle=New particle
p\x#=MouseX()
p\y#=MouseY()
p\angle#=Rand(0,359)
p\xs#=Sin(p\angle#)*3
p\ys#=Cos(p\angle#)*3
EndIf

For p.particle=Each particle
p\x#=p\x#+p\xs#
p\y#=p\y#+p\ys#
For g.gravity=Each gravity
p\xd#=g\x-p\x#
p\yd#=g\y-p\y#
Oval g\x-1,g\y-1,3,3,1
Next

p\h#=Sqr(Abs(p\xd#)^2+Abs(p\yd#)^2)

p\s#=p\xd#/p\h#
p\c#=p\yd#/p\h#

p\xs#=p\xs#+p\s#
p\ys#=p\ys#+p\c#


Color 255,255,255
Next

Text 10,10,"this works"
Oval MouseX()-1,MouseY()-1,3,3,1

For p.particle=Each particle
Oval p\x-1,p\y-1,2,2,0
Next

Flip

Wend

End






Hosted for free by InvisionFree