Burst Effect?

BlitzMax Forums/BlitzMax Beginners Area/Burst Effect?

I have some balls which are arranged in a circle. I draw them to screen with the following:

	Function drawBalls()
	
		For Local b:ball = EachIn ballList
			SetRotation(BallRotationAngle)
			DrawImage balls,b.xpos+BallXoffSet+Sin(b.angle)*distanceFromCenter,..
			b.ypos+BallYoffSet+Cos(b.angle)*distanceFromCenter,b.ballFrame
			SetRotation(0)
		Next
		
	End Function


I want there to be a sort of burst effect which causes the balls to burst outward then return inward to the center of the screen.

I thought I could use something like this.

Function testBurst()
	
	Local temp:Float = distancefromcenter
	BurstDistance = 100
	
	If KeyDown(KEY_SPACE)		
	distanceFromCenter = Sin(temp)*temp	
	temp:+1
	If temp <=0 Then temp = 360
	EndIf
	
	DrawText "temp = " +temp,0,0
End Function


It craetes a nice smooth movement inwards but then it stops and hangs.

Any ideas on how I can proceed?

To go out and then back in you shouldn't need the full range of angles for Sin, you'd only need up to 180.

Hi, I've modified the code accordingley but it still has no effect.

Anymore tips would be appreciated.

Thanks :)

You seem to have Cos() and Sin() mixed up in your code example.

Use Cos() to calulate X position and Sin() to calculate Y position. In your code you are doing the opposite(Sin() for X and Cos() for y).

@Aten

I whipped together some thing really quick to set you on the right track:

Strict
Const SCR_W:Int = 640
Const SCR_H:Int = 480

Graphics SCR_W,SCR_H,0

Type BallCollection

	Field Balls:TList = CreateList()	'List to hold all balls in collection
	Field globalAngle:Float			'The angle of the entire collection
	Field globalDistance:Int		'The distance from the centerpoint for all balls 
	Field maxDistance:Int			'The max distace the balls can be from the centerpoint
	Field minDistance:Int			'The min distace the balls can be from the centerpoint	
	Field speedDistance			'The speed of the distance change
	Field speedAngle			'The speed by wich the collections angle changes
	Field x:Int				'X component of th centerpoint of  the collection
	Field Y:Int				'Y component of th centerpoint of  the collection
	
	Function CreateBallCollection:BallCollection(posX:Int, posY:Int,gA:Float=0,gD:Int=0,maxD:Int=100, minD:Int=0,speedD:Int=1,speedA:Int=1)
		
		'Lots of options in the constructor
		'but only X,Y is required
	
		'Create a new object
		Local bc:BallCollection = New BallCollection
		
		'Set object properties
		bc.x = posX
		bc.Y = posY
		bc.globalAngle = gA
		bc.globalDistance = gD
		bc.maxDistance= maxD
		bc.minDistance= minD
		bc.speedDistance =speedD
		bc.speedAngle =speedA

		'Return object
		Return bc
				
	End Function
	

	Method AddBall:TLink(b:Ball)
	
		'Add the ball to the collection and return it's handle
		Return Balls.AddLast(b)
		
	End Method
	
	Method Update()
		
		'Check if the distance property is in range
		If globalDistance > maxDistance or globalDistance < minDistance 
		
			'If out of range invert the speed 
			speedDistance = -speedDistance
		
		End If
		
		'Adjust angle and distance using speed properties
		globalDistance:+speedDistance
		globalAngle:+speedAngle
		
		'Loop through collection of balls and call each balls update() method
		For Local b:Ball=EachIn Balls
		
			'Pass self to the ball object
			b.Update(Self)
			
		Next
		
	End Method
	
	
	Method Draw()
		
		'Loop through collection of balls and call each balls draw() method
		For Local b:Ball=EachIn Balls

			'Pass self to the ball object
			b.Draw(Self)

		Next
			
	End Method

End Type

Type Ball

	Field localAngle:Float		'The offset angle of the ball (in realtion to the collection)
	Field localDistance:Int		'The offset distance of the ball (in realtion to the collection)
	Field x:Int			'The relative X position of the ball on the screen 
	Field Y:Int			'The relative Y position of the ball on the screen
	Field Size:Int			'The size of the ball
	
	Function CreateBall:Ball(ballsize:Int, localAng:Float=0, localDist:Int=0)
	
		'Create a new ball object
		Local b:Ball = New Ball
		
		'Set object properties
		b.Size = ballsize
		b.localAngle = localAng
		b.localDistance = localDist
		
		'Return object
		Return b
	
	End Function

	Method Update(bc:BallCollection)
	
		'Calculate the relative position using both the collections and the balls angle/distance
		x = Cos(bc.globalAngle+localAngle)*(bc.globalDistance+localDistance)
		Y = Sin(bc.globalAngle+localAngle)*(bc.globalDistance+localDistance)
		
	
	End Method
	
	Method Draw(bc:BallCollection)

		'Draw the ball at the absolute position (collection centerpoit + balls relative position)
		DrawOval bc.x + x,bc.Y+Y,Size,Size
			
	End Method
	
End Type

'Create an ball collection object
Global myBalls:BallCollection = BallCollection.CreateBallCollection(SCR_W/2,SCR_H/2)

'Populate the ball collection with balls at approriate angles
For Local i:Int=0 To 359 Step 20
	
	myBalls.AddBall(Ball.CreateBall(10,i,20))
	
Next	


Repeat

	Cls

	'Update ball collection (and implicitly all the balls in it)
	myBalls.Update()
	
	'Draw ball collection (and implicitly all the balls in it)
	myBalls.Draw()	

	Flip
	FlushMem


Until KeyHit(KEY_ESCAPE)


Hope it helps! ( Slow day at work today ;-) )

Sigh, This is a much better approach then what I've been using. I'm Still an OOP noob. This is the exact effect i wanted. Thanks. :)

Don't sigh :) Just keep at it!

OOP takes some getting used to. Remember that OOP is more of a mindset than actual coding techniques. It's all about the process. Try thinking in objects and their properties first instead of thinking of how to implement the details. If you have you have a good set of objects, your implementation of the details will easily (well, sort of...) fall into place.