Plug and Play baby ;)
This ones for free.
You should use a better blending function than SIN because its a bit wimpy. ALso the timing for the explosion is dictated by the frame rate. This is realy bad and you should integrate it with your game timer. Changing from DrawOval to your frame based animation should be rather breezy. Other than that I hope you can put this code to good use, have fun.
This ones for free.
Strict Graphics 640, 480, 0 While Not KeyHit( KEY_ESCAPE ) Cls If MouseHit( 1 ) TExplosion.Create( MouseX(), MouseY(), 4+Rand( 48 ) ) EndIf GCCollect( ) TExplosion.UpdateAll( ) TExplosion.RenderAll( ) GCCollect( ) Flip Wend '/** ' * TYPE EXPLOSION ' */ Type TExplosion '/** ' * LOCAL EXPLOSION DATA ' */ Field Px:Float, Py:Float 'position Field Time:Int 'time exposition has existed for Field TimeToLive:Int 'life span of explosion Field Size:Float 'size of explosion (radius) '/** ' * LINKED EXPLOSION LIST ' */ Global FstExp:TExplosion 'first explosion in linked list Global LstExp:TExplosion 'last explosion '' Field NxtExp:TExplosion 'next explosion '' (relative to instance) Field PrvExp:TExplosion 'previous explosion '' (relative to instance) '/** ' * TEXPLOSION CONSTRUCTOR ' */ Method New( ) 'add to linked list If LstExp <> Null LstExp.NxtExp = Self self.PrvExp = LstExp LstExp = Self Else FstExp = Self LstExp = Self EndIf End Method '/** ' * CREATE A NEW EXPLOSION ' */ Function Create( aPx:Float, aPy:Float, aSize:Float, aTTL:Int=-1 ) 'create a new position Local TExp:TExplosion = New TExplosion 'store positions TExp.Px = aPx TExp.Py = aPy 'store size TExp.Size = aSize 'check time to live If aTTL > 0 TExp.TimeToLive = aTTL Else 'automaticly calculate explosion size 'replace to suit your vibes TExp.TimeToLive = aSize*20 EndIf End Function '/** ' * UPDATE ALL TEXPLOSIONS ' */ Function UpdateAll( ) 'start off with first in the list Local TExp:TExplosion = FstExp 'update all in turn While TExp <> Null 'update explosion time TExp.Time = TExp.Time+32 'time to live checks If TExp.Time > TExp.TimeToLive 'kill the explosion TExp.Kill( ) EndIf 'move to next explosion TExp = TExp.NxtExp Wend End Function '/** ' * RENDER ALL TEXPLOSIONS ' */ Function RenderAll( ) 'start of with first in the list Local TExp:TExplosion = FstExp 'render all in turn While TExp <> Null TExp.Render( ) 'move to next explosion TExp = TExp.NxtExp Wend End Function '/** ' * KILL THE HOST TEXPLOSION ' */ Method Kill( ) 'update previous explosion If self.PrvExp <> Null self.PrvExp.NxtExp = Self.NxtExp EndIf 'update next explosion If Self.NxtExp <> Null self.NxtExp.PrvExp = Self.PrvExp EndIf 'change linked list general If FstExp = Self Then FstExp = self.NxtExp If LstExp = Self Then LstExp = self.PrvExp End Method '/** ' * GET THE EXPLOSION SIZE ' */ Method GetSize:Float( ) 'explosion scale based on time Local scale:Float = (Float( Time )/TimeToLive)*90 scale = Sin( scale ) 'return the size Return size*scale End Method '/** ' * RENDER THE EXPLOSION ' */ Method Render( ) Local MySize:Float = GetSize( ) SetColor 255, 195, 85 SetBlend( ALPHABLEND ) SetAlpha 1-(MySize/Size) DrawOval Px-MySize-2, Py-MySize-2, MySize*2+4, MySize*2+4 End Method End Type
You should use a better blending function than SIN because its a bit wimpy. ALso the timing for the explosion is dictated by the frame rate. This is realy bad and you should integrate it with your game timer. Changing from DrawOval to your frame based animation should be rather breezy. Other than that I hope you can put this code to good use, have fun.