Esempio n. 1
0
 /// <summary>
 /// Sets the sprite's next move.
 /// Used only by MovementAIs.
 /// </summary>
 /// <param name="direction"></param>
 /// <param name="map"></param>
 /// <seealso cref="PlanAction"/>
 public void PlanMove(Dir direction, Map map)
 {
     nextMove = Dir.None;
     if (moving == Dir.None && direction != Dir.None) {
         facing = direction;
         graphic.SetDirection(direction);
         graphic.SetState("still");
     }
     switch (direction) {
         case Dir.Up:
             if (map.IsPassable(x, y - 1, layer)) {
                 nextMove = Dir.Up;
             }
             else if (moving == Dir.None) {
                 map.OnCollide(x, y - 1, layer, this);
             }
             break;
         case Dir.Down:
             if (map.IsPassable(x, y + 1, layer)) {
                 nextMove = Dir.Down;
             }
             else if (moving == Dir.None) {
                 map.OnCollide(x, y + 1, layer, this);
             }
             break;
         case Dir.Left:
             if (map.IsPassable(x - 1, y, layer)) {
                 nextMove = Dir.Left;
             }
             else if (moving == Dir.None) {
                 map.OnCollide(x - 1, y, layer, this);
             }
             break;
         case Dir.Right:
             if (map.IsPassable(x + 1, y, layer)) {
                 nextMove = Dir.Right;
             }
             else if (moving == Dir.None) {
                 map.OnCollide(x + 1, y, layer, this);
             }
             break;
     }
 }