controllable energy particles

  • mrsalit0s
    12th Aug 2012 Member 6 Permalink

    with this script (it was originally made to learn how to use keypress events) you are able to control the speed and the direction of energy particles (NEUT, ELEC, PHOT). change the direction with arrow keys and the vx/vy speed with J (+0.1) and K (-0.1). the speed is updated only after pressing an arrow key.

     

     

    local epup = false
    local epdown = false
    local epright = false
    local epleft = false

    local active = true
    local vnum = 1
    local epdir = ""
    local hud = 1

    function control(key,dkey,_,event)
        if dkey == 273 then --up arrow
            epup = true
            epdown = false
            epright = false
            epleft = false
            active = true
        end
        if dkey == 274 then --down arrow
            epup = false
            epdown = true
            epright = false
            epleft = false
            active = true
        end
        if dkey == 276 then --right arrow
            epup = false
            epdown = false
            epright = true
            epleft = false
            active = true
        end
        if dkey == 275 then --left arrow
            epup = false
            epdown = false
            epright = false
            epleft = true
            active = true
        end
        if event==1 then
            if key == "j" then
                vnum=vnum+0.1
            end
            if key == "m" then
                vnum=vnum-0.1
            end
            if key == "h" and hud==1 then
                tpt.unregister_step(status)
                hud=0
            else
                if key == "h" and hud==0 then
                    tpt.register_step(status)
                    hud=1
                end
            end
        end
    end

    function contr(i,x,y,s,n)
        if active then
            if epup then
                tpt.set_property("vy",-vnum)
                tpt.set_property("vx",0)
                pdir = "up"
                active = false
            end
            if epdown then
                tpt.set_property("vy",vnum)
                tpt.set_property("vx",0)
                pdir = "down"
                active = false
            end
            if epright then
                tpt.set_property("vy",0)
                tpt.set_property("vx",-vnum)
                pdir = "left"
                active = false
            end
            if epleft then
                tpt.set_property("vy",0)
                tpt.set_property("vx",vnum)
                epdir = "right"
                active = false
            end
        end
    end

    function status()
        tpt.drawtext(155,5,"Energy particle speed:",0,255,0)
        tpt.drawtext(260,5,vnum)
        tpt.drawtext(285,5,"Direction:",0,255,0)
        tpt.drawtext(332,5,epdir)
    end

    tpt.register_step(status)
    tpt.element_func(contr,tpt.el.phot.id)
    tpt.element_func(contr,tpt.el.neut.id)
    tpt.element_func(contr,tpt.el.elec.id)
    tpt.register_keypress(control)
    --By MrSalit0s

  • boxmein
    12th Aug 2012 Former Staff 0 Permalink
    @mrsalit0s (View Post)
    Nice job! Here's a screenshot of the mod:
    Image of Powder Toy with this mod
  • mrsalit0s
    12th Aug 2012 Member 0 Permalink

    @boxmein (View Post)

    thanks! i will make an animated gif and add it to the first post then :)

  • boxmein
    12th Aug 2012 Former Staff 1 Permalink
    @mrsalit0s (View Post)
    If you want it to be easy, use LICEcap to record the desktop.
  • mrsalit0s
    13th Aug 2012 Member 0 Permalink

    @boxmein (View Post)

    thanks again ^^ this is definitely better than the program i used before to capture gif's.

  • lorddeath
    13th Aug 2012 Member 0 Permalink

    @mrsalit0s (View Post)

     

    OK i wanna try this!

  • Poorsoft
    13th Aug 2012 Member 0 Permalink

    @mrsalit0s (View Post)

    This is amazing, you are capable of many things, by far. +1'ed your rep, and I may try this soon, if I have time.

  • mniip
    13th Aug 2012 Developer 0 Permalink
     if photleft==true then 

    ... basically == returns true if operands equal, why not
     if photleft then 

    much shorter

     tpt.set_property("vx",-(vnum)) 

    why parentheses?
  • mrsalit0s
    13th Aug 2012 Member 0 Permalink

    @mniip (View Post)

    okay, these things have changed now. don't know why i used parentheses here

  • EqualsThree
    13th Aug 2012 Member 0 Permalink

    Just tried this out, awesome work, man.