//given a direction (1234->NESW), can it move. //this recurses inward by 1, cause you can push 1 zencritter, but it cant push a third bool CanMove(int direction, int isPushed) { if (direction == 1) { if (board.ContainsTile(x, y + 2) && board.ContainsTile(x + 1, y + 2)) { //needs to contain the tiles to begin with if (!board.ContainsCritter(x - 1, y + 2) && !board.ContainsCritter(x + 1, y + 2)) { //needs to not have diagonals occupied if (!board.ContainsCritter(x, y + 2)) { //if no critters in the way, lifes simple. return(true); } else if (isPushed == 0) { //otherwise, if this is the first time we pushing CharacterData d = board.GetCritter(x, y + 2); if (d.touchID == -1 && d.CanMove(1, 1)) { //if we're not touching the blocking critter AND it too can move d.MoveUp(true); d.UpdateVisuals(); d.ResetPendingPosition(); return(true); //gorgeous. } } } pendingY = y; } } if (direction == 2) { if (board.ContainsTile(x + 2, y) && board.ContainsTile(x + 2, y + 1)) { if (!board.ContainsCritter(x + 2, y - 1) && !board.ContainsCritter(x + 2, y + 1)) { if (!board.ContainsCritter(x + 2, y)) { return(true); } else if (isPushed == 0) { CharacterData d = board.GetCritter(x + 2, y); if (d.touchID == -1 && d.CanMove(2, 1)) { d.MoveRight(true); d.UpdateVisuals(); d.ResetPendingPosition(); return(true); } } } pendingX = x; } } if (direction == 3) { if (board.ContainsTile(x, y - 1) && board.ContainsTile(x + 1, y - 1)) { if (!board.ContainsCritter(x - 1, y - 2) && !board.ContainsCritter(x + 1, y - 2)) { if (!board.ContainsCritter(x, y - 2)) { return(true); } else if (isPushed == 0) { CharacterData d = board.GetCritter(x, y - 2); if (d.touchID == -1 && d.CanMove(3, 1)) { d.MoveDown(true); d.UpdateVisuals(); d.ResetPendingPosition(); return(true); } } } pendingY = y; } } if (direction == 4) { if (board.ContainsTile(x - 1, y) && board.ContainsTile(x - 1, y + 1)) { if (!board.ContainsCritter(x - 2, y - 1) && !board.ContainsCritter(x - 2, y + 1)) { if (!board.ContainsCritter(x - 2, y)) { return(true); } else if (isPushed == 0) { CharacterData d = board.GetCritter(x - 2, y); if (d.touchID == -1 && d.CanMove(4, 1)) { d.MoveLeft(true); d.UpdateVisuals(); d.ResetPendingPosition(); return(true); } } } pendingX = x; } } return(false); }