Pattern-based Generator |
![]() ![]() « Citoyen » 1446241020000
| 0 | ||
Pattern Based Generator Just a note guys : 450 is the block limit , so the block height and width should not be less than 15 , and please don't make a Full block of rectangles, it WILL crash the map, or else edit the map_width and map_height manually (40 or 50) so we all can play TFM peacfully Description : This is pattern-based generator which simply takes few manually made patterns You draw when you run this game and end up with a (not so) randomly generated map Examples : 0s, 1s and 2s (The Zero must be obeyed.) manually written in the pattrns table. ![]() ![]() ![]() Instructions : blockwidth = 25 blockheight = 15 map_width = math.floor( 800 /blockwidth) map_height = math.floor( 400 /blockheight) blockwidth is how wide is a single block ( in this case 25 pixels ) blockheight is how tall is a single block(in this case 15 pixels, preferred to be as equal as the width) map_width is how many blocks are there horizontally, in this case it's the floor of 800 pxs ( the map's width ) divided by the block width map_height is how many blocks are there vertically, in this case it's the floor of 400 pxs ( the map's height) divided by the block height You can also edit the wood block and change it's properties to make it for ex a rectangle. The Script is found here. namedd = nil blockwidth = 25 blockheight = 15 map_width = math.floor(1600/blockwidth) map_height = math.floor(400/blockheight) print(map_height) print(map_width) pattrns = { } wood = { type = 12, width = 40, height = 40, color = 0x012346, 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 if ids >=420 then break; end 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 ids = 1 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, 40, nil, nil, 0.3, false) id = id + 1 ui.addTextArea(id, "<p align='center'>RELOAD</p>", nil, 5, 50+blockheight, 60, blockheight+7, 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 pl = false 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 pl = true else new_pat[y][x] = 0 end end end if not pl then return {} 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 return 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 return end end end wid = wid + 1 end if inside(50+blockwidth , __ly , blockwidth*wid , 40 , x , y) then selection = false print("End of Selection") return elseif inside(5, 50+blockheight, 60, blockheight+7, x, y) then load_up(pattrns) return end end end Dernière modification le 1446403440000 |
![]() ![]() « Citoyen » 1446241080000
| 0 | ||
0 | ||
Awesome game right there! C: |
![]() ![]() « Citoyen » 1446385440000
| 0 | ||
UPDATE !! [Version 0.2] : • You don't have to draw manually in forms of 1s and 0s now • The map is 1600 pixels wide now. • Now you Start off with an empty map • Draw the first time, press Done, Draw a second time and press done, now you have 2 patterns in the map Draw a third time, and now you have more structures in the map -You can keep drawing drawing forever though- To-do list • Players Simultaneously drawing • Map the map 800 px tall • More than 1 ground type The new code ![]() ![]() Subho a dit : Thanks ^^ |
![]() ![]() « Citoyen » 1446386340000
| 0 | ||
That's really cool |
![]() ![]() « Consul » 1446389700000
| 0 | ||
Will done, it is COOL! |
0 | ||
whoa cool |
![]() ![]() « Citoyen » 1446399840000
| 0 | ||
QUICK UPDATE version 0.21 - Code Ground limit is 430, why ? ehm, so that TFM does not crash. Me and the 3 faces. ![]() Just a note guys : 450 is the block limit , so the block height and width should not be less than 15 , and please don't make a Full block of rectangles, it WILL crash the map Dernière modification le 1446403260000 |
![]() ![]() « Consul » 1446904560000
| 0 | ||
Nice generator, Abdeltif! #RIPLeCartes #RIPOldTopic |
![]() ![]() « Citoyen » 1447778580000
| 0 | ||
how do you put it in.... |
![]() ![]() « Citoyen » 1448128200000
| 0 | ||
myhappyness a dit : when you're in your tribe house write /lua then Select everything in there then delete it (backspace) then copy this code into that window then press submit Voilà ! :D |