Log In  

Cart #25738 | 2016-07-22 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

Hi

here is my next cartridge which is combination of my previous Cellular automata class and Marching squares technique for generate procedural platform or top-down levels.

Control:
[z] tileset type #1
[x] tileset type #2
[arrows] scroll map

Note: source code is't optimized for tokens for now

AndyGFX

P#25739 2016-07-22 18:05 ( Edited 2016-07-25 01:45)

Modification for tokens cont:

Change getmarchingsquareat function

from

function getmarchingsquareat(x,y)

    local tl = cave:map(x-1,y-1) or 0   
    local tr = cave:map(x,y-1) or 0 
    local bl = cave:map(x-1,y) or 0
    local br = cave:map(x,y) or 0 

    local mm = tl..tr..bl..br

     for mid=1,#ms do
        if (mm==ms[mid].matrix) return ms[mid].tile
     end 

     if (m==1) return 2 

    return 1
end

to

function getmarchingsquareat(x,y)

    local tl = cave:map(x-1,y-1) or 0   
    local tr = cave:map(x,y-1) or 0 
    local bl = cave:map(x-1,y) or 0
    local br = cave:map(x,y) or 0 

    return (16 + (tl + shl(tr,1) + shl(br,2) + shl(bl,3))+off)

end

and remove ms array definition.

ms={}
ms[01] = {matrix = "0000", tile = 16}
...
ms[16] = {matrix = "1111", tile = 31}

Result -188 tokes.

AndyGFX

P#25808 2016-07-24 04:15 ( Edited 2016-07-24 08:16)

I made extensive use of cellular automata and marching squares in my game if you're interested in taking a look at it.

P#25839 2016-07-24 21:45 ( Edited 2016-07-25 01:45)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-01-28 01:12:26 | 0.005s | Q:12