Hi guys, I've been working on some more functions, I don't know if you're interested:
First I'd like to offer a corrected version of my file browser - there was a minor flaw, with the scrollbar not quite reaching the bottom when the final files were displayed. I've also changed it so that the scrollbar vanishes when there are more than 600 files or folders in the directory (too many more and the scrollbar would be less than a pixel high!). In the unlikely event that you ever see this happen, you'll need to use the Up/Down buttons to scroll through the files.
After the problems that arose when posting the file browser code as a code snippet, I've attached the dba file to this post.
Now, some more functions:
3d Object Library
Particles
I can't take all the credit for these functions, most of the code for the create- and update- routines was taken from the DBC Particle Bombs example program. However, the introduction of arrays to allow for more than one set of particles was my own work, along with the controls over the visual properties and auto-respawn.
The following functions require these commands to be placed at the top of your code:
rem Specify how many sets of particles you will be creating (min. one):
Particles =
Dim ParticleConstants#(Particles, 13)
Dim ParticleVariables#(Particles, 1000, 3)
Create_Particles
Function Create_Particles(Particle, FirstObj, NumParticles, Texture, xSize#, ySize#, x#, y#, z#, xVel#, yVel#, zVel#, MinLife, MaxLife)
If NumParticles>1000 then NumParticles = 1000
If NumParticles<0 then NumParticles = 1
rem Create plains
For T=0 to NumParticles - 1
Make Object Plain FirstObj + T, xSize#, ySize#
Texture Object FirstObj + T, Texture
Set Object FirstObj+T, 1, 0, 1
Next T
rem Adjust particle velocities
xVel# = 100.00 * xVel#
yVel# = 100.00 * yVel#
zVel# = 100.00 * zVel#
rem Store Particle data
ParticleConstants#(Particle, 0) = FirstObj
ParticleConstants#(Particle, 1) = NumParticles
ParticleConstants#(Particle, 2) = x#
ParticleConstants#(Particle, 3) = y#
ParticleConstants#(Particle, 4) = z#
ParticleConstants#(Particle, 5) = MinLife
ParticleConstants#(Particle, 6) = MaxLife
ParticleConstants#(Particle, 7) = xVel#
ParticleConstants#(Particle, 8) = yVel#
ParticleConstants#(Particle, 9) = zVel#
ParticleConstants#(Particle, 10) = 0.01 : rem Gravity
ParticleConstants#(Particle, 11) = 0.95 : rem Friction
ParticleConstants#(Particle, 12) = 0 : rem Bounce rate
ParticleConstants#(Particle, 13) = 0 : rem Particle Floor
`ParticleVariables#(Particle, P, 0) = xVel#
`ParticleVariables#(Particle, P, 1) = yVel#
`ParticleVariables#(Particle, P, 2) = zVel#
`ParticleVariables#(Particle, P, 3) = Particle Life
rem Set variables
For T = 1 to ParticleConstants#(ParticleNum, 1)
rem Set Life
ParticleVariables#(Particle, T, 3) = ParticleConstants#(Particle, 5) + rnd(ParticleConstants#(Particle, 6) - ParticleConstants#(Particle, 5))
rem Set velocity
ParticleVariables#(Particle, T, 0) = (rnd(xVel#)-(xVel#/2))/100
ParticleVariables#(Particle, T, 1) = (rnd(yVel#)-(yVel#/2))/100
ParticleVariables#(Particle, T, 2) = (rnd(zVel#)-(zVel#/2))/100
Position Object ParticleConstants#(Particle, 0) + (T-1), ParticleConstants#(Particle, 2), ParticleConstants#(Particle, 3), ParticleConstants#(Particle, 4)
Next T
EndFunction
Particle: A 'slot' number, pointing to a location in the required arrays so that the particle data can be accessed.
FirstObj: The first object used by the particle set
NumParticles: This is the number of particles that will be created - e.g. Say FirstObj = 5 and Numparticles = 20, Objects will be created from slots 5 up to (but not including) 25.
Texture: The image number used to texture each particle.
xSize#, ySize#: The width and height of each particle (all particles are plains).
x#, y#, z#: The location in 3d space of the particle source.
xVel#, yVel#, zVel#: 2* the max distance each particle will move along the coordinate axes. Please try and ensure that each value is >=0.01, or the particles may all clump together as the Rnd command fails. The function doesn't automatically adjust these values, as it can be an interesting effect.
MinLife, MaxLife: Every particle will survive for at least
MinLife screen refreshes, but may survive for as long as
MaxLife refreshes.
Update_Particles
Function Update_Particles(Particle, AutoRespawn, Rotation)
For T = 1 to Int(ParticleConstants#(Particle, 1))
Obj = ParticleConstants#(Particle, 0) + (T-1)
If ParticleVariables#(Particle, T, 3)>1
rem Decrease life
ParticleVariables#(Particle, T, 3) = ParticleVariables#(Particle, T, 3) - 1
rem calculate friction
ParticleVariables#(Particle, T, 0) = ParticleVariables#(Particle, T, 0) * ParticleConstants#(Particle, 11)
ParticleVariables#(Particle, T, 1) = ParticleVariables#(Particle, T, 1) * ParticleConstants#(Particle, 11)
ParticleVariables#(Particle, T, 2) = ParticleVariables#(Particle, T, 2) * ParticleConstants#(Particle, 11)
rem and gravity...
ParticleVariables#(Particle, T, 1) = ParticleVariables#(Particle, T, 1) - ParticleConstants#(Particle, 10)
rem Main velocity
xPos# = Object Position X(Obj) + ParticleVariables#(Particle, T, 0)
yPos# = Object Position Y(Obj) + ParticleVariables#(Particle, T, 1)
zPos# = Object Position Z(Obj) + ParticleVariables#(Particle, T, 2)
rem Bouncing when it hits the floor
If ParticleConstants#(Particle, 13) >0
If yPos#<=0 then ParticleVariables#(Particle, T, 1) = ParticleVariables#(Particle, T, 1) * ParticleConstants#(Particle, 12)
endif
rem Rotate Particles
If Rotation = 1
Rotate Object Obj, wrapvalue(object angle x(Obj)+rnd(50)), wrapvalue(object angle y(Obj)+rnd(50)), wrapvalue(object angle Z(Obj)+rnd(50))
endif
If Rotation = 2
Set Object To Camera Orientation Obj
endif
Position object Obj, xPos#, yPos#, zPos#
else
rem Particle life = 1, handle respawn
If AutoRespawn = 1
rem New particle velocity
ParticleVariables#(Particle, T, 0) = (rnd(ParticleConstants#(Particle, 7)) - (ParticleConstants#(Particle, 7)/2))/100
ParticleVariables#(Particle, T, 1) = (rnd(ParticleConstants#(Particle, 8)) - (ParticleConstants#(Particle, 8)/2))/100
ParticleVariables#(Particle, T, 2) = (rnd(ParticleConstants#(Particle, 9)) - (ParticleConstants#(Particle, 9)/2))/100
rem Calculate new life
ParticleVariables#(Particle, T, 3) = ParticleConstants#(Particle, 5) + rnd(ParticleConstants#(Particle, 6) - ParticleConstants#(Particle, 5))
rem Reposition
xPos# = ParticleConstants#(Particle, 2) + ParticleVariables#(Particle, T, 0)
yPos# = ParticleConstants#(Particle, 3) + ParticleVariables#(Particle, T, 1)
zPos# = ParticleConstants#(Particle, 4) + ParticleVariables#(Particle, T, 2)
Position object Obj, xPos#, yPos#, zPos#
else
ParticleVariables#(Particle, T, 3) = 0
Hide Object Obj
endif
endif
Next T
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
AutoRespawn: Set to 0 to create a 'firework' effect where the particles slowly die away. Set to 1 to have a new particle created as soon as an old particle dies. The new particle's movement is governed according to the original parameters (life, velocity, gravity, friction, bounce height) but is located at the center of the particles.
Rotation: Set to 0 to have all the particles pointing to 0,0,0 (as they were created). Set to 1 to have all particles spinning randomly on all three axes. Set to 2 to have the particles always pointing towards the camera.
Important - this function must be called once every program loop, otherwise the particles will freeze (which could be a bad thing if you're modelling a flame

)
Position_Particle_Source
Function Position_Particle_Source(Particle, x#, y#, z#)
ParticleConstants#(Particle, 2) = x#
ParticleConstants#(Particle, 3) = y#
ParticleConstants#(Particle, 4) = z#
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
x#,y#,z#: Change these before updating the particles. All new particles (i.e those that get respawned) will start from this position in 3d space. Existing particles are unaffected, so it allows you to create a vapour trail of exhaust fumes.
Set_Particle_Velocity
Function Set_Particle_Velocity(xVel#, yVel#, zVel#)
ParticleConstants#(Particle, 7) = xVel#
ParticleConstants#(Particle, 8) = yVel#
ParticleConstants#(Particle, 9) = zVel#
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
xVel#,yVel#,zVel#: Change these before updating the particles. All new particles (i.e those that get respawned) will start with this new velocity, but existing particles are unaffected.
Set_Particle_Life
Function Set_Particle_Life(MinLife, MaxLife)
ParticleConstants#(Particle, 5) = MinLife
ParticleConstants#(Particle, 6) = MaxLife
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
MinLife, MaxLife: This allows you to specify new lifetimes for particles as they get respawned.
Set_Particle_Friction
Function Set_Particle_Friction(Particle, Friction#)
ParticleConstants#(Particle, 11) = Friction#
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
Friction#: This allows you to apply a constant force on the particles. Specify a value <1 to slow down the particles, or a value >1 to speed up the particles. A value of 1 will do nothing. By default the friction is set to 0.95 (so every screen update, the particles velocity falls to 95% of the value at the previous loop. If it lives long enough it will eventually grind to a halt)
Set_Particle_Gravity
Function Set_Particle_Gravity(Particle, Gravity#)
ParticleConstants#(Particle, 10) = Gravity#
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
Friction#: This allows you to apply a constant downward force on the particles. Specify a negative value to produce antigravity and make the particle float up. By default, gravity is 0.01.
Enable/Disable Particle Floor
Function Enable_Particle_Floor(Particle)
ParticleConstants#(Particle, 13) = 1
EndFunction
Function Disable_Particle_Floor(Particle)
ParticleConstants#(Particle, 13) = 0
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
Use these two commands to create a floor at height y = 0. If the particles strike this floor, they will bounce. By default, the floor is disabled.
Set_Particle_Bounce
Function Set_Particle_Bounce(Particle, BounceHeight#)
ParticleConstants#(Particle, 12) = BounceHeight#
ParticleConstants#(Particle, 13) = 1
EndFunction
Particle: As before, a 'slot' number pointing to a location in the required arrays.
BounceHeight#: This allows you control over how high the particle rebounds. By default the value is zero (and the particle is prevented from bouncing).
So, there you have it. I hope these functions are of some use. (Actually, if you are interested, it wouldn't be too hard to knock up a few extra functions giving you the ability to hide/show particles, set visual effects, etc. Unless I'm misunderstanding how DBPro and GDk work, I think it might be possible to have a particle system with far more commands than they've got!)
"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."