Tile game quandry

Hello Kirupa world!

I’ve built a 2D array tile engine in js and html, and I can’t figure out why placement of blocks seems to arbitrarily effect the collision.

You’ll notice in the broken version the vertical tiles’ collision reacts as though the blocks were placed horizontally.

working:
http://cp-graphics.com/gallery/web/js_tileengine/tile_working.html

broken:
http://cp-graphics.com/gallery/web/js_tileengine/tile_error.html

I’m assuming it’s in the player move code…



function keyListener(e)
{
    if (!e)
    {
        e = window.event;
    }
    
    if (e.keyCode == 37)
    {
        charTileX -= 1;
        //document.getElementById('output').innerHTML = gameBoard[charTileX][charTileY];
        if (gameBoard[charTileX][charTileY] != 1)
        {
            moveChar(-32, 0);
        }
        else
        {
            charTileX += 1;
        }
    }
    else if (e.keyCode == 38)
    {
        charTileY -= 1;
        //document.getElementById('output').innerHTML = gameBoard[charTileX][charTileY];
        if (gameBoard[charTileX][charTileY] != 1)
        {
            moveChar(0, -32);
        }
        else
        {
            charTileY += 1;
        }
    }
    else if (e.keyCode == 39)
    {
        charTileX += 1;
        //document.getElementById('output').innerHTML = gameBoard[charTileX][charTileY];
        if (gameBoard[charTileX][charTileY] != 1)
        {
            moveChar(32, 0);
        }
        else
        {
            charTileX -= 1;
        }
    }
    else if (e.keyCode == 40)
    {
        charTileY += 1;
        //document.getElementById('output').innerHTML = gameBoard[charTileX][charTileY];
        if (gameBoard[charTileX][charTileY] != 1)
        {
            moveChar(0, 32);
        }
        else
        {
            charTileY -= 1;
        }
    }
    
}

function playerControlInit()
{
    document.onkeydown = keyListener;
}



Thanks!
Chris