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

5


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


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



[Please log in to post a comment]