Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            prevKs = ks;
            ks     = Keyboard.GetState();

            if (currState == GameState.MainMenu)
            {
                if (ks.IsKeyDown(Keys.W) && prevKs.IsKeyUp(Keys.W))
                {
                    currState = GameState.Simulation;
                }
            }

            if (currState == GameState.Simulation)
            {
                if (ks.IsKeyDown(Keys.Q) && prevKs.IsKeyUp(Keys.Q))
                {
                    currState = GameState.MainMenu;
                }
                if (ks.IsKeyDown(Keys.Space) && prevKs.IsKeyUp(Keys.Space))
                {
                    Random rand = new Random();
                    lunarians[(int)(rand.NextDouble() * lunarians.Length)].GiveCovid();
                }

                for (int i = 0; i < lunarians.Length; i++)
                {
                    lunarians[i].Update(gameTime, GraphicsDevice.Viewport);
                    for (int j = 0; j < lunarians.Length; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }
                        else
                        {
                            if (lunarians[j].HasCovid() && lunarians[j].hitBox.Intersects(lunarians[i].hitBox) && !lunarians[i].HasCovid())
                            {
                                lunarians[i].ChanceGiveCovid();
                            }
                        }
                    }
                }
            }

            middlePx.Update(gameTime, GraphicsDevice.Viewport);

            base.Update(gameTime);
        }