Exemple #1
0
        private MonsterStrategy ChooseStrategy()
        {
            if (_strategyFrameNum++ < _minFramesToKeepAStrategy)
            {
                return(_previousStrategy);
            }
            _strategyFrameNum = 0;

            _target = GetNearestTarget(_targets, transform.position).GetComponent <CharacterBase>();

            _nearbyMonsters =
                ManagerCollection.Instance.EnemyManager.GetActiveMonsters()
                .Select(
                    m => new MonsterDist {
                Dist = (m.transform.position - transform.position), Monster = m
            })
                .Where(m => m.Dist.magnitude < _nearbyMonstersDist)
                .ToList();


            if ((_target.transform.position - transform.position).magnitude < _chargeDist)
            {
                _previousStrategy = MonsterStrategy.Attack;
                return(_previousStrategy);
            }


            if (_nearbyMonsters.Count >= _swarmThreshold && _nearbyMonsters.Count < _spreadThreshold)
            {
                _previousStrategy = MonsterStrategy.Swarm;
                return(_previousStrategy);
            }

            if (_nearbyMonsters.Count >= _spreadThreshold)
            {
                _previousStrategy = MonsterStrategy.Spread;
                return(_previousStrategy);
            }

            _previousStrategy = MonsterStrategy.Attack;
            return(_previousStrategy);
        }
Exemple #2
0
        public void AddMonster(string type)
        {
            double[,] record = new double [Width, Height];
            Field playerField = crossedField(Player.X, Player.Y);

            record [playerField.X, playerField.Y] = -1;
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    if (fields [i, j].Full && record [i, j] != -1)
                    {
                        record [i, j] = (monsters.Count + 1) * Math.Sqrt(Math.Pow(i - playerField.X, 2) + Math.Pow(j - playerField.Y, 2));
                        foreach (Monster monster in monsters)
                        {
                            Field monsterField = crossedField(monster.X, monster.Y);
                            record [monsterField.X, monsterField.Y] = -1;
                            record [i, j] += Math.Sqrt(Math.Pow(i - monsterField.X, 2) + Math.Pow(j - monsterField.Y, 2));
                        }
                    }
                }
            }
            Field  field   = null;
            double maxRank = -1;

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    if (record [i, j] > maxRank)
                    {
                        field   = fields [i, j];
                        maxRank = record [i, j];
                    }
                }
            }
            MonsterStrategy strategy = (MonsterStrategy)Activator.CreateInstance(Type.GetType("Bounce." + type));

            monsters.Add(new Monster(strategy, type, field.X * FieldSize, field.Y * FieldSize));
        }
Exemple #3
0
        private MonsterStrategy ChooseStrategy()
        {
            _target = GetNearestTarget(_targets, transform.position).GetComponent <CharacterBase>();

            _nearbyMonsters =
                ManagerCollection.Instance.EnemyManager.GetActiveMonsters()
                .Select(
                    m => new MonsterDist {
                Dist = (m.transform.position - transform.position), Monster = m
            })
                .Where(m => m.Dist.magnitude < _nearbyMonstersDist)
                .ToList();

            _strategyFrameNum++;
            if (_strategyFrameNum < _minFramesToKeepAStrategy)
            {
                return(_previousStrategy);
            }
            _strategyFrameNum = 0;

            var targetDistance = (_target.transform.position - transform.position).magnitude;

            if (targetDistance >= _moveCloserDist || _drawersLeft == 0)
            {
                _previousStrategy = MonsterStrategy.MoveCloser;
                return(_previousStrategy);
            }

            if (targetDistance < _moveAwayDist)
            {
                _previousStrategy = MonsterStrategy.MoveAway;
                return(_previousStrategy);
            }

            _previousStrategy = MonsterStrategy.Idle;
            return(_previousStrategy);
        }
Exemple #4
0
 public Monster(MonsterStrategy strategy, string type, int x, int y) : base(x, y)
 {
     this.Type     = type;
     this.strategy = strategy;
 }