Andrettin wrote:Is there anywhere I can see an example of the particle system being used?
Currently there are 2 games on Stratagus which use particle system: Bos Wars and Doom Wars.
How it could be used:
1) define a particle:
Code: Select all
particle_building_smoke = {}
particle_building_smoke_light = {}
for i = 1, 4 do
particle_building_smoke[i] = LoadGraphic("graphics/missiles/particles/buildingsmoke"..i..".png", 16, 15)
particle_building_smoke_light[i] = LoadGraphic("graphics/missiles/particles/buildingsmoke"..(i + 4)..".png", 16, 15)
end
function addChunkParticles(amount, smokegraphic, debrisgraphic, ticksperframe1, ticksperframe2,
x, y, minvel, maxvel, minangle, maxTTL, destroyparticle, ticksperframe3, dlDeb, dlSmok, dlDest)
local smokeanimation = GraphicAnimation(smokegraphic, ticksperframe1)
local debrisanimation = nil
local destroyanimation = nil
if (debrisgraphic ~= nil) then
debrisanimation = GraphicAnimation(debrisgraphic, ticksperframe2)
else
debrisanimation = GraphicAnimation(nullgraphics, 1)
end
if (destroyparticle ~= nil) then
destroyanimation = GraphicAnimation(destroyparticle, ticksperframe3)
else
destroyanimation = GraphicAnimation(nullgraphics, 1)
end
for i = 1, amount do
local chunk = CChunkParticle(CPosition(x, y), smokeanimation, debrisanimation, destroyanimation, minvel, maxvel, minangle, maxTTL, dlDeb)
chunk:setSmokeDrawLevel(dlSmok)
chunk:setDestroyDrawLevel(dlDest)
ParticleManager:add(chunk:clone())
end
end
function addSmokeParticle(graphic, ticksperframe, x, y, speedx, speedy, drawlevel)
local smokeanimation = GraphicAnimation(graphic, ticksperframe)
local smoke = CSmokeParticle(CPosition(x, y), smokeanimation, speedx, speedy, drawlevel)
ParticleManager:add(smoke:clone())
end
2) define a unit lua handler function:
Code: Select all
DefineUnitType("unit-tech-center", {
................................
OnEachCycle = SmokeControlTechCenter,
........................................
} )
3) define that function and write whatever you want in it
Code: Select all
function ParticleBuildingSmoke(x, y)
addSmokeParticle(pickRandom(particle_building_smoke_light), 150, x + math.random(4) - 2, y + math.random(4) - 2, 2 + math.random(8), -15 - math.random(15), drawLevels.DL_PartGround)
end
function SmokeControlTechCenter(slot)
if (GetUnitVariable(slot,"HitPoints","Value") * 100 / GetUnitVariable(slot,"HitPoints","Max") <= 50)
and GetUnitVariable(slot,"SmokeTime") > 0 then
SetUnitVariable(slot,"SmokeBreak", GetUnitVariable(slot,"SmokeBreak") + 1)
if GetUnitVariable(slot,"SmokeBreak") == 8 then
SetUnitVariable(slot,"SmokeBreak", 0)
local x = GetUnitVariable(slot, "PosX") * 32
local y = GetUnitVariable(slot, "PosY") * 32
ParticleBuildingSmoke(x + 85, y + 81)
if math.random(100) >= 95 then
addChunkParticles(1, pickRandom(particle_building_smoke), pickRandom(particle_building_parts), 150, 100, x + 85, y + 81, 0, 400, 77, 0, nil, 0, drawLevels.DL_PartGround, drawLevels.DL_PartLow, drawLevels.DL_PartLow)
end
end
end
end
How that looks like in Doom Wars: