Skip to content
Will Blanton edited this page Sep 13, 2019 · 6 revisions

Added functionality for Arrays!

This is an Extension! Learn about using Extensions here!

Examples:

["0", "1", "2", "3"].strings_to_ints(); // [0, 1, 2, 3]
["apple", "orange", "banana"].contains("apple"); // true
[0, 1, 2, 3].last(); // 3
[0, 1, 2, 3].get_random(); // 2
[0, 1, 2, 3].shuffle(); // [2, 1, 3, 0]
[0, 1].merge([2, 3]); // [0, 1, 2, 3]
[[0, 1], [2, 3]].flatten(); // [0, 1, 2, 3]
[0, 1, 0, 0].flood_fill_1D(2, 8); // [0, 1, 8, 8]

Flood fill a 2D Array:

[
	[0, 0, 1, 0],	// [8, 8, 1, 0]
	[0, 0, 1, 0],	// [8, 8, 1, 0]
	[1, 1, 1, 0],	// [1, 1, 1, 0]
	[0, 0, 0, 0]	// [0, 0, 0, 0]
].flood_fill_2D(1, 1, 8);

Generate a heatmap from a 2D Array:

[
	[0, 0, 1, 0],	// [1, 2, 0, 0]
	[0, 0, 1, 0],	// [2, 3, 0, 0]
	[1, 1, 1, 0],	// [0, 0, 0, 0]
	[0, 0, 0, 0]	// [0, 0, 0, 0]
].heat_map(1, 1);

Use A* to find a path through a 2D Array:

var path = [
	[1, 1, 1, 1, 1, 1, 1, 1],
	[1, 0, 0, 0, 0, 0, 0, 1],
	[1, 1, 1, 1, 1, 0, 0, 1],
	[1, 0, 0, 0, 0, 0, 0, 1],
	[1, 0, 1, 1, 1, 1, 1, 1],
	[1, 0, 1, 0, 0, 0, 0, 1],
	[1, 0, 0, 0, 1, 0, 0, 1],
	[1, 1, 1, 1, 1, 1, 1, 1]
].a_star({
	start: { x: 1, y: 1 },
	end: { x: 6, y: 6 },
	passable: [0],
	diagonal: false
});
trace(path);

Output:

[
	[2,1],
	[3,1],
	[4,1],
	[5,1],
	[5,2],
	[5,3],
	[4,3],
	[3,3],
	[2,3],
	[1,3],
	[1,4],
	[1,5],
	[1,6],
	[2,6],
	[3,6],
	[3,5],
	[4,5],
	[5,5],
	[5,6],
	[6,6]
]
Clone this wiki locally