private void player_ReadyToMove(object sender, EventArgs e)
        {
            var nextSection = this.player.CurrentLocation.Get(this.nextDirection);

            if (nextSection != null && nextSection.Allowed)
            {
                this.lastDirection = nextDirection;
                this.player.GoTo(nextDirection);
            }
            else
            {
                this.player.GoTo(this.lastDirection);
            }
        }
 public MazeSection Get(EnumDirections d)
 {
     switch (d)
     {
         case EnumDirections.North:
             return this.N;
         case EnumDirections.South:
             return this.S;
         case EnumDirections.East:
             return this.E;
         case EnumDirections.West:
             return this.W;
         default:
             return null;
     }
 }
        public override void Update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Left))
            {
                this.nextDirection = EnumDirections.West;
            }
            else if (state.IsKeyDown(Keys.Right))
            {
                this.nextDirection = EnumDirections.East;
            }
            else if (state.IsKeyDown(Keys.Up))
            {
                this.nextDirection = EnumDirections.North;
            }
            else if (state.IsKeyDown(Keys.Down))
            {
                this.nextDirection = EnumDirections.South;
            }
        }
        private void MoveTargetingCursor(EnumDirections dir)
        {
            switch (dir)
            {
            case EnumDirections.North:
                _targetedCoords.Y--;
                break;

            case EnumDirections.South:
                _targetedCoords.Y++;
                break;

            case EnumDirections.West:
                _targetedCoords.X--;
                break;

            case EnumDirections.East:
                _targetedCoords.X++;
                break;
            }

            _gameStateHelper.SetVar("TargetingData", new TargetingData(PlotCourse(_gameStateHelper.GetVar <ActorEntity>("MainEntity"), _startingCoords, _targetedCoords), _targetedCoords));
        }
Exemple #5
0
 public MoveTargetingCursorEvent(EnumDirections dir)
 {
     EventParams = new List <object>();
     EventParams.Add(dir);
 }
Exemple #6
0
        public virtual void GoTo(EnumDirections d)
        {
            MazeSection next = null;

            if (this.CurrentLocation != null)
            {
                next = this.CurrentLocation.Get(d);

                if (next != null && next.Allowed)
                {
                    this.NextLocation = next;

                    if (d == EnumDirections.West || d == EnumDirections.East)
                        this.FacingDirection = d;

                    this.animation.Start(d, Constants.DEFAULT_BLOCK_WIDTH);
                }
            }
        }
Exemple #7
0
 // Use this for initialization
 void Start()
 {
     dir           = new EnumDirections();
     moveDirection = Random.Range(-2.0f, 2.0f);
 }
        protected void ChaseSection(MazeSection destination)
        {
            //Localizações dos elementos
            var currLocation = this.Ghost.CurrentLocation;
            var currEndLocation = destination;
            var prevLocation = this.Ghost.PreviousLocation;

            //Essa é a seção inicial,
            PathFindingNode currNode = new PathFindingNode();
            currNode.h = 0;
            currNode.g = 0;
            currNode.parent = null;
            currNode.location = currLocation;

            List<PathFindingNode> closedSet = new List<PathFindingNode>();
            List<PathFindingNode> openSet = new List<PathFindingNode>();

            closedSet.Add(currNode);

            do
            {
                //Percorrendo as opções de caminho que temos
                List<MazeSection> opcoes = new List<MazeSection> { currLocation.W, currLocation.N, currLocation.E, currLocation.S };

                foreach (var o in opcoes)
                {

                    if (o != null)
                    {

                        //A seção precisa estar ativa e não ser a seção anteriormente visitada
                        if (o.Allowed && (prevLocation == null || o.ID != prevLocation.ID))
                        {
                            //Seção não deve existir na lista de seções fechadas
                            if (!closedSet.Any(x => x.location.ID == o.ID))
                            {
                                //...nem na lista de seções abertas
                                if (!openSet.Any(x => x.location.ID == o.ID))
                                {

                                    PathFindingNode node = new PathFindingNode();
                                    node.location = o;
                                    node.parent = currNode;
                                    node.h = this.Heuristics(node.location, currEndLocation); //heuristica manhattan

                                    //Ok, esse nó participará do teste
                                    openSet.Add(node);
                                }
                            }
                        }
                    }
                }

                if (openSet.Count == 0)
                {
                    break;
                }

                //Procuramos o melhor nó localizado (custo)
                var minNode = openSet[0];

                foreach (var m in openSet)
                {
                    if (m.h < minNode.h)
                    {
                        minNode = m;
                    }
                }

                currNode = minNode;
                currLocation = currNode.location;

                //Removendo da lista de nós abertos para pesquisa e incluíndo na lista de nós proibidos
                openSet.Remove(minNode);
                closedSet.Add(currNode);

            } while (currNode.location.ID != currEndLocation.ID);

            if (currNode.location.ID == currEndLocation.ID)
            {
                ///*

                LinkedList<PathFindingNode> path = new LinkedList<PathFindingNode>();
                PathFindingNode lastPathNode = currNode;
                MazeSection nextSectionToMove = null;
                MazeSection mySection = this.Ghost.CurrentLocation;

                while (lastPathNode != null)
                {
                    path.AddFirst(lastPathNode);
                    lastPathNode = lastPathNode.parent;
                }

                nextSectionToMove = path.Count > 1 ? path.First.Next.Value.location : path.First.Value.location;

                if (nextSectionToMove.ID == mySection.N.ID)
                {
                    this.nextDirection = EnumDirections.North;
                }
                else if (nextSectionToMove == mySection.S)
                {
                    this.nextDirection = EnumDirections.South;
                }
                else if (nextSectionToMove == mySection.E)
                {
                    this.nextDirection = EnumDirections.East;
                }
                else if (nextSectionToMove == mySection.W)
                {
                    this.nextDirection = EnumDirections.West;
                }

                this.Ghost.GoTo(this.nextDirection);
                //*/
            }
        }