Exemplo n.º 1
0
        /// <summary>
        /// Try to attack one of the players in the list passed in.
        /// </summary>
        public void TryToAttackPlayers(Shark s, List<Penguin> players)
        {
            if (s.CurrState != Actor.state.Moving)
                return;

            float minDist = 10000.0f;
            float currDist = 0.0f;
            Vector2 nearestPosition = Vector2.Zero;
            Vector2 distance = Vector2.Zero;
            Vector2 vecTowardNearest = Vector2.Zero;

            float chumDist = 10000.0f;

            foreach (Penguin p in players)
            {
                if (!p.IsAlive)
                    continue;
                if (p.PowerupState == powerupstate.SharkRepellent)
                    continue;

                distance.X = p.Position.X - s.Position.X;
                distance.Y = p.Position.Y - s.Position.Y;

                currDist = distance.Length();

                // make chum have priority
                if (p.PowerupState == powerupstate.Chum)
                {
                    if (currDist < chumDist)
                    {
                        chumDist = currDist;
                        nearestPosition = p.Position;
                        vecTowardNearest = distance;
                        continue;
                    }
                }

                if (currDist < minDist)
                {
                    minDist = currDist;
                    nearestPosition = p.Position;
                    vecTowardNearest = distance;
                }
            }

            // LOL GO AFTER NO MATTER WHAT
            if (chumDist <= SHARK_ATTACK_THRESHOLD && s.CurrState != Actor.state.Dashing
                && s.CurrState != Actor.state.Dash)
            {
                s.acceleration = vecTowardNearest;
                ((Shark)s).attack();
                return;
            }

            // try to aggress toward the nearest player
            if (minDist <= SHARK_ATTACK_THRESHOLD
                && s.CurrState != Actor.state.Dashing
                && s.CurrState != Actor.state.Dash && chumDist >= 10000.0f)
            {
                s.acceleration = vecTowardNearest;
                ((Shark)s).attack();
            }
        }
Exemplo n.º 2
0
Arquivo: Fish.cs Projeto: atarng/JAMMM
        /// <summary>
        /// Sets the nearest threatening actors for this fish 
        /// among the provided actors.
        /// </summary>
        public void SetNearestThreats(List<Penguin> players, List<Shark> sharks)
        {
            // dead finish don't need threats
            if (CurrState == state.Dying || !this.IsAlive)
                return;

            float   distBetween    = 0.0f;

            float   distToNearestP = 5000.0f;
            float   distToNearestS = 5000.0f;

            Penguin nearestP       = null;
            Shark   nearestS       = null;

            foreach (Penguin p in players)
            {
                if (!p.IsAlive || p.CurrState == state.Dying)
                    continue;

                distBetween = Actor.DistanceBetween(this, p);

                if (distBetween < distToNearestP)
                {
                    distToNearestP = distBetween;

                    nearestP = p;
                }
            }

            foreach (Shark s in sharks)
            {
                if (!s.IsAlive || s.CurrState == state.Dying)
                    continue;

                distBetween = Actor.DistanceBetween(this, s);

                if (distBetween < distToNearestS)
                {
                    distToNearestS = distBetween;

                    nearestS = s;
                }
            }

            if (nearestP != null)
                this.nearestPlayer = nearestP;

            if (nearestS != null)
                this.nearestShark = nearestS;
        }