# Tile game quandry

**URL:** <https://forum.kirupa.com/t/tile-game-quandry/324560>\
**Category:** Uncategorized\
**Created:** [August 26, 2011, 5:40pm UTC](https://forum.kirupa.com/t/tile-game-quandry/324560 "2011-08-26T17:40:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![c\_concat\_p](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@c\_concat\_p](https://forum.kirupa.com/u/c_concat_p)\
**Post date:** [August 26, 2011, 5:40pm UTC](https://forum.kirupa.com/t/tile-game-quandry/324560/1 "2011-08-26T17:40:26Z")

</div>

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](http://cp-graphics.com/gallery/web/js_tileengine/tile_working.html)

broken:  
[http://cp-graphics.com/gallery/web/js\_tileengine/tile\_error.html](http://cp-graphics.com/gallery/web/js_tileengine/tile_error.html)

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

```php

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
