Built a much better version of my lightning / thunder gadget, to go along with the GLSL rain.
Here's sourcecode. I figure that this is something people will want to use for various things- amongst other things, remove the graphical stuff, and voila, you have a simplistic ambient-sound generator.
This requires the LUPS Module or 100% compatible to use as written (i.e., it'll work CA for sure) but I'm sure it could use CEGs instead with very little effort.
Code: Select all
function gadget:GetInfo()
return {
name = "Thunder Gadget",
desc = "Lightning and Thunder. Requires LUPS Module or 100% compatible",
author = "Argh",
date = "June 22, 2009",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
math_rand = math.random
local MaxSizeX = Game.mapSizeX
local MaxSizeZ = Game.mapSizeZ
local randomTime = 0
local randomFlashes = 0
local randomX, randomZ
if (gadgetHandler:IsSyncedCode()) then
function gadget:GameFrame(f)
--Spring.Echo(f,randomTime)
if f == randomTime then
randomX = math_rand(0,MaxSizeX)
randomZ = math_rand(0,MaxSizeZ)
randomSound = math_rand(1,5)
if randomSound == 1 then
Spring.PlaySoundFile("sounds/thunder05.wav", 30, randomX, 1000, randomZ)
end
if randomSound == 2 then
Spring.PlaySoundFile("sounds/thunder06.wav", 30, randomX, 1000, randomZ)
end
if randomSound == 3 then
Spring.PlaySoundFile("sounds/thunder07.wav", 30, randomX, 1000, randomZ)
end
if randomSound == 4 then
Spring.PlaySoundFile("sounds/thunder08.wav", 30, randomX, 1000, randomZ)
end
if randomSound == 5 then
Spring.PlaySoundFile("sounds/thunder09.wav", 30, randomX, 1000, randomZ)
end
end
if f >= randomTime and randomFlashes > 0 then
SendToUnsynced("lups_lightning", randomX, randomZ)
randomFlashes = randomFlashes - 1
return
end
if f >= randomTime and randomFlashes <=0 then
randomTime = f + math_rand(300,500)
randomFlashes = math_rand(10,30)
return
end
end
else
local mySize, myLife, randomT, randomA1, randomA2
local randomTexture = 'bitmaps/lightning1.tga'
local function SpawnLightning(_, randomX, randomZ)
local Lups = GG['Lups']
randomX = randomX + math_rand(-1024,1024)
randomZ = randomZ + math_rand(-1024,1024)
mySize = math_rand(512,1536)
myLife = math_rand(10,30)
randomA1 = math_rand(0.5,1.0)
randomA2 = math_rand(0.3,1.0)
randomT = math_rand(1,3)
if randomT == 1 then
randomTexture = 'bitmaps/lightning1.tga'
end
if randomT == 2 then
randomTexture = 'bitmaps/lightning2.tga'
end
if randomT == 3 then
randomTexture = 'bitmaps/lightning3.tga'
end
Lups.AddParticles('GroundFlash',{
texture = randomTexture,
layer=-40,
pos={randomX,Spring.GetGroundHeight(randomX,randomZ),randomZ},
life = myLife,
size = mySize,
sizeGrowth = -12,
colormap = {{0.9, 0.9, 1.0, randomA1},{0.5, 0.5, 1.0, 0.1},{0.9, 0.9, 1.0, randomA2},{0.5, 0.5, 1.0, 0},},
repeatEffect=false,
})
end
function gadget:Initialize()
gadgetHandler:AddSyncAction("lups_lightning", SpawnLightning)
end
function gadget:Shutdown()
gadgetHandler.RemoveSyncAction("lups_lightning")
end
end