예제 #1
0
        public void Think(Ball ball)
        {
            int n = _rng.Next(10);

            switch (n)
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                    RealThink(ball);
                    break;

                case 9:
                    Velocity.X = 0.0f;
                    Velocity.Y = 0.0f;
                    break;

                default:
                    // do nothing
                    break;
            }
        }
예제 #2
0
        private Vector2 CollisionPoint(bool playerCollision, Ball ball)
        {
            float x, y = ball.Midpoint().Y;

            if (playerCollision)
            {
                x = _player.Position.X + _player.Width;
            }
            else
            {
                x = _ai.Position.X;
            }

            return new Vector2(x, y);
        }
예제 #3
0
 private void RealThink(Ball ball)
 {
     if (ball.Midpoint().Y > Midpoint().Y)
     {
         if (Velocity.Y < _yVelocity)
         {
             Velocity.Y += 0.05f;
             if (Velocity.Y > _yVelocity)
             {
                 Velocity.Y = _yVelocity;
             }
         }
     }
     else if (ball.Midpoint().Y < Midpoint().Y)
     {
         if (Velocity.Y > -_yVelocity)
         {
             Velocity.Y -= 0.05f;
             if (Velocity.Y < -_yVelocity)
             {
                 Velocity.Y = -_yVelocity;
             }
         }
     }
     else if (ball.Midpoint().Y == Midpoint().Y)
     {
         Velocity.Y = 0.0f;
     }
 }
예제 #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _player = new PlayerPaddle(_court);
            _player.Texture = Content.Load<Texture2D>("paddle");
            _player.StartingPosition();

            _ai = new AIPaddle(_court);
            _ai.Texture = Content.Load<Texture2D>("paddle");
            _ai.StartingPosition();

            _ball = new Ball(_court);
            _ball.Texture = Content.Load<Texture2D>("ball");
            _ball.StartingPosition(_court);

            _splash = Content.Load<Texture2D>("splash");
            _font = Content.Load<SpriteFont>("ScoreFont");
            _gameEndHeadingFont = Content.Load<SpriteFont>("GameEndHeading");

            _paddleCollidePlayer = Content.Load<SoundEffect>("paddle_collide_player");
            _paddleCollideAi = Content.Load<SoundEffect>("paddle_collide_ai");
            _wallCollide = Content.Load<SoundEffect>("wall_collide");
            _aiScoreSound = Content.Load<SoundEffect>("disappointed_crowd_idiot");
            _playerScoreSound = Content.Load<SoundEffect>("pleased_crowd_about_time");

            _meanGreen = new Color(45, 198, 13);
            _creditsFont = Content.Load<SpriteFont>("CreditsFont");

            var creditsYSpacing = _creditsFont.MeasureString("X").Y * 0.5f ;
            var creditLineSizes = _creditLines.ConvertAll(x => _creditsFont.MeasureString(x));

            var creditsBaseY = _court.Height;

            for (int i = 0; i < _creditLines.Count; i++)
            {
                _creditsBaseByLine.Add(new Vector2(_court.Width / 2 - creditLineSizes[i].X / 2,
                    creditsBaseY + ((creditLineSizes[i].Y * i) + i * creditsYSpacing)));
            }

            _particleEffect = new ParticleEffect();
            _particleEffect.Texture = Content.Load<Texture2D>("spark02");
            _logger.Initialize(new GameTime(), 1000.0f / 15.0f);
            _gameState = GameState.Playing;
        }