Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lastparticle = -1
- local overlay = false
- local lastkey = {}
- local dokeypress
- local function step()
- if tpt.set_pause() == 0 then
- lastparticle = -1
- end
- if overlay then
- for i in sim.parts() do
- if i <= lastparticle then
- tpt.drawpixel(math.floor(tpt.get_property("x", i)+.5), math.floor(tpt.get_property("y", i)+.5), 0, 0, 0, 150)
- else
- break
- end
- end
- end
- if lastkey["time"] and lastkey["time"] < socket.gettime() then
- dokeypress(lastkey["key"], lastkey["nkey"], lastkey["modifier"], lastkey["event"])
- lastkey["time"] = socket.gettime()+.1
- end
- end
- tpt.register_step(step)
- --replicate TPT's life decreasing
- local function decreaselife()
- for i in sim.parts() do
- local life = tpt.get_property("life", i)
- local properties = elem.property(tpt.get_property("type", i), "Properties")
- if life > 0 and bit.band(properties, elem.PROP_LIFE_DEC) ~= 0 then
- if life == 1 and bit.band(properties, bit.bor(elem.PROP_LIFE_KILL_DEC,elem.PROP_LIFE_KILL)) ~= 0 then
- sim.partKill(i)
- else
- tpt.set_property("life", life-1, i)
- end
- elseif life <= 0 and bit.band(properties, elem.PROP_LIFE_KILL) ~= 0 then
- sim.partKill(i)
- end
- end
- end
- function dokeypress(key, nkey, modifier, event)
- if event == 1 and key == 'f' then
- if bit.band(modifier, 0x300) ~= 0 then
- overlay = not overlay
- return false
- elseif bit.band(modifier, 0xC0) ~= 0 then --ctrl is pressed
- lastparticle = lastparticle + 1
- if lastparticle >= sim.XRES*sim.YRES then
- print("reached the end of the particles")
- lastparticle = -1
- else
- if lastparticle == -1 then
- print("decreasing particle life")
- decreaselife()
- end
- while lastparticle < sim.XRES*sim.YRES and tpt.get_property("type", lastparticle) == 0 do
- lastparticle = lastparticle + 1
- end
- sim.updateParticles(lastparticle, lastparticle)
- end
- return false
- elseif bit.band(modifier, 0x3) ~= 0 then --shift is pressed
- local mousex, mousey = sim.adjustCoords(tpt.mousex, tpt.mousey)
- local i = sim.pmap(mousex, mousey)
- if i then
- if i > lastparticle then
- print("advancing from particle #"..(lastparticle+1).." to particle #"..i)
- sim.updateParticles(lastparticle+1, i)
- lastparticle = i
- else
- print("#"..lastparticle.." has already been updated")
- end
- else
- print("advancing to end (particles #"..(lastparticle+1).." to #"..(sim.XRES*sim.YRES-1)..")")
- sim.updateParticles(lastparticle+1, sim.XRES*sim.YRES-1)
- lastparticle = -1
- end
- return false
- else
- lastparticle = -1
- end
- end
- end
- local function keypress(key, nkey, modifier, event)
- if event == 1 then
- lastkey = {["key"] = key, ["nkey"] = nkey, ["modifier"] = modifier, ["event"] = event, ["time"] = socket.gettime()+.5}
- else
- lastkey = {}
- end
- return dokeypress(key, nkey, modifier, event)
- end
- tpt.register_keypress(keypress)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement