Orbit

BlitzPlus Forums/BlitzPlus Programming/Orbit

Sure! This has 50 objects. Use mouse to affect them (space changes the polarity):
Include "gravity.bb"

AppTitle "Gravity"
Graphics 600, 600, 32, 2
SetFont LoadFont("Arial", 20, True)
SeedRnd MilliSecs()

; create balls
ball_count% = 50
Dim ball%(ball_count%)

gravity% = 2
r% = 200

; Create objects
For i% = 1 To ball_count%
	ball%(i%) = CreatePhysicsObject(Rand(10, GraphicsWidth() - 10), Rand(10, GraphicsHeight() - 10), 0, 2, Rnd(.95, .99))
Next

While Not KeyHit(1)
	Cls
	
	mx% = MouseX()
	my% = MouseY()
	
	; Draw gravity
	Color 100, 0, 0
	Oval mx% - r%, my% - r%, r% * 2, r% * 2, False
	
	; Loop all balls
	For i% = 1 To ball_count%
		; Affect balls
		SetPhysicsObjectZ#(ball%(i%), 0)
		AffectPhysicsObject(ball%(i%), mx%, my%, 0, gravity%, r%)
		
		; Don't let the ball to leave the screen
		If PhysicsObjectX#(ball%(i%)) < 0 Or PhysicsObjectX#(ball%(i%)) > GraphicsWidth() Then
			SetPhysicsObjectX#(ball%(i%), PhysicsObjectX#(ball%(i%)) - PhysicsObjectXSpeed#(ball%(i%)))
			SetPhysicsObjectXSpeed#(ball%(i%), -PhysicsObjectXSpeed#(ball%(i%)))
		EndIf
		If PhysicsObjectY#(ball%(i%)) < 0 Or PhysicsObjectY#(ball%(i%)) > GraphicsHeight() Then
			SetPhysicsObjectY#(ball%(i%), PhysicsObjectY#(ball%(i%)) - PhysicsObjectYSpeed#(ball%(i%)))
			SetPhysicsObjectYSpeed#(ball%(i%), -PhysicsObjectYSpeed#(ball%(i%)))
		EndIf
		
		; Draw ball
		Color 200, 200, 200
		Oval PhysicsObjectX#(ball%(i%)) - 5, PhysicsObjectY#(ball%(i%)) - 5, 10, 10, True
	Next	
	
	; Reverse gravity
	If KeyHit(57) Then gravity% = -gravity%
	
	Flip
Wend
End


After each affect of an object you should Zero the z position of it!