Exemplo n.º 1
0
        public override void EngagePowerup(Player p)
        {
            base.EngagePowerup(p);

            p.mHealth += 25;
            if (p.mHealth > Config.Instance.GetAsInt("PlayerHealth"))
            {
                p.mHealth = Config.Instance.GetAsInt("PlayerHealth");
            }
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            float mls = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
            mTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (mState == eEnemyState.FLOCK)
            {
                this.mAnimPlayer0.Update(gameTime);
                this.mAnimPlayer1.Update(gameTime);
                this.mAnimPlayer2.Update(gameTime);
                this.mAnimPlayer3.Update(gameTime);
                this.mAnimPlayer4.Update(gameTime);

                // move towards nearest owner
                if (mOwner != null)
                {
                    Vector2 dir = mOwner.mPOI - mPosition;
                    dir.Normalize();

                    mVelocity = mVelocity + mls * (dir * mChaseStrength);

                    if (mTimer - mOwnedTime > mOwnedDuration)
                    {
                        mOwner.mOwnedCount--;
                        mOwner.UnOwnEnemy(this);
                        mOwner = null;
                    }
                }
                else
                {
                    // no owner, so move towards current point of interest

                    Vector2 dir = Program.Instance.GetCurrentPointOfInterest() - mPosition;

                    if (dir.Length() > InterestRadius)
                    {
                        dir.Normalize();

                        mVelocity = mVelocity + mls * (dir * mChaseStrength);
                    }
                }

                // move away from nearest predator
                Player predator = GetNearestPredator();

                if (predator != null)
                {
                    Vector2 dir = mPosition - predator.mPosition;
                    if (dir.Length() - Radius - predator.Radius < InterestRadius)
                    {
                        dir.Normalize();

                        mVelocity = mVelocity + mls * (dir * mAvoidPlayerStrength);
                    }
                }

                // move away from nearest enemy
                Enemy enemy = GetNearestEnemy();

                if (enemy != this)
                {
                    Vector2 dir = mPosition - enemy.mPosition;
                    if (dir.Length() - Radius - enemy.Radius < InterestRadius)
                    {
                        dir.Normalize();

                        mVelocity = mVelocity + mls * (dir * mAvoidEnemyStrength);
                    }
                }

                Enemy ownedEnemy = GetNearestOwnedEnemy();
                if (ownedEnemy != null)
                {
                    Vector2 dir = mPosition - enemy.mPosition;
                    if (dir.Length() - Radius - enemy.Radius < InterestRadius)
                    {
                        if (dir.Length() - Radius - enemy.Radius < Radius)
                        {
                            if (mOwner != null && enemy.mOwner != null && mOwner != enemy.mOwner)
                            {
                                // destroy both
                                Program.Instance.DestroyEnemy(this);
                                Program.Instance.DestroyEnemy(enemy);
                            }
                            else if (mOwner != null && enemy.mOwner == null && mState != eEnemyState.FIRE && enemy.mState != eEnemyState.FIRE)
                            {
                                // convert enemy
                                mOwner.OwnEnemy(enemy);
                                enemy.SetOwned(mOwner);
                            }
                            else if (mOwner == null && enemy.mOwner != null && mState != eEnemyState.FIRE && enemy.mState != eEnemyState.FIRE)
                            {
                                // convert this
                                enemy.mOwner.OwnEnemy(this);
                                SetOwned(enemy.mOwner);
                            }
                        }
                    }
                }

                // add drag
                Vector2 drag = new Vector2(-mVelocity.X, -mVelocity.Y);
                if (drag.Length() != 0)
                {
                    drag.Normalize();
                    mVelocity = mVelocity + mls * (drag * (mVelocity.Length() * 2));
                }

                if (mVelocity.Length() > mMaxSpeed)
                {
                    mVelocity.Normalize();
                    mVelocity = mVelocity * mMaxSpeed;
                }

                // set position
                mPositionX = mPosition.X + mls * mVelocity.X;
                mPositionY = mPosition.Y + mls * mVelocity.Y;
            }
            else if (mState == eEnemyState.FIRE)
            {
                if (mVelocity.Length() > mMaxSpeed)
                {
                    mVelocity.Normalize();
                    mVelocity = mVelocity * mMaxSpeed;
                }

                // set position
                mPositionX = mPosition.X + mls * mVelocity.X;
                mPositionY = mPosition.Y + mls * mVelocity.Y;

                if (mPosition.X > Config.Instance.GetAsInt("ScreenWidth") ||
                    mPosition.Y > Config.Instance.GetAsInt("ScreenHeight") ||
                    mPosition.X < 0 ||
                    mPosition.Y < 0)
                {
                    Program.Instance.DestroyEnemy(this);
                }

                if (mPrevOwner != null)
                {
                    if (mTimer - mFireTime > 100)
                    {
                        mState = eEnemyState.FLOCK;
                        mPrevOwner.OwnEnemy(this);
                        mPrevOwner = null;
                    }
                }

            }
            else if (mState == eEnemyState.HOMING)
            {
                if (mHomingPlayer.mHealth > 0)
                {
                    Vector2 dir = mHomingPlayer.mPosition - mPosition;
                    dir.Normalize();

                    mVelocity = mVelocity + mls * (dir * mChaseStrength);
                }
                else
                {
                    /*
                    mOwner.mOwnedCount--;
                    mOwner.UnOwnEnemy(this);
                    mOwner = null;
                     * */
                }

                // add drag
                Vector2 drag = new Vector2(-mVelocity.X, -mVelocity.Y);
                if (drag.Length() != 0)
                {
                    drag.Normalize();
                    mVelocity = mVelocity + mls * (drag * (mVelocity.Length() * 2));
                }

                if (mVelocity.Length() > mMaxSpeed)
                {
                    mVelocity.Normalize();
                    mVelocity = mVelocity * mMaxSpeed;
                }

                // set position
                mPositionX = mPosition.X + mls * mVelocity.X;
                mPositionY = mPosition.Y + mls * mVelocity.Y;
            }

            base.Update(gameTime);
        }
