Table of content

Previous: 0. Introduction

# Lesson 1. Getting started: the basics of particle programming

# a. What are particles?

Let us start at the beginning: what are particles and what do we need them for? According to the manual, particles are a special kind of entities which is used for creating all sorts of cool visual effects such as explosions, light beams, etc. As such, they are similar to ordinary entities, but differ from them in several ways.

First, they can only be represented in levels by (preferably small) bitmaps, unlike entities which can be also take the 'physical' shape of models (.mdl files) or maps (.wmb files). Particles are then just little images moving about in levels.

Second, contrary to sprite entities, particles are always facing the camera: no facing and oriented flags, nor pan, tilt and roll variables are defined for particles.

Third, these little images are rendered in a somewhat less detailed fashion than real entities. I'm suspecting that the particle engine uses a 8-bit color display, or that it might even use the graphic card differently than for sprite entities, but I could be wrong. At any rate, just choose an arbitrary bitmap, place two instances of it in a level side-by-side, one as a particle and the other as a sprite entity, and you will probably have no trouble figuring out which is which.

The last big difference between particles and full-fledge entities is that there is no collision detection for particles. Particles are therefore not a good tool to mediate interactions between players or entities.

However, all these simplifications and limitations are largely compensated by the fact that they are rendered extremely quickly by the game engine, and that, contrary to ordinary entities, 3DGS allows up to 10 000 particles at the same time in a level! They are therefore ideal for all sorts of visual effects and 'eye candy'.

Just as particles have been streamlined for faster display, people at Conitec have also provided a simplified syntax to program them in a more efficient way. Indeed, although particles and entities share a lot of the same variables and flags ( alpha, transparent, red, green, blue, bright, etc. - see the manual for a list), there are differences between them.

First, as stated earlier, some entity flags and variables are not available for particles. Another example is the number of free skill variables: skill1 to skill100 for entities, but only skill_x to skill_z and skill_a to skill_d for particles.

Second, there are some very useful flags and variables which are special to particles. I only name a few here. For instance, the move flag either freezes particles in space or lets them move around. Giving the gravity parameter a non-zero value creates a constant force acting on the particles and which is either directed straight up or down. streak and beam are flags which when set to 'on' smudge or create a continuous beam behind a speeding particle, respectively.

vel_x, vel_y and vel_z are variables which represent the components of the vector velocity of the particle. Having direct access to particle velocity allows to program the trajectory of the particles without having to write the complete equations of motion for the vector position my.x of the particle (unlike what we have to do for ordinary entities, as explained in the C-script tutorial Tuesday lesson). Finally, lifespan is a variable which is defined as a timer and counts down the life of the particle. Its value is set by default to 80 ticks when the particle is created, and it is reduced by time ticks at each frame, therefore counting backwards the number of ticks remaining in the life of the particle. When lifespan is smaller or equal to zero, the particle is removed from the level and the memory it occupies is freed.

Next: 1.b Particle Creation