some thoughts.
boolean afuera(int px, int py, int dir)
{
switch (dir)
{
case 1: return (px < 1) || (py > 6); // remove the math
break;
....
}
return false; // ????
}
The switch statement has no default, which implies that dir = {1,2,3,4} ==> dir could be a 1 byte datatype?
you need to add a return true/false in the end of the function to make the code robust.