Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function createBlock(x, y, weight, structure, map)
- local block = {}
- block.parent = structure
- block.weight = weight
- block.pressure = 0
- block.map = map
- block.x = x
- block.y = y
- block.updateWeight = function(self)
- self.pressure = self.parent.pressure
- if self.map[self.x] ~= nil then
- if self.map[self.x][self.y] ~= nil then
- local block = self.map[self.x][self.y + 1]
- block:addPressure(block.pressure + self.weigth + self.pressure)
- blobk.parent:update()
- end
- end
- end
- block.addPressure = function(self, pressure)
- self.parent.pressure = self.parent.pressure + pressure
- self.pressure = self.parent.pressure
- end
- block.reload = function(self)
- local x = self.x
- local y = self.y
- local map = self.map
- if map[x] == nil then map[x] = {} end
- map[x][y] = self
- --print("block @ "..x..","..y)
- end
- block.draw = function(self, ox, oy)
- term.setCursorPos(self.x + ox, self.y + oy)
- term.setBackgroundColor(self.parent.col.back)
- term.setTextColor(self.parent.col.text)
- term.write(self.parent.col.char)
- end
- return block
- end
- local function createStructure(pos, length, dir, map, weight)
- local struct = {}
- for i=1,length do
- local p = {pos[1], pos[2]}
- p[dir] = p[dir] + (i - 1)
- local block = createBlock(p[1], p[2], weight, struct, map)
- struct[i] = block
- --print("Created block "..i)
- end
- struct.length = length
- struct.x = pos[1]
- struct.y = pos[2]
- struct.weight = weight
- struct.map = map
- struct.col = {}
- struct.col.back = colors.white
- struct.col.text = colors.black
- struct.col.char = " "
- struct.pressure = 0
- struct.reset = function(self)
- for i=1,self.length do
- local block = self[i]
- block.weight = self.weight
- block.pressure = 0
- end
- struct.pressure = 0
- end
- struct.update = function(self)
- for i=1,self.length do
- local block = self[i]
- block:updateWeight()
- end
- end
- struct.reload = function(self)
- --print("Reloading..")
- for i=1,self.length do
- local block = self[i]
- block:reload()
- end
- end
- struct:reload()
- return struct
- end
- local function createMap()
- local map = {}
- map.offset = {0,0}
- map.draw = function(self)
- --sleep(4)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- for x,ytab in pairs(map) do
- --if type(ytab) == "function" then ytab() end
- for y,block in pairs(ytab) do
- block:draw(map.offset[1], map.offset[2])
- end
- end
- end
- return map
- end
- local length = 3
- local map = createMap()
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- local struct = createStructure({x, y}, 3, button, map, 10)
- map:draw()
- end
Advertisement
Add Comment
Please, Sign In to add comment