Example #1
0
        private (int[, ] map, Point?lootCoord) CreateStepsMapToClosestLootBox(WorldActivityCalculator worldCalculator)
        {
            //worldCalculator = new WorldActivityCalculator(startMap);

            CurrentMap = worldCalculator.currentMap;
            stepsMap   = new int[CurrentMap.Size.X, CurrentMap.Size.Y];
            int stepCount = 1;

            stepsMap[CurrentMap.PlayerPosition.X, CurrentMap.PlayerPosition.Y] = 1;

            Point?findedLootBoxCoordinate = null;
            var   lastStepVisitedCells    = new List <Point>()
            {
                CurrentMap.PlayerPosition
            };

            while (lastStepVisitedCells.Count > 0 && findedLootBoxCoordinate == null)
            {
                worldCalculator.Tick();
                stepCount++;
                var currentStepVisitedCells = new List <Point>();
                for (int i = 0; i < lastStepVisitedCells.Count; i++)
                {
                    var visitedCellCoord = lastStepVisitedCells[i];
                    for (var dx = -1; dx < 2; dx++)
                    {
                        for (var dy = -1; dy < 2; dy++)
                        {
                            var currentCellCoord = new Point(visitedCellCoord.X + dx, visitedCellCoord.Y + dy);

                            if (dx * dy != 0 || !CurrentMap.Contains(currentCellCoord))
                            {
                                continue;
                            }

                            var currentCellValue = CurrentMap.Cells[currentCellCoord.X, currentCellCoord.Y];

                            if (stepsMap[currentCellCoord.X, currentCellCoord.Y] == 0)
                            {
                                if (currentCellValue == MapCell.LootBox)
                                {
                                    findedLootBoxCoordinate = currentCellCoord;
                                }

                                if (Map.IsCellPassable(currentCellValue))
                                {
                                    currentStepVisitedCells.Add(currentCellCoord);
                                    stepsMap[currentCellCoord.X, currentCellCoord.Y] = stepCount;
                                }
                            }
                        }
                    }
                }

                lastStepVisitedCells = currentStepVisitedCells;
            }
            return(stepsMap, findedLootBoxCoordinate);
        }
Example #2
0
 public void Update(GameTime gameTime)
 {
     elapsedTimeFromLastStep += gameTime.ElapsedGameTime;
     if (elapsedTimeFromLastStep >= stepTime)
     {
         elapsedTimeFromLastStep = TimeSpan.Zero;
         worldCalculator.Tick();
         map.TryToMovePlayer(playerPathManager.GetNextStep());
     }
 }