コード例 #1
0
ファイル: Move.cs プロジェクト: milesgray/resatiate
        private ITile CalculateMovement(MoveTask moveTask)
        {
            // isActive is based off of the previous move - true if the move succeeded
            if (moveTask.isActive)
                // get the next tile to move to on the path
                return moveTask.PopPath();
            else
            {
                // since the previous move did not succeed, recalculate the path
                moveTask.CalculatePath();

                // get the next tile to move to on the new path
                return moveTask.PopPath();
            }
        }
コード例 #2
0
        private bool Move()
        {
            bool result = false;

            if (this.rand.Next(1, 100) > 20)
            {
                if (this.moveTask.isEnabled)
                {
                    // pops off the next tile if it can
                    // - will attempt to recalculate 5 times before giving up
                    ITile tile = CalculateMovement();

                    // MoveTo will return false when the entity doesn't move (end of path)
                    moveTask.isActive = MoveTo(tile);

                    var coords = tile.ToCoordinates();
                    //var memory =  this.Memory[coords.X, coords.Y];

                   // memory.Visited = true;
                   // memory.Intensity = 100;
                }
                else
                {
                    moveTask = new MoveTask(this, ChooseDestination());

                    // gemerates a path and sets isEnabled to true
                    this.moveTask.Initialize();
                }
            }

            return result;
        }
コード例 #3
0
ファイル: Move.cs プロジェクト: milesgray/resatiate
        /// <summary>
        /// Move to another tile, potentially
        /// </summary>
        /// <returns>Did it move?</returns>
        private bool Move()
        {
            bool result = false;
            // MoveChance = 100 makes it move every frame
            if (this.rand.Next(1, 100) <= Chance)
            {
                // isEnabled means that it hasn't given up on this destination yet
                if (this.moveTask.IfNotNull(x => x.isEnabled))
                {
                    // pops off the next tile if it can
                    // - will attempt to recalculate 5 times before giving up
                    ITile tile = CalculateMovement(this.moveTask);

                    //if (tile == this.entity.Tile)
                    //{
                        // MoveTo will return false when the entity doesn't move (end of path)
                        moveTask.isActive = this.entity_move.MoveTo(FindAngle(tile.Position));
                    //}
                }
                else
                {
                    // the MoveTask will calculate a connected sequence of tiles that lead to the destination
                    moveTask = new MoveTask(this.entity, ChooseDestination(this.entity));

                    // gemerates a path and sets isEnabled to true
                    this.moveTask.Initialize();
                }
            }

            return result;
        }