Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namedd = nil
- blockwidth = 25
- blockheight = 15
- map_width = math.floor( 1600 /blockwidth)
- map_height = math.floor( 400 /blockheight)
- pattrns = {
- }
- wood = {
- type = 0,
- width = 40,
- height = 40,
- foreground = false,
- friction = 0.3,
- restitution = 0.2,
- angle = 0,
- miceCollision = true,
- groundCollision = true,
- dynamic = false,
- fixedRotation = false,
- mass = 0,
- linearDamping = 0,
- angularDamping = 0,
- }
- xml = [[<C><P L="1600" H="400"/><Z><S><S L="1700" o="324aa0" H="28" X="800" Y="413" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D /><O /></Z></C>]]
- -- If You will edit the below, EDIT IT WITH CARE. ;)
- to_load = {}
- input = {}
- upd = {}
- inp_id_start = 0
- inp_id_end = 0
- id = 1
- ids = 1
- selection = false
- pvs = false
- tfm.exec.disableAutoNewGame (true)
- function new_map( height, width, patterns, seed)
- local width = width
- local height = height
- local diverse = diverse
- local pnum = #patterns
- local seed = seed or tonumber(math.random(0,99999)..math.random(0,99999))
- local tiles = {}
- local used = {}
- if #patterns==0 then
- return {}
- end
- math.randomseed(seed)
- local function pattern(pattern, x, y)
- for Y,v1 in ipairs(pattern) do
- for X,v in ipairs(v1) do
- if X+x-1>height then
- return false
- elseif Y+y-1>width then
- return false
- end
- end
- end
- for Y,v1 in ipairs(pattern) do
- for X,v in ipairs(v1) do
- if type(tiles[X+x]) == "table" then
- tiles[X+x-1][Y+y-1] = v
- used[X+x-1][Y+y-1] = true
- end
- end
- end
- end
- for x = 0, height do
- tiles[x] = {}
- used[x] = {}
- for y = 0, width do
- used[x][y] = false
- end
- end
- for y = 0, width do
- for x = 0, height do
- if not used[x][y] then
- local pat = math.random(1,pnum)
- pattern(patterns[pat], x, y)
- end
- end
- end
- math.randomseed(tonumber(string.reverse(seed)))
- return tiles
- end
- function load_map(tiles, x, y, w, h, prot)
- local prot = prot or wood
- local x = x or 0
- local y = y or 0
- local tiles = type(tiles)=="table" and tiles or error("table expected at #1, got "..type(tiles))
- local w = w or blockwidth
- local h = h or blockheight
- if #tiles==0 then return end
- prot.width = w
- prot.height = h
- for x,gab in pairs(tiles) do
- for y,val in pairs(gab) do
- if val ~= 0 then
- local w2 = w/2
- local h2 = h/2
- local cx = x*w + w2
- local cy = y*h + h2
- tfm.exec.addPhysicObject(ids , cx, cy, prot)
- tfm.exec.displayParticle(3, cx, cy, math.random(-1.5,1.5)*math.random(), math.random(-1,1)*math.random(), 0, 0, nil)
- ids = ids + 1
- end
- end
- if (x+1)%6 == 0 then
- coroutine.yield(x, y)
- end
- end
- end
- function add_patterns(nh, nv, np)
- selection = true
- local w = nh
- local h = nv
- __ly = 1
- local vac = "o"
- inp_id_start = id
- for _x=1,w do
- input[_x] = {}
- upd[_x] = {}
- end
- for _y=1,h do
- for _x=1,w do
- id = id + 1
- input[_x][_y] = false
- upd[_x][_y] = id
- ui.addTextArea(id, "", nil, 50+_x*blockwidth, 50+_y*blockheight, blockwidth-7, blockheight-7, nil, nil, 0.3, false)
- end
- __ly = 50+(_y+1)*blockheight
- end
- id = id + 1
- ui.addTextArea(id, "<p align='center'>DONE</p>", nil, 50+blockwidth, __ly, blockwidth*w-7, blockheight, nil, nil, 0.3, false)
- inp_id_end = id
- end
- function inside(x,y,w,h,gx,gy)
- if gx<=x+w and gx>=x and gy<=y+h and gy>=y then
- return true
- else
- return false
- end
- end
- function load_up(__patts)
- tfm.exec.newGame(xml)
- local map = new_map(map_width,map_height,__patts)
- to_load[1] = {co = coroutine.create(load_map), map = map}
- coroutine.resume(to_load[1].co, to_load[1].map, 0, 0, blockwidth, blockheight,wood)
- end
- function to_pattern(tbl)
- local tbl = tbl
- local new_pat = {}
- for x, oly in pairs(tbl) do
- for y in pairs(oly) do
- new_pat[y] = {}
- end
- end
- for x, oly in pairs(tbl) do
- for y,l in pairs(oly) do
- if l == true then
- new_pat[y][x] = 1
- else
- new_pat[y][x] = 0
- end
- end
- end
- return new_pat
- end
- ----------------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------
- -----------------------------------------------------CALLS AND EVENTS-------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------------
- add_patterns(7, 7)
- load_up(pattrns)
- function eventLoop(np, lp)
- local to_remove = {}
- if selection and not pvs then
- pvs = true
- elseif not selection and pvs then
- for p=inp_id_start,inp_id_end do
- ui.removeTextArea(p)
- end
- pattrns[#pattrns+1] = to_pattern(input)
- pvs = false
- load_up(pattrns)
- add_patterns(7,7)
- end
- for k,v in pairs(to_load) do
- coroutine.resume(v.co, v.map, 0, 0, blockwidth, blockheight, wood)
- if coroutine.status(v.co) == "dead" then
- to_remove[k] = true
- end
- end
- for k,v in pairs(to_remove) do
- if v == true then
- to_load[k] = nil
- to_remove[k] = false
- end
- end
- end
- if namedd == nil then
- for k,v in pairs(tfm.get.room.playerList) do
- system.bindMouse(k, true)
- end
- else
- system.bindMouse(namedd)
- end
- --function eventAreaCallback to be added
- function eventMouse(name, x, y)
- local wid = 0
- if selection then
- for ix,vl in pairs(input) do
- for iy,val in pairs(vl) do
- if inside(50+ix*blockwidth, 50+iy*blockheight, blockwidth-2, blockheight-2, x, y) then
- if not input[ix][iy] then
- ui.removeTextArea(upd[ix][iy])
- ui.addTextArea(upd[ix][iy], "", nil, 50+ix*blockwidth, 50+iy*blockheight, blockwidth-7, blockheight-7, 0xBA7BCD, 0xBA7BCD+300,0, false)
- input[ix][iy] = true
- elseif input[ix][iy] then
- ui.removeTextArea(upd[ix][iy])
- ui.addTextArea(upd[ix][iy], "", nil, 50+ix*blockwidth, 50+iy*blockheight, blockwidth-7, blockheight-7, nil,nil, 0.3, false)
- input[ix][iy] = false
- end
- print("click")
- else
- end
- end
- wid = wid + 1
- end
- if inside(50+blockwidth , __ly , blockwidth*wid , blockheight , x , y) then
- selection = false
- print("End of Selection")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement