I'm making a very simple Pac - Man game and have everything working except for a small bug. I'm using a grid based system where Pac - Man can only move if the tiles in front of him are open. Everything works fine up until you make a turn. If you turn before Pac - Man is in the right tile, his location gets rounded out and he ends up moving through the wall. I've added my code and an image of what happens.
Player.as class
package
{
import flash.display.MovieClip;
import flash.display.InteractiveObject;
public class Player extends MovieClip
{
var speed:int;
var playerX:int;
var playerY:int;
var wall:Wall = new Wall ;
var currentKey:String;
var playerRX:int;
var playerRY:int;
public function Player()
{
}
public function movePlayer(lastKey:String, levelArray:Array)
{
trace(currentKey, lastKey)
if(currentKey == lastKey)
{
if (x % wall.width >= speed)
{
playerRX = 1;
}
else
{
playerRX = 0;
}
if(y % wall.width >= speed)
{
playerRY = 1
}
else
{
playerRY = 0;
}
}
currentKey = lastKey;
speed = 5;
playerX = x / 15;
playerY = y / 15;
var leftCollision = playerX + playerRX;
var topCollision = playerY + playerRY;
if (lastKey == "left")
{
if (levelArray[leftCollision - 1][playerY] != 1 && levelArray[leftCollision - 1][playerY + 1] != 1 && levelArray[leftCollision - 1][playerY + 2] != 1)
{
x -= speed;
}
}
if (lastKey == "right")
{
if (levelArray[playerX + 3][playerY] != 1 && levelArray[playerX + 3][playerY + 1] != 1 && levelArray[playerX + 3][playerY + 2] != 1)
{
x += speed;
}
}
if (lastKey == "up")
{
if (levelArray[playerX][topCollision - 1] != 1 && levelArray[playerX + 1][topCollision - 1] != 1 && levelArray[playerX + 2][topCollision - 1] != 1)
{
y -= speed;
}
}
if (lastKey == "down")
{
if (levelArray[playerX][playerY + 3] != 1 && levelArray[playerX + 1][playerY + 3] != 1 && levelArray[playerX + 2][playerY + 3] != 1)
{
y += speed;
}
}
}
}
}

Currently Pac - Man doesn't move from tile to tile, Pac - Man is 45x45 and tiles are 15x15. Should i change it so he does move from tile to tile and tween it to make it look like hes transitioning?