Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="game">Game</param>
 /// <param name="ball">SpriteBatch</param>
 /// <param name="bat">Bat class</param>
 /// <param name="side">Left or right side in integer(1 is left,2 is right)</param>
 /// <param name="sndDing">Ding sound effect</param>
 public CollisionManager(Game game,
                         Ball ball,
                         Bat bat,
                         int side,
                         SoundEffect sndDing = null)
     : base(game)
 {
     this.ball    = ball;
     this.bat     = bat;
     this.side    = side;
     this.sndDing = sndDing;
     delay        = 0;
     // TODO: Construct any child components here
 }
Exemple #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            batTex      = Content.Load <Texture2D>("image/Sideways Bat");
            stage       = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            sndClick    = Content.Load <SoundEffect>("sound/click");
            sndDing     = Content.Load <SoundEffect>("sound/ding");
            sndFail     = Content.Load <SoundEffect>("sound/fail");
            sndGameOver = Content.Load <SoundEffect>("sound/gameOver");

            leftBat = new Bat(this, spriteBatch, batTex,
                              new Vector2(0, (stage.Y - batTex.Height) / 2),
                              new Vector2(0, 5),
                              stage, Keys.A, Keys.Z);


            rightBat = new Bat(this, spriteBatch, batTex,
                               new Vector2(stage.X - batTex.Width, (stage.Y - batTex.Height) / 2),
                               new Vector2(0, -5),
                               stage, Keys.Up, Keys.Down);


            Texture2D ballTex = Content.Load <Texture2D>("image/ball");

            ball = new Ball(this, spriteBatch, ballTex,
                            new Vector2((stage.X - ballTex.Width) / 2, (stage.Y - ballTex.Height) / 2),
                            new Vector2(5, 5), stage, 3, 9, int_NUMBER_OF_POINTS_TO_WIN, sndClick, sndFail, sndGameOver);


            leftCM  = new CollisionManager(this, ball, leftBat, idLeftSide, sndDing);
            rightCM = new CollisionManager(this, ball, rightBat, idRightSide, sndDing);


            font = Content.Load <SpriteFont>("font/font");
            Color messageColor = Color.Black;

            player1_Status = new Font(this, spriteBatch, font, "Player 1",
                                      new Vector2(50, 10), messageColor);

            player2_Status = new Font(this, spriteBatch, font, "Player 2",
                                      new Vector2(550, 10), messageColor);

            pressEnterMessage = new Font(this, spriteBatch, font, "Press Enter to start",
                                         new Vector2(300, 300), messageColor);

            pressSpaceBarMessage = new Font(this, spriteBatch, font, "GAME OVER! Press Space bar to start a new game",
                                            new Vector2(200, 300), messageColor, true);

            Components.Add(player1_Status);
            Components.Add(player2_Status);
            Components.Add(pressEnterMessage);
            Components.Add(pressSpaceBarMessage);
            Components.Add(ball);
            Components.Add(leftBat);
            Components.Add(rightBat);
            Components.Add(leftCM);
            Components.Add(rightCM);
            PlayerScore.GameInPlay = true;

            // TODO: use this.Content to load your game content here
        }