public override void Update()
        {
            if (!Active)
            {
                return;
            }

            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick += DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }
            else
            {
                m_ChangetargetTick += DT;

                if (m_ChangetargetTick > 8.0f)
                {
                    m_PickedTarget     = 0;
                    m_ChangetargetTick = 0.0f;
                }
            }

            if (m_AnimTick >= MILLIS_PER_FRAME)
            {
                ++frameX;

                if (m_Facing == Facing.Right)
                {
                    frameY = 0.0f;
                    if (frameX >= NUM_FRAMES_X)
                    {
                        frameX = 0;
                    }
                }
                else
                {
                    frameY = 3.0f;
                    if (frameX >= NUM_FRAMES_X)
                    {
                        frameX = 0;
                    }
                }

                m_AnimTick = 0.0f;
            }

            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            Vector2 my_centre     = this.Position;

            if ((player_centre.X) < my_centre.X)
            {
                m_Facing = Facing.Left;
            }
            else
            {
                m_Facing = Facing.Right;
            }

            float       dist      = Vector2.Distance(player_centre, my_centre);
            const float speed     = 0.8f;
            Vector2     direction = Vector2.Zero;

            // Seek Player
            if (dist < 400)
            {
                direction = Vector2.Normalize(player_centre - my_centre);
                Velocity  = direction * speed;
            }
            else if (dist < 1800)
            {
                double elapsed = GameSimulation.instance.GetTotalTime();
                Velocity = new Vector2((float)Math.Cos(elapsed) * speed, (float)Math.Sin(elapsed) * speed);
            }

            // Update Pos
            Position += Velocity;
        }
Ejemplo n.º 2
0
        public override void Update()
        {
            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick += DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }

            // Get distance of closest player
            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            Vector2 my_centre     = this.Position;

            if (player_centre.X < my_centre.X)
            {
                m_Facing = Facing.Left;
            }
            else
            {
                m_Facing = Facing.Right;
            }

            if (m_Facing == Facing.Left)
            {
                frameY = 0.0f;
            }
            else
            {
                frameY = 2.0f;
            }

            if (m_AnimTick >= k_MillisPerFrame)
            {
                ++frameX;

                if (frameX >= m_NumFramesX)
                {
                    frameX = 0;
                }

                m_AnimTick = 0.0f;
            }

            float dist = Vector2.Distance(my_centre, player_centre);

            // Dash Attack the player
            switch (m_AIState)
            {
            case MinionAIState.Idle:
            {
                if (m_FoundTarget == 0)
                {
                    this.Velocity = new Vector2(0.0f, 0.0f);

                    if (dist < k_MoveToPlayerDist)
                    {
                        m_FoundTarget = 1;
                        m_Direction   = Vector2.Normalize(player_centre - my_centre);
                    }
                }
                else
                {
                    this.Velocity      = m_Direction * 3.0f;
                    m_AttackWaitCount += DT;
                }

                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Charge;
                    m_FoundTarget     = 0;
                }
                break;
            }

            case MinionAIState.Charge:
            {
                if (dist < k_MinChargeDistance)
                {
                    if ((player_centre.Y > this.Position.Y) && (player_centre.Y < this.Position.Y))
                    {
                        this.Velocity.X = 10.0f * (float)m_Facing;
                        m_AIState       = MinionAIState.Dash;
                        break;
                    }
                }

                // Give up and try and get nearer
                m_AttackWaitCount += DT;
                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Idle;
                }

                break;
            }

            case MinionAIState.Dash:
            {
                float m_friction = 0.2f;

                // Apply friction
                if (this.Velocity.X < 0)
                {
                    this.Velocity.X += m_friction;
                }
                if (this.Velocity.X > 0)
                {
                    this.Velocity.X -= m_friction;
                }

                // Set to Zero when speed is low enough
                if (this.Velocity.X > 0 && this.Velocity.X < m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                }
                if (this.Velocity.X < 0 && this.Velocity.X > -m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                    m_PickedTarget  = 0;
                }
                break;
            }
            }

            this.Position += this.Velocity;
        }
        public override void Update()
        {
            // Resolve new players
            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick -= DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }

            m_AttackWaitCount -= DT;
            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            bool    break_idle    = false;
            bool    got_atatcked  = false;
            float   dist          = Vector2.Distance(Position, player_centre);

            if (dist < 300)
            {
                break_idle = true;
            }

            m_FacingTime += DT;
            if (m_FacingTime > 0.7f)
            {
                m_CanSwitchDir = true;
                m_FacingTime   = 0.0f;
            }

            if (m_AIState == ShadowAIState.Attacking || m_AIState == ShadowAIState.Idle)
            {
                if ((player_centre.X < Position.X) && m_CanSwitchDir == true)
                {
                    m_Facing       = Facing.Left;
                    m_CanSwitchDir = false;
                }
                else if ((player_centre.X > Position.X) && m_CanSwitchDir == true)
                {
                    m_Facing       = Facing.Right;
                    m_CanSwitchDir = false;
                }
            }

            Velocity = Vector2.Zero;

            // Logic
            switch (m_AIState)
            {
            case ShadowAIState.Rising:
                m_AttackWaitCount = 1.5f * ATTK_COUNT;
                break;

            case ShadowAIState.Idle:
            case ShadowAIState.Attacking:
            {
                // No object
                Velocity = new Vector2((float)m_Facing * 0.8f, 0.0f);

                // TODO *** Handle collision for walls
                break;
            }

            case ShadowAIState.Sinking:
                m_PickedTarget = 0;
                break;
            }

            Animate(break_idle, (got_atatcked && dist > 200));

            Position += Velocity;
        }