I plan on making a simple rpg, so one of the first things I have to do is create a system to lay out tiles. I've been playing around with arrays. Here is a small demo that takes an array with number values and then outputs a 'symbol' in it's place. Eventually I'll have to change that to a 'tile'. I find it very helpful to break bigger problems down into smaller ones, so this is merely a textual example, but I'll eventually go to blocks, and then actual graphics tiles.
Update:
The code is quite ugly right now and I'll refactor soon, but I finally got it working. What is it exactly? It's basically a program that outputs tiles based upon the array you put in. each number in the array corresponds to a different tile color. I'll eventually replace the colored tiles with graphics.
http://codepen.io/kevm3/full/EaLOZa/
Code:
//Input data
var a =
[[1, 2, 3, 3, 1],
[1, 1, 1, 2, 1],
[1, 3, 2, 1, 2]];
//Create representation map array
var map = [[], [], []];
for(i=0; i<3; i++)
{
for(j=0; j<a[i].length; j++)
{
if(a[i][j] === 1)
{
map[i].push("X");
}
else if(a[i][j] === 2)
{
map[i].push("0");
} else if(a[i][j] === 3)
{
map[i].push("#");
}
} //end inner for
}
console.log(map[0]);
console.log(map[1]);
console.log(map[2]);
Update:
The code is quite ugly right now and I'll refactor soon, but I finally got it working. What is it exactly? It's basically a program that outputs tiles based upon the array you put in. each number in the array corresponds to a different tile color. I'll eventually replace the colored tiles with graphics.
http://codepen.io/kevm3/full/EaLOZa/
Last edited: