Пример #1
0
        public override void Update(GameTime gameTime)
        {
            foreach (Ball ball in balls.Children)
            {
                //left goal
                if (Vector2.Distance(leftGoal.Position, ball.Position) < (leftGoal.Sprite.Width * leftGoal.Scale) / 2 + (ball.Sprite.Width * ball.Scale) / 2)
                {
                    ball.Reset();
                    player.Reset();
                    keeper.Reset();
                    //ScoreCount.ScorePlayer1 += 100;
                }

                //right goal
                if (Vector2.Distance(rightGoal.Position, ball.Position) < (rightGoal.Sprite.Width * rightGoal.Scale) / 2 + (ball.Sprite.Width * ball.Scale) / 2)
                {
                    ball.Reset();
                    player.Reset();
                    keeper.Reset();
                }
            }

            //player
            if (Vector2.Distance(player.Position, ball.Position) < (player.Sprite.Width * player.Scale) / 2 + (ball.Sprite.Width * ball.Scale) / 2)
            {
                ElasticCollision(player, ball);
            }

            //keeper
            if (Vector2.Distance(keeper.Position, ball.Position) < (keeper.Sprite.Width * keeper.Scale) / 2 + (ball.Sprite.Width * ball.Scale) / 2)
            {
                ElasticCollision(keeper, ball);
            }

            base.Update(gameTime);

            //if (GameEnvironment.KeyboardState.IsKeyDown(Keys.Space))
            //   GameEnvironment.SwitchTo(1);
        }