| Mirage Source http://www.miragesource.net/forums/ |
|
| Basic Particle code http://www.miragesource.net/forums/viewtopic.php?f=210&t=2572 |
Page 1 of 1 |
| Author: | Ambientiger [ Wed Aug 29, 2007 11:37 pm ] |
| Post subject: | Basic Particle code |
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. 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 <= 0 Then Particle(i).LifeSpan = Rnd * 500 Particle(i).X = Xstart Particle(i).Y = Ystart Particle(i).Yv = Rnd * -15 Particle(i).Xv = Rnd * -10 + 5 End If PSet (Particle(i).X, Particle(i).Y), RGB(0, 0, 0) Next i Refresh Loop End Sub Private Sub Form_Unload(Cancel As Integer) bRunning = False End End Sub |
|
| Author: | William [ Wed Aug 29, 2007 11:47 pm ] |
| Post subject: | Re: Basic Particle code |
I have never before heared of: Code: PSet Although I dont think it would work on the picscreen. And its pretty slow too. |
|
| Author: | Rezeyu [ Wed Aug 29, 2007 11:49 pm ] |
| Post subject: | Re: Basic Particle code |
Doesn't it set pixel color? I remember reading about it when I was looking up VBCrLf |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|