Ok, I wrote a really simple particle engine, and I ran into a little snag with making the particles rebound. I tried using the generic bouncing code from the code archives, but I'm not quite sure how to blend it with my code...Here's the particle code I wrote. If anyone can tell me how to add rebound to it I'll be very grateful.
(Note sure how to do a code box...sorry)
Type Particle
Field Entity,XSpeed#,YSpeed#,ZSpeed#,Alpha#,Lifespan
End Type
Function CreateParticle.Particle(X,Y,Z,Sprite,Lifespan=100,R=255,G=255,B=255)
p.Particle = New Particle
p\Entity = Sprite
p\XSpeed = 0
p\YSpeed = 2
p\ZSpeed = 1
p\Alpha = 1
p\Lifespan = Lifespan
EntityType(p\Entity,CT_PARTICLE)
EntityColor(p\Entity,R,G,B)
PositionEntity(p\Entity,X,Y,Z)
RotateEntity(p\Entity,0,Rand(360),0)
Return p
End Function
Function UpdateParticles()
For p.Particle = Each Particle
MoveEntity(p\Entity,p\XSpeed,p\YSpeed,p\ZSpeed)
p\YSpeed = p\YSpeed - 0.1
If p\Lifespan > 0 Then
p\Lifespan = p\Lifespan - 1
Else
If p\Alpha > 0 Then
p\Alpha = p\Alpha - 0.1
EntityAlpha(p\Entity,p\Alpha)
Else
FreeEntity p\Entity
Delete p
EndIf
EndIf
Next
End Function
(Note sure how to do a code box...sorry)
Type Particle
Field Entity,XSpeed#,YSpeed#,ZSpeed#,Alpha#,Lifespan
End Type
Function CreateParticle.Particle(X,Y,Z,Sprite,Lifespan=100,R=255,G=255,B=255)
p.Particle = New Particle
p\Entity = Sprite
p\XSpeed = 0
p\YSpeed = 2
p\ZSpeed = 1
p\Alpha = 1
p\Lifespan = Lifespan
EntityType(p\Entity,CT_PARTICLE)
EntityColor(p\Entity,R,G,B)
PositionEntity(p\Entity,X,Y,Z)
RotateEntity(p\Entity,0,Rand(360),0)
Return p
End Function
Function UpdateParticles()
For p.Particle = Each Particle
MoveEntity(p\Entity,p\XSpeed,p\YSpeed,p\ZSpeed)
p\YSpeed = p\YSpeed - 0.1
If p\Lifespan > 0 Then
p\Lifespan = p\Lifespan - 1
Else
If p\Alpha > 0 Then
p\Alpha = p\Alpha - 0.1
EntityAlpha(p\Entity,p\Alpha)
Else
FreeEntity p\Entity
Delete p
EndIf
EndIf
Next
End Function