Burst Effect?

BlitzMax Forums/BlitzMax Beginners Area/Burst Effect?

@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 ;-) )