/// <summary>
        /// Initialize our game and load all graphics.
        /// </summary>
        protected override void Initialize()
        {
            // Remember resolution
            width = graphics.GraphicsDevice.Viewport.Width;
            height = graphics.GraphicsDevice.Viewport.Height;

            // Load all our content
            backgroundTexture = content.Load<Texture2D>("PongBackground");
            gameTexture = content.Load<Texture2D>("BreakoutGame");
            audioEngine = new AudioEngine("BreakoutSound.xgs");
            waveBank = new WaveBank(audioEngine, "Wave Bank.xwb");
            if (waveBank != null)
                soundBank = new SoundBank(audioEngine, "Sound Bank.xsb");

            // Create all sprites
            paddle = new SpriteHelper(gameTexture, GamePaddleRect);
            ball = new SpriteHelper(gameTexture, GameBallRect);
            block = new SpriteHelper(gameTexture, GameBlockRect);
            youWon = new SpriteHelper(gameTexture, GameYouWonRect);
            youLost = new SpriteHelper(gameTexture, GameYouLostRect);
            background = new SpriteHelper(backgroundTexture, null);

            // Init all blocks, set positions and bounding boxes
            for (int y = 0; y < NumOfRows; y++)
                for (int x = 0; x < NumOfColumns; x++)
                {
                    blockPositions[x, y] = new Vector2(
                        0.05f + 0.9f * x / (float)(NumOfColumns - 1),
                        0.066f + 0.5f * y / (float)(NumOfRows - 1));
                    Vector3 pos = new Vector3(blockPositions[x, y], 0);
                    Vector3 blockSize = new Vector3(
                        GameBlockRect.X/1024.0f, GameBlockRect.Y/768, 0);
                    blockBoxes[x, y] = new BoundingBox(
                        pos - blockSize/2,
                        pos + blockSize/2);
                } // for for

            // Start with level 1
            StartLevel();

            base.Initialize();
        }
Example #2
0
        /// <summary>
        /// Load all graphics content (just our background texture).
        /// Use this method to make sure a device reset event is handled correctly.
        /// </summary>
        protected override void LoadContent()
        {
            // Load all our content
            backgroundTexture = Content.Load<Texture2D>("SpaceBackground");
            // Game texture
            gameTexture = Content.Load<Texture2D>("BreakoutGame");
            audioEngine = new AudioEngine("Content\\BreakoutSound.xgs");
            waveBank = new WaveBank(audioEngine, "Content\\Wave Bank.xwb");
            if (waveBank != null)
                soundBank = new SoundBank(audioEngine, "Content\\Sound Bank.xsb");

            // Create all sprites
            paddle = new SpriteHelper(gameTexture, GamePaddleRect);
            ball = new SpriteHelper(gameTexture, GameBallRect);
            block = new SpriteHelper(gameTexture, GameBlockRect);
            // You won sound
            youWon = new SpriteHelper(gameTexture, GameYouWonRect);
            // You lost sound
            youLost = new SpriteHelper(gameTexture, GameYouLostRect);
            // And finally the background texture as a sprite
            background = new SpriteHelper(backgroundTexture, null);
        }