mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-16 17:31:27 +00:00
1715b7631f
Add a test case source/lunatic/test/delmusicsfx.lua. git-svn-id: https://svn.eduke32.com/eduke32@3822 1a8010ca-5511-0410-912e-c29ae57300e0
44 lines
1 KiB
Lua
44 lines
1 KiB
Lua
|
|
local con = require "con"
|
|
|
|
local spritesofstat = spritesofstat
|
|
|
|
local Inf = 0/1
|
|
|
|
-- Insert MUSICANDSFX? (Delete it otherwise.)
|
|
-- XXX: should be a per-player gamevar, but this is testing code.
|
|
local insp = false
|
|
local hitag, lotag = 0, 0
|
|
|
|
gameevent("JUMP",
|
|
function(aci, pli)
|
|
local ps = player[pli]
|
|
|
|
if (insp) then
|
|
-- Insert MUSICANDSFX sprite with same lo-/hitag as last deleted one.
|
|
|
|
local spr = sprite[con.spawn(aci, 5)]
|
|
spr.lotag, spr.hitag = lotag, hitag
|
|
else
|
|
-- Delete nearest MUSICANDSFX sprite.
|
|
|
|
local nearestdst = Inf
|
|
local nearesti = -1
|
|
|
|
for i in spritesofstat(gv.STAT_FX) do
|
|
local dst = (sprite[i]-ps.pos):len2()
|
|
if (nearesti == -1 or dst < nearestdst) then
|
|
nearesti = i
|
|
nearestdst = dst
|
|
end
|
|
end
|
|
|
|
if (nearesti >= 0) then
|
|
local spr = sprite[nearesti]
|
|
lotag, hitag = spr.lotag, spr.hitag
|
|
actor.delete(nearesti)
|
|
end
|
|
end
|
|
|
|
insp = not insp
|
|
end)
|