コード例 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (InputEngine.IsKeyPressed(Keys.F10) && !playerJoined)
            {
                LidgrenClient.RequeustToJoin();
            }

            #region update player
            if (player != null)
            {
                player.Update(gameTime);
                player.Position = Vector2.Clamp(player.Position, Vector2.Zero, (worldSize - new Vector2(player.SpriteWidth, player.SpriteHeight)));
            }
            foreach (OtherPlayer p in OtherPlayers)
            {
                p.Update(gameTime);
            }
            #endregion
            #region Update Collectables
            if (player != null)
            {
                foreach (Collectable c  in Collectables)
                {
                    c.Update(gameTime);
                }
            }

            if (player != null)
            {
                foreach (Collectable item in Collectables)
                {
                    if (item.Alive && player.collisionDetect(item))
                    {
                        collectablesAliveCount--;
                        player.Score += item.Score;
                        item.Alive    = false;
                        collectSound.Play();
                        LidgrenClient.Collected(item.collectableData);
                        LidgrenClient.SendScore(new ScoreData {
                            playerID = player.playerData.playerID, Tag = player.playerData.GamerTag, score = player.Score
                        });
                    }
                    item.Update(gameTime);
                }
            }
            #endregion Collectables
            #region Camera Control
            if (player != null & followCamera != null)
            {
                followCamera.Follow(player);
            }
            #endregion
            catchMessage(LidgrenClient.CheckMessages());

            base.Update(gameTime);
        }