Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Particle code
#1
Not really sure where to put this, it's not a tutorial, a feature or the likes.
Please move it if you think there's a better place for it.

I take no credit for it, but I also can't give any credit to someone for it. Sad

I found it on a source code site whilst looking for ideas and code examples for my engine, but I don't remember where.
It's short, sweet, doesn't use DX or BitBlt and could be modified numerous ways, hope you like.

Simply open a new VB6 project and paste the code below into the forms code box.

[code]Private Type Ptype
X As Long
Y As Long
Xv As Long
Yv As Long
LifeSpan As Long
End Type

Const Max = 250
Dim Particle(Max) As Ptype
Dim bRunning As Boolean
Dim Xstart As Long, Ystart As Long
Dim i As Long

Private Sub Form_Load()
Show

Xstart = ScaleWidth \ 2
Ystart = ScaleHeight \ 2

For i = 0 To Max
Particle(i).LifeSpan = Rnd * 500

Particle(i).X = Xstart
Particle(i).Y = Ystart

Particle(i).Yv = Rnd * -15
Particle(i).Xv = Rnd * -10 + 5
Next i

bRunning = True
ParticleLoop
End Sub

Private Sub ParticleLoop()
Do While bRunning
DoEvents

For i = 0 To Max
PSet (Particle(i).X, Particle(i).Y), BackColor

Particle(i).X = Particle(i).X + Particle(i).Xv
Particle(i).Y = Particle(i).Y + Particle(i).Yv

Particle(i).Yv = Particle(i).Yv + 0.96

If Particle(i).Y >= ScaleHeight Then
Particle(i).Yv = -(Particle(i).Yv * 0.46)
Particle(i).Y = ScaleHeight
End If

Particle(i).LifeSpan = Particle(i).LifeSpan - 1

If Particle(i).LifeSpan
Reply
#2
I have never before heared of:
Code:
PSet

Although I dont think it would work on the picscreen. And its pretty slow too.
Reply
#3
Doesn't it set pixel color?

I remember reading about it when I was looking up VBCrLf
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)