Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- CCSand by CosmoConsole
- Supports Redirect API created by GopherAtl
- License: Creative Commons Attribution-NonCommercial-ShareAlike (http://creativecommons.org/licenses/by-nc-sa/3.0/)
- A program coded with LUA for dan200's (Daniel Ratcliffe) ComputerCraft mod (http://www.computercraft.info/)
- created for Minecraft by Mojang AB (http://minecraft.net/)
- This program is a falling sand-type of simulator game.
- Do not change anything beyond this if you are not sure what to do.
- --]]
- -- Build no 111
- --assert(true, "Program is in development phase. Remove the first line if you're a debugger.")
- version = " v0.5"
- if term.isColor() == false then
- error("This program requires an Advanced Computer")
- end
- paused = true
- on = true
- drawing = false
- dirty = true
- particleLimit = 1000
- page = 0
- sel = 1
- fps = 10
- menu = false
- debug = false
- shouldRender = false
- buffer=term
- API = false
- ipart = nil
- statusbar = ""
- textReset = os.startTimer(5)
- brushSize = 1
- logs = fs.open("ccsand.log", "a")
- function log(s)
- logs.writeLine(os.day() .. "-" .. textutils.formatTime(os.time(),true) .. "; " .. s)
- end
- -- elements = [1] = {name, bg, fg, ch, type, spread%, grav%, weight, flam, init, inil, inic, ltp, ltr, htp, htr, inv, func, tc, expl, tool}
- -- (l/h)t(p/r) = low/high temperature point/reaction
- -- inv = can other materials go into it
- -- func = own function
- -- ini(t/l/c) = initial temperature/life/co-type
- -- type; solid = 0, powder = 1, liquid = 2
- elements = {
- [0] = {" Air ", colors.black, colors.white, " ", 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 0, 0, 0},
- [1] = {" Sand", colors.yellow, colors.white, ":", 1, 20, 90, 52, 0, 295, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 35, 0, 0},
- [2] = {" Wall", colors.lime, colors.lime, ".", 0, 0, 0, 100, 0, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 80, 0, 0},
- [3] = {"Water", colors.blue, colors.lightBlue, "~", 2, 8, 95, 30, 0, 295, 0, 0, 272.9, 16, 373.1, 15, 0, ["func"] = nil, 25, 0, 0},
- [4] = {" Void", colors.purple, colors.black, "+", 0, 0, 0, 100, 0, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = nil, 80, 0, 0},
- [5] = {"Crazy", colors.white, colors.blue, "X", 0, 0, 0, 0, 0, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = nil, 70, 0, 0},
- [6] = {" N2 ", colors.lightBlue, colors.white, ":", 0, 0, 0, 10, 0, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = gas_movement, 30, 0, 0},
- [7] = {" Fire", colors.orange, colors.yellow, "^", 2, 8, -100, 24, 0, 595, 20, 0, 373, 18, -1, 0, 1, ["func"] = fire, 40, 0, 0},
- [8] = {" Oil ", colors.green, colors.yellow, "~", 2, 8, 95, 28, 80, 295, 0, 0, -1, 0, 600, 7, 0, ["func"] = nil, 40, 0, 0},
- [9] = {" O2 ", colors.lightBlue, colors.white, "O", 0, 0, 0, 10, 90, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = gas_movement, 30, 0, 0},
- [10] = {" Wood", colors.yellow, colors.brown, ":", 0, 0, 0, 100, 60, 293, 0, 0, -1, 0, 600, 7, 0, ["func"] = nil, 55, 0, 0},
- [11] = {" TNT ", colors.red, colors.pink, "T", 0, 0, 0, 100, 100, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 35, 1, 0},
- [12] = {"Insul", colors.lightGray, colors.magenta, ":", 0, 0, 0, 100, 0, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 0, 0, 0},
- [13] = {"*Heat", colors.red, colors.black, "H", 0, 0, 0, 100, 100, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 35, 1, 1},
- [14] = {"*Cool", colors.blue, colors.black, "C", 0, 0, 0, 100, 0, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = nil, 0, 0, 2},
- [15] = {"Steam", colors.lightGray, colors.white, ";", 2, 8, -95, 10, 0, 395, 0, 0, 373, 3, -1, 0, 0, ["func"] = nil, 25, 0, 0},
- [16] = {" Ice ", colors.cyan, colors.lightBlue, "o", 0, 0, 0, 100, 0, 253, 0, 0, -1, 0, 273, 3, 0, ["func"] = nil, 50, 0, 0},
- [17] = {"Plasm", colors.magenta, colors.yellow, "^", 2, 8, -100, 24, 0, 7595, 20, 5373, 7, 0, -1, 0, 1, ["func"] = fire, 40, 0, 0},
- [18] = {"Smoke", colors.gray, colors.black, "o", 2, 8, -100, 24, 0, 325, 10, 0, -1, 0, 423, 7, 1, ["func"] = death, 40, 0, 0},
- [19] = {"CFire", colors.blue, colors.cyan, "^", 2, 8, -100, 24, 0, 10, 20, 0, -1, 0, 173, 0, 1, ["func"] = death, 40, 0, 0},
- [20] = {"Neutr", colors.lightBlue, colors.cyan, ".", 0, 0, 0, 0, 0, 293, 15, -8, -1, 0, -1, 0, 1, ["func"] = neutrons, 25, 0, 0},
- [21] = {" Lava", colors.red, colors.orange, "~", 2, 8, 95, 30, 0, 2095, 0, 22, 1095, -1, -1, 0, 0, ["func"] = ignite, 50, 0, 0},
- [22] = {"Stone", colors.gray, colors.lightGray, ":", 1, 20, 96, 65, 0, 295, 0, 0, -1, 0, 1100, 21, 0, ["func"] = nil, 70, 0, 0},
- [23] = {"Metal", colors.blue, colors.gray, "X", 0, 0, 0, 100, 0, 293, 0, 0, -1, 0, 1150, 21, 0, ["func"] = nil, 90, 0, 0},
- [24] = {" CO2 ", colors.lightGray, colors.gray, "O", 1, 20, 15, 10, 0, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = co2, 30, 0, 0},
- [25] = {" H2 ", colors.lightBlue, colors.cyan, "O", 2, 0, -1, 5, 0, 295, 0, 0, -1, 0, -1, 0, 1, ["func"] = h2, 30, 0, 0},
- [26] = {"Clone", colors.cyan, colors.yellow, "C", 0, 0, 0, 100, 0, 293, 0, 0, -1, 0, -1, 0, 0, ["func"] = clone, 70, 0, 0},
- }
- if debug == true then
- log("CCSand opened in debug mode!")
- end
- local splashes = {
- "CC stands for CosmoConsole and ComputerCraft",
- "You need Advanced Computers for this",
- "Try to save & load!",
- "This game doesn't have moving solids"
- }
- statusbar = splashes[math.random(1, #splashes)]
- if debug then log("Searching for Redirect API created by GopherAtl") end
- if redirect then
- buffer=redirect.createRedirectBuffer()
- if debug then log("Redirect buffer enabled") end
- else
- local ok=pcall(os.loadAPI,"redirect")
- if not ok then ok=pcall(os.loadAPI,shell.dir().."/redirect") end
- if (ok) and (redirect) then
- buffer=redirect.createRedirectBuffer()
- if debug then log("Redirect buffer loaded and enabled") end
- API = true
- else
- if debug then log("Redirect buffer not found") end
- end
- term.restore()
- end
- term.clear()
- creationTemp = nil
- creationCotype = nil
- creationLife = nil
- MAX_TEMP = 9999
- MIN_TEMP = 0
- --print("Press Q to Quit!")
- function trim(s)
- return (s:gsub("^%s*(.-)%s*$", "%1"))
- end
- function log2(input)
- return (math.log(input)/math.log(2))
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function openMenu()
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- term.setCursorPos(47, 19)
- write(version)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- menu = true
- dirty = true
- end
- function pause()
- --write("Pause toggled")
- paused = not paused
- end
- function quit()
- --term.clear()
- --term.setCursorPos(5, 5)
- --print("Thank you for playing!")
- --print("ccSand by CosmoConsole")
- --os.sleep(3)
- term.clear()
- term.setCursorPos(1, 1)
- logs.close()
- on = false
- end
- --log("CCSand opened.")
- grid = {1, 40, 1, 17}
- --40x17 grid
- lx = 0
- ly = 0
- -- [particle_id] = {id, x, y, type, life, cotype, temp}
- -- particle 0 to avoid 'nil'
- particles = {
- } --[0] = {0, 0, 0, 0, 0, 0, 0}
- -- particle ID begins at 1. 0 is air.
- part_id = 1
- function getParticleCalled(i)
- for k, v in pairs(particles) do
- if v[1] == i then
- return k
- end
- end
- return 0
- end
- function getParticleAt(x,y)
- for k, v in pairs(particles) do
- if v[2] == x then
- if v[3] == y then
- return k
- end
- end
- end
- return 0
- end
- function render2(pt,rx,ry)
- if rx < grid[1] then return end
- if rx > grid[2] then return end
- if ry < grid[3] then return end
- if ry > grid[4] then return end
- term.setCursorPos(rx,ry)
- term.setBackgroundColor(elements[pt][2])
- term.setTextColor(elements[pt][3])
- print(elements[pt][4])
- --buffer[rx[ry]] = {elements[pt][4], elements[pt][2], elements[pt][3]}
- end
- function render(rx,ry,part)
- if part == nil then
- p = getParticleAt(rx,ry)
- else
- p = part
- rx = part[2]
- ry = part[3]
- end
- if rx < grid[1] then return end
- if rx > grid[2] then return end
- if ry < grid[3] then return end
- if ry > grid[4] then return end
- px = particles[p]
- term.setCursorPos(rx,ry)
- if px == nil then
- px = {0,0,0,0,0,0,0}
- end
- term.setBackgroundColor(elements[px[4]][2])
- term.setTextColor(elements[px[4]][3])
- print(elements[px[4]][4])
- end
- function createParticle(x,y,type,life,cotype,temp)
- if getParticleAt(x,y) ~= 0 then
- return 0
- end
- if x == nil then
- return 0
- end
- if y == nil then
- return 0
- end
- if type == nil then
- return 0
- end
- if y > grid[4] then
- return 0
- end
- if y < grid[3] then
- return 0
- end
- if x > grid[2] then
- return 0
- end
- if x < grid[1] then
- return 0
- end
- if #particles > particleLimit then
- return 0
- end
- l = elements[type][11]
- if life ~= nil then l = life end
- if l < 0 then l = math.random(0 - l) end
- c = elements[type][12]
- if cotype ~= nil then c = cotype end
- if c < 0 then c = math.random(0 - c) end
- t = elements[type][10]
- if temp ~= nil then t = temp end
- i = part_id
- part_id = part_id + 1
- if debug == true then
- log("Creating particle of " .. type .. " at " .. x .. "," .. y)
- end
- dirty = true
- render(x, y, table.insert(particles, {i, x, y, type, l, c, t}))
- return i
- end
- function killParticle(i)
- if particles[i] then
- px = particles[i][2]
- py = particles[i][3]
- if debug == true then
- log("Killing particle #" .. particles[i][1] .. " at " .. px .. "," .. py)
- end
- if i == ipart then ipart = nil end
- table.remove(particles, i)
- dirty = true
- --render(px,py)
- end
- return true
- end
- function drawElement(i,x,y)
- if elements[i] == nil then return end
- tx = elements[i][3]
- bx = elements[i][2]
- if bx == tx then
- tx = colors.white
- end
- if bx == 256 then
- tx = colors.black
- end
- if bx < 128 then
- tx = colors.black
- end
- --log("drawElement: tx is " .. tx .. " and bx is " .. bx)
- term.setBackgroundColor(bx)
- term.setTextColor(tx)
- x1, y1 = term.getCursorPos()
- term.setCursorPos(x,y)
- write(elements[i][1])
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(x1, y1)
- end
- function selectElement(i)
- if i > (#elements) then return end
- sel = i
- drawElement(i,46,17)
- end
- function kissa()
- for i = 1,1000 do
- drawElement(math.random(0,#elements),math.random(1,50),math.random(1,17))
- end
- end
- function info(x,y)
- if y > grid[4] then return end
- if y < grid[3] then return end
- if x > grid[2] then return end
- if x < grid[1] then return end
- local pxy = getParticleAt(x,y)
- if pxy ~= 0 then
- ipart = particles[pxy]
- else
- ipart = nil
- end
- dirty = true
- end
- function closeMenu()
- dirty = true
- menu = false
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, 19)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 19)
- write("ccSand by CosmoConsole")
- term.setCursorPos(47, 19)
- write(version)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- end
- function drawPage(i)
- ep = (i * 16) + 1
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- for iterator_a=1,17 do
- term.setCursorPos(41,iterator_a)
- write(" ")
- end
- for iterator_a=1,8 do
- drawElement(ep,41,iterator_a+3)
- ep = ep + 1
- drawElement(ep,46,iterator_a+3)
- ep = ep + 1
- end
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.white)
- term.setCursorPos(42, 2)
- write("<")
- term.setCursorPos(49, 2)
- write(">")
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(45, 2)
- write(" ")
- term.setCursorPos(45, 2)
- write(page + 1)
- end
- function menuToggle()
- if menu == true then
- closeMenu()
- else
- openMenu()
- end
- end
- function particleMove(p1,p2,px,py)
- pm1 = particles[p1]
- pm2 = particles[p2]
- if p2 == 0 then
- inGrid = false
- if px >= grid[1] then
- if px <= grid[2] then
- if py >= grid[3] then
- if py <= grid[4] then
- inGrid = true
- end
- end
- end
- end
- if inGrid == true then
- if particles[p1] == nil then return false end
- opx = particles[p1][2]
- opy = particles[p1][3]
- particles[p1][2] = px
- particles[p1][3] = py
- render(px,py)
- render(opx,opy)
- dirty = true
- if debug == true then
- log("Moving particle #" .. particles[p1][1] .. " from " .. opx .. "," .. opy .. " to " .. px .. "," .. py)
- end
- return true
- else
- killParticle(p1)
- return true
- end
- end
- return false
- end
- function particleSwitch(p1,p2,px,py)
- pm1 = particles[p1]
- pm2 = particles[p2]
- if p2 == 0 then
- inGrid = false
- if px >= grid[1] then
- if px <= grid[2] then
- if py >= grid[3] then
- if py <= grid[4] then
- inGrid = true
- end
- end
- end
- end
- if inGrid == true then
- opx = particles[p1][2]
- opy = particles[p1][3]
- particles[p1][2] = px
- particles[p1][3] = py
- render(px,py)
- render(opx,opy)
- dirty = true
- if debug == true then
- log("Moving particle #" .. particles[p1][1] .. " from " .. opx .. "," .. opy .. " to " .. px .. "," .. py)
- end
- else
- killParticle(p1)
- end
- else
- if particles[p2][4] == 4 then
- if debug == true then
- log("VOID: *slurp*")
- end
- killParticle(p1)
- return
- end
- --particles[p1][2] = pm2[2]
- --particles[p2][2] = pm1[2]
- --particles[p1][3] = pm2[3]
- --particles[p2][3] = pm1[3]
- opx = particles[p2][2]
- opy = particles[p2][3]
- particles[p2][2] = particles[p1][2]
- particles[p2][3] = particles[p1][3]
- particles[p1][2] = opx
- particles[p1][3] = opy
- dirty = true
- if debug == true then
- log("Switching particles between " .. pm1[2] .. "," .. pm1[3] .. " and " .. pm2[2] .. "," .. pm2[3])
- end
- end
- end
- function notYetImplemented()
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, 19)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 19)
- write("Not yet implemented")
- term.setCursorPos(47, 19)
- write(version)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- end
- function rect(xa,ya,xb,yb)
- if not (xa and xb and ya and yb) then
- return
- end
- local dp = 0
- for xi=xa,xb do
- for yi=ya,yb do
- if elements[sel][20] == 0 then
- createParticle(p2,p3,sel,creationLife,creationCotype,creationTemp)
- elseif elements[sel][20] == 1 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.min(particles[getParticleAt(p2,p3)][7] + 5, MAX_TEMP) end
- elseif elements[sel][20] == 2 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.max(particles[getParticleAt(p2,p3)][7] - 5, MIN_TEMP) end
- end
- dp = dp + 1
- end
- end
- return xa .. "-" .. xb .. "," .. ya .. "-" .. yb .. ";" .. dp .. " vs " .. (((xb - xa) + 1) * ((yb - ya) + 1))
- end
- function arect(xa,ya,xb,yb)
- if not (xa and xb and ya and yb) then
- return
- end
- local dp = 0
- for xi=xa,xb do
- for yi=ya,yb do
- createParticle(xi, yi, 0)
- dp = dp + 1
- end
- end
- return xa .. "-" .. xb .. "," .. ya .. "-" .. yb .. ";" .. dp .. " vs " .. (((xb - xa) + 1) * ((yb - ya) + 1))
- end
- function setStatus(sx)
- textReset = os.startTimer(5)
- statusbar = string.sub(sx, 1, 51)
- dirty = true
- end
- local fileEngine = nil
- local fileName = nil
- local serid = nil
- function saveAt()
- fileEngine = fs.open(fileName, "w")
- fileEngine.write(serid)
- fileEngine.close()
- fileEngine = nil
- end
- function loadAt()
- fileEngine = fs.open(fileName, "r")
- particles = textutils.unserialize(fileEngine.readAll())
- fileEngine.close()
- fileEngine = nil
- end
- function save()
- term.setCursorPos(1, 18)
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 18)
- sleep(0.5)
- write(">")
- cons = read()
- closeMenu()
- if trim(cons) == "" then
- redraw()
- timeout = os.startTimer(0)
- return
- end
- fileName = cons
- ok = true
- serid = textutils.serialize(particles)
- --ok, err = pcall(setFileEngineWrite)
- ok, err = pcall(saveAt)
- if ok then
- setStatus("Successfully saved")
- else
- if err then setStatus(tostring(err)) end
- end
- timeout = os.startTimer(0)
- end
- function load()
- term.setCursorPos(1, 18)
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 18)
- sleep(0.5)
- write(">")
- cons = read()
- closeMenu()
- dirty = true
- if trim(cons) == "" then
- redraw()
- timeout = os.startTimer(0)
- return
- end
- fileName = cons
- ok = true
- --ok, err = pcall(setFileEngineRead)
- ok, err = pcall(loadAt)
- if ok then
- setStatus("Successfully loaded")
- else
- if err then setStatus(tostring(err)) end
- end
- timeout = os.startTimer(0)
- end
- function clear()
- particles = {}
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- for i = 1,16 do
- term.setCursorPos(1,i)
- write(string.rep(" ", 40))
- end
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- closeMenu()
- end
- function mquit()
- if menu == true then
- quit()
- end
- end
- function mload()
- if menu == true then
- load()
- end
- end
- function msave()
- if menu == true then
- save()
- end
- end
- function mclear()
- if menu == true then
- clear()
- end
- end
- function redraw()
- if debug then log("Can I redraw now?") end
- if buffer.isBuffer then term.redirect(buffer) end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if debug then log("Redraw: Clearing buffer") end
- for i = 1,17 do
- term.setCursorPos(1,i)
- write(string.rep(" ", 40))
- end
- if debug then log("Redraw: Buffer clear. Starting particle render.") end
- for k, v in ipairs(particles) do
- render2(v[4], v[2], v[3])
- end
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, 19)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 19)
- write(statusbar)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 18)
- write(string.rep(" ", 51))
- term.setCursorPos(11, 18)
- write("[MENU]")
- drawPage(page)
- drawElement(sel,46,17)
- if debug then log("Redraw: Rendered particles.") end
- if menu == true then
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, 19)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 19)
- write("[EN]Quit [L]oad [S]ave [C]lear")
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- end
- if ipart == nil then
- drawElement(0,41,17)
- term.setCursorPos(41,16)
- print(" ")
- else
- drawElement(ipart[4],41,17)
- term.setCursorPos(41,16)
- print(" ")
- term.setCursorPos(41,16)
- print(ipart[5])
- term.setCursorPos(46,16)
- print(ipart[6])
- term.setCursorPos(41,18)
- print(" ")
- term.setCursorPos(41,18)
- print((ipart[7] - 273.15) .. " C")
- end
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- if buffer.isBuffer then
- if debug then log("Buffering.") end
- term.restore()
- buffer.blit()
- end
- dirty = false
- end
- function setPage(i)
- if i == -1 then
- i = 15
- end
- page = i % 16f
- drawPage(i % 16)
- end
- function nextPage()
- setPage(page + 1)
- end
- function previousPage()
- setPage(page - 1)
- end
- timeout = os.startTimer(0.1)
- function explode(x, y)
- local part
- if getParticleAt(x-1,y) ~= 0 then
- part = getParticleAt(x-1,y)
- particles[part][7] = particles[part][7] + 40
- particleMove(part,0,x-2,y)
- particleMove(part,0,x-1,y-1)
- particleMove(part,0,x-1,y+1)
- end
- if getParticleAt(x+1,y) ~= 0 then
- part = getParticleAt(x+1,y)
- particles[part][7] = particles[part][7] + 40
- particleMove(part,0,x+2,y)
- particleMove(part,0,x+1,y-1)
- particleMove(part,0,x+1,y+1)
- end
- if getParticleAt(x,y-1) ~= 0 then
- part = getParticleAt(x,y-1)
- particles[part][7] = particles[part][7] + 40
- particleMove(part,0,x,y-2)
- particleMove(part,0,x+1,y-1)
- particleMove(part,0,x-1,y-1)
- end
- if getParticleAt(x,y+1) ~= 0 then
- part = getParticleAt(x,y+1)
- particles[part][7] = particles[part][7] + 40
- particleMove(part,0,x,y+2)
- particleMove(part,0,x+1,y+1)
- particleMove(part,0,x-1,y+1)
- end
- end
- function clone(p, k, x, y)
- if getParticleAt(x-1,y) ~= 0 then
- if p[6] == 0 then
- if particles[getParticleAt(x-1,y)][4] ~= 26 then
- particles[k][6] = particles[getParticleAt(x-1,y)][4]
- end
- end
- end
- if p[6] ~= 0 then
- if math.random(1,2) == 1 then createParticle(x-1, y, p[6]) end
- if math.random(1,2) == 1 then createParticle(x+1, y, p[6]) end
- if math.random(1,2) == 1 then createParticle(x-1, y+1, p[6]) end
- if math.random(1,2) == 1 then createParticle(x+1, y+1, p[6]) end
- if math.random(1,2) == 1 then createParticle(x-1, y-1, p[6]) end
- if math.random(1,2) == 1 then createParticle(x+1, y-1, p[6]) end
- if math.random(1,2) == 1 then createParticle(x, y-1, p[6]) end
- if math.random(1,2) == 1 then createParticle(x, y+1, p[6]) end
- end
- end
- function co2(p, k, x, y)
- if getParticleAt(x-1,y) ~= 0 then
- if particles[getParticleAt(x-1,y)][4] == 7 then
- killParticle(getParticleAt(x-1,y))
- end
- end
- if getParticleAt(x+1,y) ~= 0 then
- if particles[getParticleAt(x+1,y)][4] == 7 then
- killParticle(getParticleAt(x+1,y))
- end
- end
- if getParticleAt(x,y-1) ~= 0 then
- if particles[getParticleAt(x,y-1)][4] == 7 then
- killParticle(getParticleAt(x,y-1))
- end
- end
- if getParticleAt(x,y+1) ~= 0 then
- if particles[getParticleAt(x,y+1)][4] == 7 then
- killParticle(getParticleAt(x,y+1))
- end
- end
- gas_movement(p, k, x, y)
- end
- function gas_movement(p, k, x, y)
- local m = math.random(1, 5)
- if m == 1 then particleMove(k, getParticleAt(x-1,y), x-1, y) end
- if m == 2 then particleMove(k, getParticleAt(x+1,y), x+1, y) end
- if m == 3 then particleMove(k, getParticleAt(x,y-1), x, y-1) end
- if m == 4 then particleMove(k, getParticleAt(x,y+1), x, y+1) end
- end
- function ignite(p, k, x, y)
- if getParticleAt(x-1,y) ~= 0 then
- if elements[particles[getParticleAt(x-1,y)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x-1,y)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x-1,y))
- createParticle(x-1,y,7)
- if elements[particles[getParticleAt(x-1,y)][4]][19] ~= 0 then
- explode(x-1,y)
- end
- end
- end
- end
- if getParticleAt(x+1,y) ~= 0 then
- if elements[particles[getParticleAt(x+1,y)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x+1,y)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x+1,y))
- createParticle(x+1,y,7)
- if elements[particles[getParticleAt(x+1,y)][4]][19] ~= 0 then
- explode(x+1,y)
- end
- end
- end
- end
- if getParticleAt(x,y-1) ~= 0 then
- if elements[particles[getParticleAt(x,y-1)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x,y-1)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x,y-1))
- createParticle(x,y-1,7)
- if elements[particles[getParticleAt(x,y-1)][4]][19] ~= 0 then
- explode(x,y-1)
- end
- end
- end
- end
- if getParticleAt(x,y+1) ~= 0 then
- if elements[particles[getParticleAt(x,y+1)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x,y+1)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x,y+1))
- createParticle(x,y+1,7)
- if elements[particles[getParticleAt(x,y+1)][4]][19] ~= 0 then
- explode(x,y+1)
- end
- end
- end
- end
- end
- function fire(p, k, x, y)
- if getParticleAt(x-1,y) ~= 0 then
- if elements[particles[getParticleAt(x-1,y)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x-1,y)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x-1,y))
- createParticle(x-1,y,7)
- if elements[particles[getParticleAt(x-1,y)][4]][19] ~= 0 then
- explode(x-1,y)
- end
- end
- end
- end
- if getParticleAt(x+1,y) ~= 0 then
- if elements[particles[getParticleAt(x+1,y)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x+1,y)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x+1,y))
- createParticle(x+1,y,7)
- if elements[particles[getParticleAt(x+1,y)][4]][19] ~= 0 then
- explode(x+1,y)
- end
- end
- end
- end
- if getParticleAt(x,y-1) ~= 0 then
- if elements[particles[getParticleAt(x,y-1)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x,y-1)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x,y-1))
- createParticle(x,y-1,7)
- if elements[particles[getParticleAt(x,y-1)][4]][19] ~= 0 then
- explode(x,y-1)
- end
- end
- end
- end
- if getParticleAt(x,y+1) ~= 0 then
- if elements[particles[getParticleAt(x,y+1)][4]][9] ~= 0 then
- if elements[particles[getParticleAt(x,y+1)][4]][9] >= math.random(100) then
- killParticle(getParticleAt(x,y+1))
- createParticle(x,y+1,7)
- if elements[particles[getParticleAt(x,y+1)][4]][19] ~= 0 then
- explode(x,y+1)
- end
- end
- end
- end
- death(p, k, x, y)
- end
- function seri()
- log(textutils.serialize(particles))
- end
- function h2(p, k, x, y)
- local igni = false
- if getParticleAt(x-1,y) ~= 0 then
- if particles[getParticleAt(x-1,y)][4] == 7 then
- igni = true
- end
- end
- if getParticleAt(x+1,y) ~= 0 then
- if particles[getParticleAt(x+1,y)][4] == 7 then
- igni = true
- end
- end
- if getParticleAt(x,y-1) ~= 0 then
- if particles[getParticleAt(x,y-1)][4] == 7 then
- igni = true
- end
- end
- if getParticleAt(x,y+1) ~= 0 then
- if particles[getParticleAt(x,y+1)][4] == 7 then
- igni = true
- end
- end
- if igni then
- killParticle(k)
- createParticle(x, y, 7, nil, 15, nil)
- end
- if particles[k] then gas_movement(p, k, x, y) end
- end
- function neutrons(p, k, x, y)
- if (particles[k]) then
- if (p[6] == 1) then
- if particleMove(k, getParticleAt(x,y-1), x, y - 1) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 2) then
- if particleMove(k, getParticleAt(x,y+1), x, y + 1) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 3) then
- if particleMove(k, getParticleAt(x-1,y+1), x - 1, y + 1) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 4) then
- if particleMove(k, getParticleAt(x-1,y), x - 1, y) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 5) then
- if particleMove(k, getParticleAt(x-1,y), x - 1, y - 1) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 6) then
- if particleMove(k, getParticleAt(x+1,y - 1), x + 1, y - 1) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 7) then
- if particleMove(k, getParticleAt(x+1,y), x + 1, y) == false then
- particles[k][6] = math.random(1,8)
- end
- elseif (p[6] == 8) then
- if particleMove(k, getParticleAt(x+1,y+1), x + 1, y + 1) == false then
- particles[k][6] = math.random(1,8)
- end
- end
- end
- if (particles[k]) then death(p, k, x, y) end
- end
- function death(p, k, x, y)
- particles[k][5] = p[5] - 1
- if particles[k] then
- if particles[k][5] == 0 then
- if particles[k][4] == 7 then
- if particles[k][6] == 15 then
- if particles[k] then killParticle(k) end
- createParticle(x, y, 15)
- else
- if particles[k] then killParticle(k) end
- createParticle(x, y, 18)
- end
- else
- killParticle(k)
- end
- end
- end
- end
- redraw()
- function temp_conduct(k)
- local sides = 0
- local top = false
- local bottom = false
- local left = false
- local right = false
- local ot = particles[k][7]
- local x = particles[k][2]
- local y = particles[k][3]
- local cond = {0, 0, 0, 0} --udlr
- if getParticleAt(x,y-1) ~= 0 then
- up = true
- sides = sides + 1
- cond[1] = math.min(elements[particles[getParticleAt(x,y-1)][4]][18], elements[particles[getParticleAt(x,y)][4]][18])
- end
- if getParticleAt(x,y+1) ~= 0 then
- down = true
- sides = sides + 1
- cond[2] = math.min(elements[particles[getParticleAt(x,y+1)][4]][18], elements[particles[getParticleAt(x,y)][4]][18])
- end
- if getParticleAt(x-1,y) ~= 0 then
- left = true
- sides = sides + 1
- cond[3] = math.min(elements[particles[getParticleAt(x-1,y)][4]][18], elements[particles[getParticleAt(x,y)][4]][18])
- end
- if getParticleAt(x+1,y) ~= 0 then
- right = true
- sides = sides + 1
- cond[4] = math.min(elements[particles[getParticleAt(x+1,y)][4]][18], elements[particles[getParticleAt(x,y)][4]][18])
- end
- if sides > 0 then
- for iter = 1,4 do
- cond[iter] = cond[iter] / (sides + 1)
- cond[iter] = cond[iter] * 1.5
- end
- end
- if cond[1] > 0 then
- local rt = particles[getParticleAt(x,y-1)][7]
- local tt = (ot + rt) / 2
- local oto = tt - ot
- local rto = tt - rt
- oto = oto / cond[1]
- rto = rto / cond[1]
- particles[getParticleAt(x,y)][7] = round(ot + oto, 2)
- particles[getParticleAt(x,y-1)][7] = round(rt + rto, 2)
- end
- if cond[2] > 0 then
- local rt = particles[getParticleAt(x,y+1)][7]
- local tt = (ot + rt) / 2
- local oto = tt - ot
- local rto = tt - rt
- oto = oto / cond[2]
- rto = rto / cond[2]
- particles[getParticleAt(x,y)][7] = round(ot + oto, 2)
- particles[getParticleAt(x,y+1)][7] = round(rt + rto, 2)
- end
- if cond[3] > 0 then
- local rt = particles[getParticleAt(x-1,y)][7]
- local tt = (ot + rt) / 2
- local oto = tt - ot
- local rto = tt - rt
- oto = oto / cond[3]
- rto = rto / cond[3]
- particles[getParticleAt(x,y)][7] = round(ot + oto, 2)
- particles[getParticleAt(x-1,y)][7] = round(rt + rto, 2)
- end
- if cond[4] > 0 then
- local rt = particles[getParticleAt(x+1,y)][7]
- local tt = (ot + rt) / 2
- local oto = tt - ot
- local rto = tt - rt
- oto = oto / cond[4]
- rto = rto / cond[4]
- particles[getParticleAt(x,y)][7] = round(ot + oto, 2)
- particles[getParticleAt(x+1,y)][7] = round(rt + rto, 2)
- end
- end
- buttons = {
- [1] = {11, 16, 18, 18, " Menu ", menuToggle, true},
- [2] = {1, 6, 18, 18, " || ", pause, true},
- [3] = {41, 45, 4, 4, "elem01", function () return selectElement((page * 16) + 1) end, true},
- [4] = {46, 50, 4, 4, "elem02", function () return selectElement((page * 16) + 2) end, true},
- [5] = {41, 45, 5, 5, "elem03", function () return selectElement((page * 16) + 3) end, true},
- [6] = {46, 50, 5, 5, "elem04", function () return selectElement((page * 16) + 4) end, true},
- [7] = {41, 45, 6, 6, "elem05", function () return selectElement((page * 16) + 5) end, true},
- [8] = {46, 50, 6, 6, "elem06", function () return selectElement((page * 16) + 6) end, true},
- [9] = {41, 45, 7, 7, "elem07", function () return selectElement((page * 16) + 7) end, true},
- [10] = {46, 50, 7, 7, "elem08", function () return selectElement((page * 16) + 8) end, true},
- [11] = {41, 45, 8, 8, "elem09", function () return selectElement((page * 16) + 9) end, true},
- [12] = {46, 50, 8, 8, "elem0a", function () return selectElement((page * 16) + 10) end, true},
- [13] = {41, 45, 9, 9, "elem0b", function () return selectElement((page * 16) + 11) end, true},
- [14] = {46, 50, 9, 9, "elem0c", function () return selectElement((page * 16) + 12) end, true},
- [15] = {41, 45, 10, 10, "elem0d", function () return selectElement((page * 16) + 13) end, true},
- [16] = {46, 50, 10, 10, "elem0e", function () return selectElement((page * 16) + 14) end, true},
- [17] = {41, 45, 11, 11, "elem0f", function () return selectElement((page * 16) + 15) end, true},
- [18] = {46, 50, 11, 11, "elem10", function () return selectElement((page * 16) + 16) end, true},
- [19] = {1, 8, 19, 19, "quit", mquit, true},
- [20] = {11, 16, 19, 19, "load", mload, true},
- [21] = {19, 24, 19, 19, "save", msave, true},
- [22] = {26, 32, 19, 19, "clear", mclear, true},
- [23] = {42, 42, 2, 2, "pprev", previousPage, true},
- [24] = {49, 49, 2, 2, "pnext", nextPage, true}
- }
- function simulate()
- xParticles = particles
- for k, v in ipairs(xParticles) do
- temp_conduct(k)
- e = elements[v[4]]
- continue = false
- if e[13] ~= -1 then
- if particles[k][7] <= e[13] then
- killParticle(k)
- if e[14] == -1 then
- createParticle(v[2], v[3], v[6], v[5], 0, v[7])
- else
- createParticle(v[2], v[3], e[14], v[5], v[6], v[7])
- end
- continue = true
- end
- end
- if e[15] ~= -1 then
- if particles[k][7] >= e[15] then
- killParticle(k)
- if e[16] == 21 then
- createParticle(v[2], v[3], e[16], v[5], v[4], v[7])
- else
- createParticle(v[2], v[3], e[16], v[5], v[6], v[7])
- end
- continue = true
- end
- end
- if continue == false then
- if e[5] ~= 0 then
- --Should move
- grav = e[7]
- spr = e[6]
- px = v[2]
- py = v[3]
- gf = math.floor(grav / 100)
- gp = grav % 100
- if gp >= math.random(100) then
- gf = gf + 1
- end
- gstep = -1
- sgf = 1
- if grav < 0 then
- gstep = 1
- sgf = -1
- end
- spread = false
- if spr >= math.random(100) then
- spread = true
- end
- if grav ~= 0 then
- --Can move down? If yes, then do it and ignore the rest.
- canGoDown = gf
- for i=gf,sgf,gstep do
- if getParticleAt(px,py+i) ~= 0 then
- if (elements[particles[getParticleAt(px,py+i)][4]][17] == 0) and (elements[particles[getParticleAt(px,py+i)][4]][8] >= e[8]) then
- canGoDown = (i + gstep)
- end
- end
- end
- if canGoDown ~= 0 then
- sp = 0
- if spread then
- sp = math.random(2)
- if sp == 2 then
- sp = -1
- end
- end
- if getParticleAt(px+sp,py+canGoDown) ~= 0 then
- if (elements[particles[getParticleAt(px+sp,py+canGoDown)][4]][17] == 0) then
- sp = 0
- end
- end
- --particleSwitch call: particle 1 table ID, particle 2 table ID, where particle 1 tries to move (X), where particle 1 tries to move (Y)
- if (sp ~= 0) and (canGoDown ~= 0) then
- particleSwitch(k, getParticleAt(px+sp,py+canGoDown), px+sp, py+canGoDown)
- end
- else
- --Okay, it cannot go down, how about diagonals? (1px left/right and 1px down).
- --First, can it go down-left diagonally?
- canGoDL = true
- if getParticleAt(px-1,py+sgf) ~= 0 then
- if (elements[particles[getParticleAt(px-1,py+sgf)][4]][17] == 0) and (elements[particles[getParticleAt(px-1,py+sgf)][4]][8] >= e[8]) then
- canGoDL = false
- end
- end
- canGoDR = true
- if getParticleAt(px+1,py+sgf) ~= 0 then
- if (elements[particles[getParticleAt(px+1,py+sgf)][4]][17] == 0) and (elements[particles[getParticleAt(px+1,py+sgf)][4]][8] >= e[8]) then
- canGoDR = false
- end
- end
- if (canGoDR) and (canGoDL) then
- dir = math.random(1,2)
- if dir == 1 then
- particleSwitch(k, getParticleAt(px+1,py+sgf), px+1, py+sgf)
- elseif dir == 2 then
- particleSwitch(k, getParticleAt(px-1,py+sgf), px-1, py+sgf)
- end
- elseif (canGoDR) or (canGoDL) then
- if canGoDR == true then particleSwitch(k, getParticleAt(px+1,py+sgf), px+1, py+sgf) end
- if canGoDL == true then particleSwitch(k, getParticleAt(px-1,py+sgf), px-1, py+sgf) end
- elseif (canGoDR == false) and (canGoDL == false) then
- --How about left/right (not down)? (Liquids only)
- if e[5] == 2 then
- canGoLeft = true
- canGoRight = true
- if getParticleAt(px-1,py) ~= 0 then
- if elements[particles[getParticleAt(px-1,py)][4]][17] == 0 then
- canGoLeft = false
- end
- end
- if getParticleAt(px+1,py) ~= 0 then
- if elements[particles[getParticleAt(px+1,py)][4]][17] == 0 then
- canGoRight = false
- end
- end
- if (canGoLeft) and (canGoRight) then
- dir = math.random(1,2)
- if dir == 1 then
- particleMove(k, getParticleAt(px-1,py), px-1, py)
- elseif dir == 2 then
- particleMove(k, getParticleAt(px+1,py), px+1, py)
- end
- else
- if canGoLeft then particleSwitch(k, getParticleAt(px-1,py), px-1, py) end
- if canGoRight then particleSwitch(k, getParticleAt(px+1,py), px+1, py) end
- end
- end
- end
- end
- end
- end
- end
- if e["func"] then
- --they get particle data, it's key, then X and Y
- if debug == true then
- log("Reached element function")
- end
- if particles[k] then
- e["func"](v, k, v[2], v[3])
- end
- end
- if particles[k] then
- if v[4] == 0 then
- killParticle(k)
- end
- end
- end
- end
- function setLife(i)
- local pc = getParticleAt(lx,ly)
- if pc == 0 then
- return
- end
- if lx == 0 then
- return
- end
- if ly == 0 then
- return
- end
- particles[pc][5] = i
- end
- function setCotype(i)
- local pc = getParticleAt(lx,ly)
- if pc == 0 then
- return
- end
- if lx == 0 then
- return
- end
- if ly == 0 then
- return
- end
- particles[pc][6] = i
- end
- function heat(i)
- local pc = getParticleAt(lx,ly)
- if pc == 0 then
- return
- end
- if lx == 0 then
- return
- end
- if ly == 0 then
- return
- end
- particles[pc][7] = math.min(particles[pc][7] + i, MAX_TEMP)
- end
- function cool(i)
- local pc = getParticleAt(lx,ly)
- if pc == 0 then
- return
- end
- if lx == 0 then
- return
- end
- if ly == 0 then
- return
- end
- particles[pc][7] = math.max(particles[pc][7] - i, MIN_TEMP)
- end
- term.clear()
- term.setCursorPos(1,1)
- info(1,1)
- while on do
- evt, p1, p2, p3, p4, p5 = os.pullEvent()
- if evt == "key" then
- --print(p1 .. " pressed")
- if p1 == 57 then
- pause()
- elseif p1 == 33 then
- if paused then simulate() end
- elseif p1 == 14 then
- term.setCursorPos(1, 18)
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.yellow)
- write(string.rep(" ", 51))
- term.setCursorPos(1, 18)
- write(">")
- cons = read()
- term.setCursorPos(1, 18)
- func, e = loadstring(cons, "lua")
- func2, e2 = loadstring("return " .. cons, "lua")
- nfp = 0
- if not func then
- if func2 then
- func = func2
- e = nil
- nfp = 1
- end
- else
- if func2 then
- func = func2
- end
- end
- setfenv(func,getfenv())
- result = {pcall(func)}
- if result[1] then
- nii = 1
- resulter = ">"
- while (result[nii + 1] ~= nil) or (nii <= nfp) do
- resulter = resulter .. tostring(result[nii + 1])
- nii = nii + 1
- end
- statusBar = string.sub(resulter, 1, 51)
- dirty = true
- else
- statusBar = string.sub(tostring(result[2]), 1, 51)
- dirty = true
- end
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 18)
- write(string.rep(" ", 51))
- textReset = os.startTimer(5)
- timeout = os.startTimer(0)
- end
- if (p1 == keys.leftCtrl) or (p1 == keys.rightCtrl) then
- if menu == true then
- closeMenu()
- else
- openMenu()
- end
- end
- if menu == true then
- if p1 == 46 then
- clear()
- end
- if p1 == 28 then
- quit()
- end
- if p1 == 31 then
- save()
- end
- if p1 == 38 then
- load()
- end
- end
- elseif evt == "mouse_drag" then
- if p2 >= grid[1] then
- if p2 <= grid[2] then
- if p3 >= grid[3] then
- if p3 <= grid[4] then
- if drawing == true then
- if p1 == 1 then
- if brushSize <= 1 then
- if elements[sel][20] == 0 then
- createParticle(p2,p3,sel,creationLife,creationCotype,creationTemp)
- elseif elements[sel][20] == 1 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.min(particles[getParticleAt(p2,p3)][7] + 5, MAX_TEMP) end
- elseif elements[sel][20] == 2 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.max(particles[getParticleAt(p2,p3)][7] - 5, MIN_TEMP) end
- end
- else
- local bs = (brushSize - 1)
- local ds = (brushSize * 2) - 1
- rect(p2-bs, p3-bs, (p2-bs)+ds, (p3-bs)+ds)
- end
- elseif p1 == 2 then
- if brushSize <= 1 then
- killParticle(getParticleAt(p2,p3))
- else
- local bs = (brushSize - 1)
- local ds = (brushSize * 2) - 1
- arect(p2-bs, p3-bs, (p2-bs)+ds, (p3-bs)+ds)
- end
- end
- end
- end
- end
- end
- end
- elseif evt == "mouse_click" then
- --write(p1 .. "," .. p2 .. "," .. p3 .. " ")
- if p2 >= grid[1] then
- if p2 <= grid[2] then
- if p3 >= grid[3] then
- if p3 <= grid[4] then
- drawing = true
- if p1 == 3 then
- info(p2, p3)
- end
- if p1 == 1 then
- lx = p2
- ly = p3
- if brushSize <= 1 then
- if elements[sel][20] == 0 then
- createParticle(p2,p3,sel,creationLife,creationCotype,creationTemp)
- elseif elements[sel][20] == 1 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.min(particles[getParticleAt(p2,p3)][7] + 5, MAX_TEMP) end
- elseif elements[sel][20] == 2 then
- if getParticleAt(p2,p3) ~= 0 then particles[getParticleAt(p2,p3)][7] = math.max(particles[getParticleAt(p2,p3)][7] - 5, MIN_TEMP) end
- end
- else
- local bs = (brushSize - 1)
- local ds = (brushSize * 2) - 1
- rect(p2-bs, p3-bs, (p2-bs)+ds, (p3-bs)+ds)
- end
- end
- if p1 == 2 then
- if brushSize <= 1 then
- killParticle(getParticleAt(p2,p3))
- else
- local bs = (brushSize - 1)
- local ds = (brushSize * 2) - 1
- arect(p2-bs, p3-bs, (p2-bs)+ds, (p3-bs)+ds)
- end
- end
- else
- drawing = false
- end
- else
- drawing = false
- end
- else
- drawing = false
- end
- else
- drawing = false
- end
- for k, v in pairs(buttons) do
- term.setCursorPos(1, k)
- --print(p2 .. "," .. p3 .. " vs " .. v[1] .. "-" .. v[2] .. "," .. v[3] .. "-" .. v[4])
- if p2 >= v[1] then
- if p2 <= v[2] then
- if p3 >= v[3] then
- if p3 <= v[4] then
- --print(v[func])
- if v[7] == true then
- v[6]()
- break
- end
- end
- end
- end
- end
- end
- elseif evt == "timer" and p1 == timeout then
- timeout = os.startTimer(1 / fps)
- --shouldRender = not shouldRender
- pb = colors.gray
- pf = colors.white
- if paused == true then
- pb = colors.white
- pf = colors.black
- else
- if menu == false then
- simulate()
- --if shouldRender == true then redraw() end
- end
- end
- --if dirty then redraw() end
- redraw()
- term.setBackgroundColor(pb)
- term.setTextColor(pf)
- term.setCursorPos(1, 18)
- write("[ || ]")
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- elseif evt == "timer" and p1 == textReset then
- statusbar = "ccSand by CosmoConsole " .. version
- dirty = true
- end
- end
- if API then os.unloadAPI("redirect") end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment