2013-05-28 19:52:51 +00:00
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
local require = require
|
2013-06-20 18:31:47 +00:00
|
|
|
|
|
|
|
local string = require("string")
|
|
|
|
local con = require("con")
|
2013-05-28 19:52:51 +00:00
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
local gv = gv
|
|
|
|
local sprite = sprite
|
|
|
|
local actor = actor
|
|
|
|
local player = player
|
|
|
|
|
|
|
|
local assert = assert
|
|
|
|
|
|
|
|
local printf = printf
|
|
|
|
local gameevent = gameevent
|
2013-05-28 19:52:51 +00:00
|
|
|
local spritesofstat = spritesofstat
|
|
|
|
|
|
|
|
local Inf = 0/1
|
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
|
|
|
|
module(...)
|
|
|
|
|
|
|
|
|
2013-05-28 19:52:51 +00:00
|
|
|
-- Insert MUSICANDSFX? (Delete it otherwise.)
|
2013-06-07 10:18:17 +00:00
|
|
|
insp = false
|
|
|
|
|
|
|
|
-- Hitag and lotag of last deleted MUSICANDSFX sprite.
|
|
|
|
tag = {}
|
|
|
|
tag.hi, tag.lo = 0, 0
|
2013-05-28 19:52:51 +00:00
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
-- 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
|
|
|
|
|
2013-06-12 17:49:53 +00:00
|
|
|
gameevent{"JUMP", actor.FLAGS.chain_beg,
|
2013-05-28 19:52:51 +00:00
|
|
|
function(aci, pli)
|
|
|
|
local ps = player[pli]
|
|
|
|
|
2013-06-07 10:18:17 +00:00
|
|
|
ournumjumps = ournumjumps+1
|
|
|
|
|
2013-05-28 19:52:51 +00:00
|
|
|
if (insp) then
|
|
|
|
-- Insert MUSICANDSFX sprite with same lo-/hitag as last deleted one.
|
2013-06-07 10:18:17 +00:00
|
|
|
printf("delmusicsfx: jump count=%d, inserting", ournumjumps)
|
2013-05-28 19:52:51 +00:00
|
|
|
|
|
|
|
local spr = sprite[con.spawn(aci, 5)]
|
2013-06-07 10:18:17 +00:00
|
|
|
spr.lotag, spr.hitag = tag.lo, tag.hi
|
2013-05-28 19:52:51 +00:00
|
|
|
else
|
|
|
|
-- Delete nearest MUSICANDSFX sprite.
|
|
|
|
|
|
|
|
local nearestdst = Inf
|
|
|
|
local nearesti = -1
|
|
|
|
|
2013-06-07 14:26:30 +00:00
|
|
|
for i in spritesofstat(actor.STAT.FX) do
|
2013-05-28 19:52:51 +00:00
|
|
|
local dst = (sprite[i]-ps.pos):len2()
|
2013-06-07 10:18:17 +00:00
|
|
|
if (nearesti == -1 or (dst < nearestdst and dst < sprite[i].hitag)) then
|
|
|
|
printf("MSFX %d dist %d", i, dst)
|
2013-05-28 19:52:51 +00:00
|
|
|
nearesti = i
|
|
|
|
nearestdst = dst
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (nearesti >= 0) then
|
|
|
|
local spr = sprite[nearesti]
|
2013-06-07 10:18:17 +00:00
|
|
|
tag.lo, tag.hi = spr.lotag, spr.hitag
|
2013-05-28 19:52:51 +00:00
|
|
|
actor.delete(nearesti)
|
|
|
|
end
|
2013-06-07 10:18:17 +00:00
|
|
|
|
|
|
|
assert(nearesti < 0 or sprite[nearesti].picnum==5)
|
|
|
|
printf("delmusicsfx: jump count=%d, deleting sprite %d", ournumjumps, nearesti)
|
2013-05-28 19:52:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
insp = not insp
|
2013-06-12 17:49:53 +00:00
|
|
|
end}
|
2013-06-20 18:31:47 +00:00
|
|
|
|
|
|
|
-- Display the number of times we jumped on the screen.
|
|
|
|
gameevent
|
|
|
|
{
|
|
|
|
"DISPLAYREST",
|
|
|
|
|
|
|
|
function()
|
2013-06-22 11:31:09 +00:00
|
|
|
con.minitext(240, 10, string.format("jumped %d times", ournumjumps))
|
2013-06-20 18:31:47 +00:00
|
|
|
end
|
|
|
|
}
|