rubber

  • 6nop6nop
    15th Jun 2022 Member 1 Permalink
    local RUBR = elem.allocate("MEEP", "RUBR")
    local BCOL = 73
    local GAS = 10
    local COAL = 59
    elem.element(elem.MEEP_PT_RUBR, elem.element(elem.DEFAULT_PT_GOO))
    elem.property(elem.MEEP_PT_RUBR, "Name", "RUBR")
    elem.property(elem.MEEP_PT_RUBR, "Description", "Rubber. Bouncy")
    elem.property(elem.MEEP_PT_RUBR, "Colour", 0xbfaf4f)
    elem.property(elem.MEEP_PT_RUBR, "Flammable", 30)
    
    elements.property(elem.MEEP_PT_RUBR, "Update",function (i, x, y, ss, nt)
        local vulcanization = tpt.parts[i].tmp
        cellX,cellY = x/4, y/4
        if sim.pressure(cellX,cellY) > 2+vulcanization or tpt.parts[i].temp > 375+(vulcanization*10) then
            tpt.parts[i].vx = tpt.parts[i].vx + sim.velocityX(cellX,cellY) * 0.05 --move like goo
            tpt.parts[i].vy = tpt.parts[i].vy + sim.velocityY(cellX,cellY ) * 0.05
            if sim.pressure(cellX,cellY) > 4 and tpt.parts[i].temp > 500 and math.random(0,10) == 1 then
                sim.partKill(i) --pyrolysis
                
                if math.random(1,2) > 1 then
                    sim.partCreate(-1,x,y,BCOL)
                else
                    sim.partCreate(-1,x,y,GAS)
                end
            end
        end
        if (ss < nt) then
           
            for r in sim.neighbors(x,y) do
                local t = sim.partProperty(r,sim.FIELD_TYPE)
                if t ~= RUBR  and vulcanization < 25 then
           
                    tpt.parts[r].vx  = tpt.parts[r].vx - tpt.parts[r].vx --bounce parts
                    tpt.parts[r].vy  = tpt.parts[r].vx - tpt.parts[r].vy 
                end
    
                if (t == COAL or t == BCOL) and tpt.parts[r].temp > 375 and math.random(0,10000) < 1 then
                    tpt.parts[i].tmp = tpt.parts[i].tmp+1
                    sim.partKill(r)
                end
    
    
            end
        end
    end)
    
    elements.property(elem.MEEP_PT_RUBR, "Graphics",function (i, colr, colg, colb)
        local j = math.max(1 - (tpt.parts[i].tmp /30 ),0.2)
        return 0, 0x00000001, 255, colr*j, colg*j, colb*j,  0,0,0,0
    end)