Tilebased collision detection

Hey guys!

I’m trying to create a tilebased RPG game where i use a 2D array to lay out the tiles and set the right frame.

var tileSize:int = 40;
var mapHeight:int = 5;
var mapWidth:int = 5;

var myMap:Array =
[
[1,1,1,1,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,0,0,0,1],
[1,1,1,1,1]
];

for (var i:int=0; i<mapHeight; i++)
{
    for (var u:int=0; u<mapWidth; u++)
    {
        var tile:Tile = new Tile();
        tile.gotoAndStop(myMap*[u]+1);
        tile.x = tileSize * u;
        tile.y = tileSize * i;
        addChild(tile);
    }
}

To move the character i’ve made it so that when you press a key he will move the size of one tile in that direction by animation, and when the animation hits the last frame, it’ll run a code that puts the character back to frame one aswell as updating his actual position in actionscript. This gives an illusion of moving one tile and stopping.

However, i’ve done this before but i can’t remember how to make the character detect wheter the next tile is a wall or not. I remember making my own coordinates for the character, so one tile would be one coordinate, and i would run a check to see if for example playerXPosition+1 = 1 or 0 in the 2D array. where 1 would be a wall and 0 would be an open tile. I just can’t remember how i did that…

I was hoping someone could help me out here :slight_smile: