xxxxxxxxxx
76
var img=[];
var row=0;
var col=0;
var numTiles=100;
var tileWidth=40;
var tileHeight=40;
var board=[]; // Array of board tile types
function preload()
{
//img = loadImage('./Textures/wall.webp');
img[0]= loadImage('./Textures/air.webp');
img[1]= loadImage('./Sprites/fwd.webp');
img[2]= loadImage('./Textures/wall.webp');
img[3]= loadImage('./Textures/crate.webp');
}
function setup() {
createCanvas(400, 400);
for(var i=0; i<100; i++)
{
board.push(0);
}
}
function draw() {
//background('skyblue');
var indx=0;
for(var i=0; i<10; i++)
{
row=i;
for(var j=0; j<10; j++)
{
col=j;
image(img[board[indx]], row*40,col*40, tileWidth, tileHeight);
indx++;
}
}
}
function mousePressed()
{
if((mouseY<height) && (mouseX<width))
{
change=ind(floor(mouseX/40), floor(mouseY/40));
if(board[change]<3)
{
board[change]++;
}
else
{
board[change]=0;
}
}
}
function ind(r, c) // Returns Array index given a row/ col
{
var arrind=0;
arrind=r * (10) + c;
return arrind;
}