/// <summary> /// /// </summary> /// <param name="spot"></param> /// <param name="pea"></param> public JumpEventArgs(DataJumpSpot spot, DataPea pea, Int32 points) : base() { this.Spot = spot; this.Pea = pea; this.Points = points; }
/// <summary> /// Creates a new flag sprite /// </summary> /// <param name="layer"></param> /// <param name="source"></param> public SpriteFlag(SceneLayer layer, DataJumpSpot source) : base(layer, "Graphics/Flag-Pole") { _source = source; //if (source.Placement == DataJumpSpot.Location.Left) // this.Effects = SpriteEffects.FlipHorizontally; }
/// <summary> /// Finds a path to a jumping spot /// </summary> /// <param name="spot">Spot to jump</param> /// <param name="path">Path</param> /// <returns>Has found</returns> private Boolean FindPath(DataPea pea, DataJumpSpot spot, out Queue <MoveNode> path) { path = new Queue <MoveNode>(); var startNode = new Node <MoveNode>() { Value = GetSnapshot(pea).PreviousNode }; //.Action == MoveNode.Type.None ? new Node<MoveNode>() { Value = new MoveNode() { Position = pea.GridPosition, Action = MoveNode.Type.Walk} } : ; var goalNode = new Node <MoveNode>() { Value = new MoveNode() { Position = new Point(spot.Source.X, spot.Source.Y - 1), Action = MoveNode.Type.Walk } }; var domain = new List <Node <MoveNode> >(); domain.Add(startNode); // Notes: Normally you would build the domain from ALL the walkable places and // have the neighbourghing function run just once for each node. Because that // function is complex, I added it dynamically (runs on reach node). This changes // some of the behavior of A*. Don't forget that... // Debuging Solver <MoveNode> .SolverProgress += new EventHandler <SolverResultEventArgs <MoveNode> >(PeaController_SolverProgress); // Get a path var result = Solver <MoveNode> .Solve( startNode, goalNode, domain, CreateMoveNodesFrom, // This was initialially not in the solver n => Math.Abs(n.Value.Position.X - goalNode.Value.Position.X) + Math.Abs(n.Value.Position.Y - goalNode.Value.Position.Y), n => Math.Abs(n.Value.Position.X - startNode.Value.Position.X) + Math.Abs(n.Value.Position.Y - startNode.Value.Position.X), (n, m) => n.Value.Equals(m.Value), #if DEBUG true #else false #endif ); if (result == null) { path = null; return(false); } foreach (Node <MoveNode> node in result) { path.Enqueue(node.Value); } return(true); }
/// <summary> /// Is reachable from spot /// </summary> /// <param name="spot"></param> /// <returns></returns> private Boolean IsReachable(DataPea pea, DataJumpSpot spot, out Queue <MoveNode> path) { // Question: Is it worth it to save paths found (need re-evaluation when grid // changes). Should test that later and work from there. if (!FindPath(pea, spot, out path)) { return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="spot"></param> /// <param name="pea"></param> public JumpEventArgs(DataJumpSpot spot, DataPea pea) : base() { this.Spot = spot; this.Pea = pea; }
/// <summary> /// Is still a valid jumpspot /// </summary> /// <param name="dataJumpSpot"></param> /// <returns></returns> protected Boolean IsValid(DataJumpSpot dataJumpSpot) { return((dataJumpSpot.Placement == DataJumpSpot.Location.Left ? dataJumpSpot == dataJumpSpot.Source.JumpLeft : dataJumpSpot == dataJumpSpot.Source.JumpRight) || IsJumpSpot(dataJumpSpot.Source, dataJumpSpot.Placement)); }