Exemplo n.º 3
0
 public void SetOwned(Player owner)
 {
     mOwner = owner;
     mOwnedTime = mTimer;
     owner.mOwnedCount++;
     mOwnedDuration = (owner.mOwnedCount * 1000) + 5000;
 }
Exemplo n.º 4
0
 public void Homing(Player player)
 {
     mHomingPlayer = player;
     mState = eEnemyState.HOMING;
 }
Exemplo n.º 5
0
 public virtual void EngagePowerup(Player p)
 {
 }
Exemplo n.º 6
0
        public static Vector2 GetAvgDirectionForAllPlayers(Player pCaptain)
        {
            Vector2 result = new Vector2();

            foreach (Player p in Player.m_PlayerMerges[pCaptain.id].players)
            {
                float moveX = GamePad.GetState(p.id).ThumbSticks.Left.X;
                float moveY = -GamePad.GetState(p.id).ThumbSticks.Left.Y;

                Vector2 playerDir = new Vector2(moveX, moveY);

                if (playerDir.Length() > 0)
                {
                    playerDir.Normalize();
                    result += playerDir;
                }
            }

            // Get captain movement
            float fCaptainMoveX = GamePad.GetState(pCaptain.id).ThumbSticks.Left.X;
            float fCaptainMoveY = GamePad.GetState(pCaptain.id).ThumbSticks.Left.Y;

            result += new Vector2(fCaptainMoveX, -fCaptainMoveY);

            if (result.Length() > 0)
                result.Normalize();

            return result;
        }
Exemplo n.º 7
0
            public bool Find(Player p)
            {
                if (players.Contains(p))
                    return true;

                return false;
            }
Exemplo n.º 8
0
 public void Add(Player p)
 {
     players.Add(p);
 }
Exemplo n.º 9
0
        private static bool IsThisPlayerCaptain(Player p)
        {
            if (m_PlayerMerges.ContainsKey(p.id))
                return true;

            return false;
        }
Exemplo n.º 10
0
 public override void EngagePowerup(Player p)
 {
     p.mPowerupBurst = false;
     p.mPowerupHoming = true;
     base.EngagePowerup(p);
 }