示例#1
0
        public override void Update(GameTime gt)
        {
            if (currentBehaviour == null)
            {
                if (Vector2.Distance(Position, currentTarget.Position) < closeEnough)
                {
                    currentBehaviour = new Evade(this, currentTarget);
                }
                else
                {
                    currentBehaviour = new Pursue(this, currentTarget);
                }
            }

            if (Vector2.Distance(Position, currentTarget.Position) < closeEnough)
            {
                currentBehaviour = null;
            }

            if (m_Velocity.Length() > 0)
            {
                m_Velocity.Normalize();
            }

            if (currentBehaviour != null)
            {
                m_Velocity += currentBehaviour.GetForce();
            }

            base.Update(gt);
        }
示例#2
0
        public override void Update(GameTime gt)
        {
            if (currentTarget != null)
            {
                currentBehaviour = new Evade(this, currentTarget);
            }

            //Target is far away enough, so sit still
            if (Vector2.Distance(m_Position, currentTarget.Position) > m_FarAwayEnough)
            {
                m_Velocity = Vector2.Zero;
            }
            //otherwise move away
            else
            {
                m_Velocity += currentBehaviour.GetForce();
            }

            if (m_Velocity.Length() > 0)
            {
                m_Velocity.Normalize();
            }

            base.Update(gt);
        }
示例#3
0
        public override void Update(GameTime gt)
        {
            Vector2 mousePos = Vector2.Zero;

            mousePos.X = Mouse.GetState().X;
            mousePos.Y = Mouse.GetState().Y;

            currentBehaviour = new Seek(this, mousePos);

            m_Velocity += currentBehaviour.GetForce();

            base.Update(gt);
        }
示例#4
0
        public override void Update(GameTime gt)
        {
            //go outside level, reset pos
            if (m_Position.X < 0 || m_Position.X > Game1.g_iScreenWidth || m_Position.Y < 0 || m_Position.Y > Game1.g_iScreenHeight)
            {
                ResetPosition();
            }

            if (m_Velocity.Length() > 0)
            {
                m_Velocity.Normalize();
            }

            m_Velocity += currentBehaviour.GetForce();

            base.Update(gt);
        }