Пример #1
0
        protected void GameUpdate(GameTime gameTime)
        {
            mTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (mAlivePlayerCount > 1)
            {
                //UpdateTimeText();

                if (mEnemies.Count < mMaxEnemies)
                {
                    mEnemies.Add(new Enemy(this, this.Content));
                }

                if (mTimer - mLastPOIUpdateTime > 1000)
                {
                    GetNewPointOfInterest();
                }

                foreach (Enemy e in mDestroyEnemies)
                {
                    Program.Instance.mEnemies.Remove(e);
                }

                mDestroyEnemies.Clear();

                foreach (Powerup p in mDestroyPowerups)
                {
                    Program.Instance.mPowerups.Remove(p);
                }

                mDestroyPowerups.Clear();

                if (mTimer - mLastPowerupTime > Config.Instance.GetAsInt("PowerupInterval"))
                {
                    NewPowerup();
                }
            }
            else
            {
                // game over
                int width = Config.Instance.GetAsInt("ScreenWidth");
                int height = Config.Instance.GetAsInt("ScreenHeight");

                rnum1 = new RankFirstNum(this, this.Content);
                pressA = new PressA(this, this.Content);

                rnum1.mPosition = new Vector2(width / 2, height / 2 + 128);
                pressA.mPosition = new Vector2(width - 128, 128);

                List<Player> lp = new List<Player>();
                List<Player> sorted = new List<Player>();
                List<Sprite> positions = new List<Sprite>();

                positions.Add(rnum1);

                foreach (Player p in GamePlayers)
                {
                    if (p.mHealth > 0)
                    {
                        sorted.Add(p);
                    }
                }
                /*
                while (lp.Count > 0)
                {
                    Player largest = null;

                    foreach (Player p in lp)
                    {
                        if (largest == null)
                        {
                            largest = p;
                        }
                        else if (p.PixelWidth > largest.PixelWidth)
                        {
                            largest = p;
                        }
                    }

                    sorted.Add(largest);
                    lp.Remove(largest);
                }
                 */

                for (int i = 0; i < sorted.Count; i++)
                {
                    Player p = sorted[i];
                    switch (p.id)
                    {
                        case PlayerIndex.One:
                            {
                                rp1 = new RankP1(this, this.Content);
                                rp1.mPositionX = Config.Instance.GetAsInt("ScreenWidth") / 2;
                                rp1.mPositionY = Config.Instance.GetAsInt("ScreenHeight") / 2 - 96;

                                break;
                            }
                        case PlayerIndex.Two:
                            {
                                rp2 = new RankP2(this, this.Content);
                                rp2.mPositionX = Config.Instance.GetAsInt("ScreenWidth") / 2;
                                rp2.mPositionY = Config.Instance.GetAsInt("ScreenHeight") / 2 - 96;
                                break;
                            }
                        case PlayerIndex.Three:
                            {
                                rp3 = new RankP3(this, this.Content);
                                rp3.mPositionX = Config.Instance.GetAsInt("ScreenWidth") / 2;
                                rp3.mPositionY = Config.Instance.GetAsInt("ScreenHeight") / 2 - 96;
                                break;
                            }
                        case PlayerIndex.Four:
                            {
                                rp4 = new RankP4(this, this.Content);
                                rp4.mPositionX = Config.Instance.GetAsInt("ScreenWidth") / 2;
                                rp4.mPositionY = Config.Instance.GetAsInt("ScreenHeight") / 2 - 96;
                                break;
                            }
                    }

                    break;
                }

                mGameState = GameState.GameOver;
            }

            mEnemies.Sort(DepthCompare);
            m_GamePlayers.Sort(DepthCompare);
        }
Пример #2
0
        public void Restart()
        {
            bRestart = false;
            mBackground.Destroy();

            foreach (Player p in m_GamePlayers)
            {
                if (p.mPowerupBurstIcon != null)
                {
                    p.mPowerupBurstIcon.Destroy();
                }

                p.mPHead.Destroy();
                foreach (Heart h in p.mHearts)
                {
                    h.Destroy();
                }
                p.Destroy();
            }

            m_GamePlayers = new List<Player>();

            foreach (Enemy e in mEnemies)
            {
                e.Destroy();
            }

            mEnemies = new List<Enemy>();

            foreach (Powerup pow in mPowerups)
            {
                pow.Destroy();
            }

            mPowerups = new List<Powerup>();

            mLastPowerupTime = 0;
            mTimer = 0;

            mMaxEnemies = Config.Instance.GetAsInt("MaxEnemies");

            if(rnum1 != null)
                rnum1.Destroy();
            if(rnum2 != null)
                rnum2.Destroy();
            if(rnum3 != null)
                rnum3.Destroy();
            if(rp1 != null)
                rp1.Destroy();
            if(rp2 != null)
                rp2.Destroy();
            if(rp3 != null)
                rp3.Destroy();
            if(rp4 != null)
                rp4.Destroy();

            rnum1 = null;
            rnum2 = null;
            rnum3 = null;

            rp1 = null;
            rp2 = null;
            rp3 = null;
            rp4 = null;

            mTime.Dispose();

            mGameState = GameState.Init;
        }