raze/polymer/eduke32/source/lunatic/test/delmusicsfx.lua
helixhorned 5db04f585e Lunatic: player method fadecol(), an improved palfrom.
Also, an external 'minitext' with optional shade and pal. args and
documentation for ps:padecol().

git-svn-id: https://svn.eduke32.com/eduke32@3893 1a8010ca-5511-0410-912e-c29ae57300e0
2013-06-20 18:31:50 +00:00

88 lines
2 KiB
Lua

local require = require
local string = require("string")
local con = require("con")
local gv = gv
local sprite = sprite
local actor = actor
local player = player
local assert = assert
local printf = printf
local gameevent = gameevent
local spritesofstat = spritesofstat
local Inf = 0/1
module(...)
-- Insert MUSICANDSFX? (Delete it otherwise.)
insp = false
-- Hitag and lotag of last deleted MUSICANDSFX sprite.
tag = {}
tag.hi, tag.lo = 0, 0
-- Preliminary dummy of a local gamevar.
local ournumjumps = 0
require "end_gamevars"
-- We may cache globals defined in the gamevar section afterwards, but not
-- refer to locals defined prior to the gamevar section in it.
local tag = tag
gameevent{"JUMP", actor.FLAGS.chain_beg,
function(aci, pli)
local ps = player[pli]
ournumjumps = ournumjumps+1
if (insp) then
-- Insert MUSICANDSFX sprite with same lo-/hitag as last deleted one.
printf("delmusicsfx: jump count=%d, inserting", ournumjumps)
local spr = sprite[con.spawn(aci, 5)]
spr.lotag, spr.hitag = tag.lo, tag.hi
else
-- Delete nearest MUSICANDSFX sprite.
local nearestdst = Inf
local nearesti = -1
for i in spritesofstat(actor.STAT.FX) do
local dst = (sprite[i]-ps.pos):len2()
if (nearesti == -1 or (dst < nearestdst and dst < sprite[i].hitag)) then
printf("MSFX %d dist %d", i, dst)
nearesti = i
nearestdst = dst
end
end
if (nearesti >= 0) then
local spr = sprite[nearesti]
tag.lo, tag.hi = spr.lotag, spr.hitag
actor.delete(nearesti)
end
assert(nearesti < 0 or sprite[nearesti].picnum==5)
printf("delmusicsfx: jump count=%d, deleting sprite %d", ournumjumps, nearesti)
end
insp = not insp
end}
-- Display the number of times we jumped on the screen.
gameevent
{
"DISPLAYREST",
function()
con.minitext(160, 10, string.format("jumped %d times", ournumjumps))
end
}