Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Particle System help


tslusny
 Share

Recommended Posts

I need help with **Particle system** that im planning to add to **Eclipse Advanced:** http://www.touchofdeathforums.com/smf2/index.php/topic,82336.0.html

This is how far i get it to work
[![](http://www.freemmorpgmaker.com/files/imagehost/pics/0ff375d7fef84bb2cee25d1a25f39ae5.PNG)](http://www.freemmorpgmaker.com/files/imagehost/#0ff375d7fef84bb2cee25d1a25f39ae5.PNG)

But it should look like this:
[![](http://www.freemmorpgmaker.com/files/imagehost/pics/a3af90cea2920f2a305d2b913cbaff28.png)](http://www.freemmorpgmaker.com/files/imagehost/#a3af90cea2920f2a305d2b913cbaff28.png)

I changed particle texture to just simple black box texture becouse of that original texture was too hard to see.
**This is source what i used (it is only particle system). vbGore used this source for their particle system.**
Link to download: http://www.mediafire.com/?ij67s37ql5ipgfc

Code what i implemented to eclipse (of course DX8):
Class Particle
```
Option Explicit

Private mvarsngX As Single
Private mvarsngY As Single
Private mvarsngSize As Single
Private mvarsngXSpeed As Single
Private mvarsngYSpeed As Single
Private mvarsngXAccel As Single
Private mvarsngYAccel As Single
Private mvarsngR As Single
Private mvarsngG As Single
Private mvarsngB As Single
Private mvarsngA As Single
Private mvarsngAlphaDecay As Single

Public Property Let sngAlphaDecay(ByVal vData As Single)
    mvarsngAlphaDecay = vData
End Property

Public Property Get sngAlphaDecay() As Single
    sngAlphaDecay = mvarsngAlphaDecay
End Property

Public Property Let sngA(ByVal vData As Single)
    mvarsngA = vData
End Property

Public Property Get sngA() As Single
    sngA = mvarsngA
End Property

Public Property Let sngB(ByVal vData As Single)
    mvarsngB = vData
End Property

Public Property Get sngB() As Single
    sngB = mvarsngB
End Property

Public Property Let sngG(ByVal vData As Single)
    mvarsngG = vData
End Property

Public Property Get sngG() As Single
    sngG = mvarsngG
End Property

Public Property Let sngR(ByVal vData As Single)
    mvarsngR = vData
End Property

Public Property Get sngR() As Single
    sngR = mvarsngR
End Property

Public Property Let sngYAccel(ByVal vData As Single)
    mvarsngYAccel = vData
End Property

Public Property Get sngYAccel() As Single
    sngYAccel = mvarsngYAccel
End Property

Public Property Let sngXAccel(ByVal vData As Single)
    mvarsngXAccel = vData
End Property

Public Property Get sngXAccel() As Single
    sngXAccel = mvarsngXAccel
End Property

Public Property Let sngYSpeed(ByVal vData As Single)
    mvarsngYSpeed = vData
End Property

Public Property Get sngYSpeed() As Single
    sngYSpeed = mvarsngYSpeed
End Property

Public Property Let sngXSpeed(ByVal vData As Single)
    mvarsngXSpeed = vData
End Property

Public Property Get sngXSpeed() As Single
    sngXSpeed = mvarsngXSpeed
End Property

Public Property Let sngSize(ByVal vData As Single)
    mvarsngSize = vData
End Property

Public Property Get sngSize() As Single
    sngSize = mvarsngSize
End Property

Public Property Let sngY(ByVal vData As Single)
    mvarsngY = vData
End Property

Public Property Get sngY() As Single
    sngY = mvarsngY
End Property

Public Property Let sngX(ByVal vData As Single)
    mvarsngX = vData
End Property

Public Property Get sngX() As Single
    sngX = mvarsngX
End Property

Public Sub ResetColor(sngRed As Single, sngGreen As Single, sngBlue As Single, sngAlpha As Single, sngDecay As Single)
    '//Reset color to the new values
    sngR = sngRed
    sngG = sngGreen
    sngB = sngBlue
    sngA = sngAlpha
    sngAlphaDecay = sngDecay
End Sub

Public Sub ResetIt(X As Single, Y As Single, XSpeed As Single, YSpeed As Single, XAcc As Single, YAcc As Single, sngResetSize As Single)
    sngX = X
    sngY = Y
    sngXSpeed = XSpeed
    sngYSpeed = YSpeed
    sngXAccel = XAcc
    sngYAccel = YAcc
    sngSize = sngResetSize
End Sub

Public Sub UpdateParticle(sngTime As Single)
    sngX = sngX + sngXSpeed * sngTime
    sngY = sngY + sngYSpeed * sngTime

    sngXSpeed = sngXSpeed + sngXAccel * sngTime
    sngYSpeed = sngYSpeed + sngYAccel * sngTime

    sngA = sngA - sngAlphaDecay * sngTime
End Sub

```
Class ColFireFX (this class is for drawing that fire)
```
Option Explicit

Private Particles() As Particle
Private vertsPoints() As TLVERTEX

Private mCol As Collection

Private sngX As Single, sngY As Single
Public ParticleCounts As Long

Private lngFloat0 As Long
Private lngFloat1 As Long
Private lngFloatSize As Long

Private lngPreviousFrame As Long

Public Sub Begin()
    '//We initialize our stuff here
    Dim I As Long

    lngFloat0 = FtoDW(0)
    lngFloat1 = FtoDW(1)
    lngFloatSize = FtoDW(25) '//Size of our flame particles..

    '//Redim our particles to the particlecount
    ReDim Particles(0 To ParticleCounts)

    '//Redim vertices to the particle count
    '//Point sprites, so 1 per particle
    ReDim vertsPoints(0 To ParticleCounts)

    '//Now generate all particles
    For I = 0 To ParticleCounts
        Set Particles(I) = New Particle
        vertsPoints(I).RHW = 1
        Call Reset(I)
    Next I

    '//Set initial time
    lngPreviousFrame = timeGetTime
End Sub

Public Sub Reset(I As Long)
    Dim X As Single, Y As Single

    X = sngX + (Rnd * 10)
    Y = sngY

    '//This is were we will reset individual particles.
    With Particles(I)
        Call .ResetIt(X, Y, -0.4 + (Rnd * 0.8), -0.5 - (Rnd * 0.4), 0, -(Rnd * 0.3), 2)
        Call .ResetColor(1, 0.5, 0.2, 0.6 + (0.2 * Rnd), 0.01 + Rnd * 0.05)
    End With
End Sub

Public Sub Update()
    Dim I As Long
    Dim sngElapsedTime As Single

    '//We calculate the time difference here
    sngElapsedTime = (timeGetTime - lngPreviousFrame) / 100
    lngPreviousFrame = timeGetTime

    For I = 0 To ParticleCounts
        With Particles(I)
            Call .UpdateParticle(sngElapsedTime)

            '//If the particle is invisible, reset it again.
            If .sngA <= 0 Then
                Call Reset(I)
            End If

            vertsPoints(I).Color = D3DColorMake(.sngR, .sngG, .sngB, .sngA)
            vertsPoints(I).X = .sngX
            vertsPoints(I).Y = .sngY

        End With
    Next I
End Sub
Public Sub Render()
    With Direct3D_Device

        '//Set our texture
        .SetTexture 0, gTexture(Tex_Particle.Texture).Texture
        '//And draw all our particles :D
        .DrawPrimitiveUP D3DPT_POINTLIST, ParticleCounts, vertsPoints(0), Len(vertsPoints(0))
    End With
End Sub

Public Sub ReLocate(sngNewX As Single, sngNewY As Single)
    sngX = sngNewX
    sngY = sngNewY
End Sub

```
I added this to Sub Render_Graphics into that direct3D scene:
```
myNewFire.Update
            myNewFire.Render
```
I added this to bottom of Sub GameInit
```
Set myNewFire = New colFireFX
    myNewFire.ParticleCounts = 150
    myNewFire.ReLocate 150, 200
    myNewFire.Begin
```
And i added to modGlobals:
```
Public myNewFire As colFireFX
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...