Ejemplo n.º 1
0
 public CollisionManager(Game game, Bat batLeft, Bat batRight, Ball ball, SoundEffect hit, Vector2 stage)
     : base(game)
 {
     // TODO: Construct any child components here
     this.batLeft  = batLeft;
     this.batRight = batRight;
     this.ball     = ball;
     this.hit      = hit;
     this.stage    = stage;
 }
Ejemplo n.º 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);

            // TODO: use this.Content to load your game content here
            SoundEffect hit  = Content.Load <SoundEffect>("sounds/click");
            SoundEffect miss = Content.Load <SoundEffect>("sounds/ding");

            applause = Content.Load <SoundEffect>("sounds/applause1");

            Vector2 batspeed = new Vector2(0, 5);

            stage = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            //ScoreBoard
            Texture2D scoreBoardTex = Content.Load <Texture2D>("images/Scorebar");
            Vector2   scoreBoardPos = new Vector2(0, stage.Y - scoreBoardTex.Height);

            scoreBoard = new ScoreBoard(this, spriteBatch, scoreBoardTex, scoreBoardPos);
            this.Components.Add(scoreBoard);



            //Ball
            Texture2D ballTex   = Content.Load <Texture2D>("images/Ball");
            Vector2   ballPos   = new Vector2(stage.X / 2 - ballTex.Width / 2, stage.Y / 2 - ballTex.Height / 2 - scoreBoardTex.Height / 2);
            Vector2   ballSpeed = new Vector2(1, 1);

            ball = new Ball(this, spriteBatch, ballTex, ballPos, hit, miss, stage, scoreBoardTex.Height + ballTex.Height);
            this.Components.Add(ball);

            //Left bat
            Texture2D batLeftTex = Content.Load <Texture2D>("images/BatLeft");
            Vector2   batLeftPos = new Vector2(0, stage.Y / 2 - batLeftTex.Height / 2 - scoreBoardTex.Height / 2);

            batLeft = new Bat(this, spriteBatch, batLeftTex, batLeftPos, batspeed, stage);
            this.Components.Add(batLeft);

            //Right bat
            Texture2D batRightTex = Content.Load <Texture2D>("images/BatRight");
            Vector2   batRightPos = new Vector2(stage.X - batRightTex.Width, stage.Y / 2 - batLeftTex.Height / 2 - scoreBoardTex.Height / 2);

            batRight = new Bat(this, spriteBatch, batRightTex, batRightPos, batspeed, stage);
            this.Components.Add(batRight);

            //Collision Manager
            cm = new CollisionManager(this, batLeft, batRight, ball, hit, stage);
            this.Components.Add(cm);


            font = Content.Load <SpriteFont>("fonts/SpriteFont1");

            //Left Score
            leftScorePos = new Vector2(0, stage.Y - scoreBoardTex.Height / 2 - font.LineSpacing / 2);
            leftScoreMsg = leftPlayer + ": " + ball.LeftScore.ToString();
            leftScore    = new ScoreString(this, spriteBatch, leftScoreMsg, leftScorePos, Color.Black, font);
            this.Components.Add(leftScore);

            //Right Score
            rightScoreMsg = rightPlayer + ": " + ball.RightScore.ToString();
            rightScorePos = new Vector2(stage.X - font.MeasureString(rightScoreMsg).X, stage.Y - scoreBoardTex.Height / 2 - font.LineSpacing / 2);
            rightScore    = new ScoreString(this, spriteBatch, rightScoreMsg, rightScorePos, Color.Black, font);
            this.Components.Add(rightScore);

            //Winning Msg
            winMsg    = "";
            winMsgPos = new Vector2(stage.X / 2 - font.MeasureString("Press spacebar to restart").X / 2, stage.Y - scoreBoardTex.Height / 2 - font.LineSpacing);
            win       = new ScoreString(this, spriteBatch, winMsg, winMsgPos, Color.Blue, font);
            this.Components.Add(win);
        }