Пример #1
0
        protected override void Initialize()
        {
            height        = graphics.GraphicsDevice.Viewport;
            height.Height = 800;
            graphics.GraphicsDevice.Viewport = height;


            this.graphics.PreferredBackBufferHeight = 800;
            this.graphics.ApplyChanges();

            ball_1 = new Ball(new Vector2(400, 400),  // init Position

                              2,                      // Speed multi, multiplies final speed vector
                                                      // after all other modifications in the game lifetime
                              new Vector2(1, 1));     // init Direction

            ball_2 = new Ball(new Vector2(400, 400),
                              2,
                              new Vector2(1, 1));

            paddle           = new Paddle(this.graphics);
            theBrick_Manager = new Brick_Manager(this.graphics);
            theScore_Manager = new Score_Manager(this.graphics);
            theMenu_Manager  = new Menu_Manager(this.graphics);

            // Initializing audio objects
            theAudioEngine = new AudioEngine("Content\\Audio\\Breakout_Audio.xgs");
            theWaveBank    = new WaveBank(theAudioEngine, "Content\\Audio\\Wave Bank.xwb");
            theSoundBank   = new SoundBank(theAudioEngine, "Content\\Audio\\Sound Bank.xsb");

            theMusic_Manager = new Music_Manager();
            gameover         = false;
            base.Initialize();
        }
Пример #2
0
        /// <summary>
        /// Determines if the obj colide, re-sets obj and bounding box positions,
        /// and checks what should be killed and what audio to play.
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="obj2"></param>
        /// <param name="isKillable"></param>
        public static void Check_Sprite_colision(Sprite obj1, Sprite obj2, bool isKillable)
        {
            if (obj2.isActive)
            {
                if (obj1.box.Intersects(obj2.box))
                {
                    if (obj1.Type == "Ball" || obj2.Type == "Ball")
                    {
                        ballCollided = true;                            // Flag for release of second ball in game version 2
                    }
                    if (obj1.Type == "Paddle" || obj2.Type == "Paddle") // Only produce sound if the obj is a Ball
                    {
                        Breakout.theSoundBank.PlayCue("PaddleHit");
                    }


                    if (isKillable)
                    {
                        Score_Manager.add_points(convertToBrick(obj2).get_Points());
                        brick_applyReflectPower((Ball)obj1, (Brick)obj2);
                        obj2.Kill();
                        Breakout.theSoundBank.PlayCue("BrickHit");
                    }

                    // Find Left/Right side
                    if (obj1.Prev_Pos_max.X < obj2.box.Min.X)
                    {
                        // Do left side computation
                        obj1.Direction.X *= -1;
                        obj1.Position.X   = obj2.box.Min.X - obj1.get_Texture().Width;
                        obj1.box.Min.X    = obj1.Position.X;
                        obj1.box.Max.X    = obj2.box.Min.X;
                    }
                    else if (obj1.Prev_Pos_min.X > obj2.box.Max.X)
                    {
                        // Do right side computation
                        obj1.Direction.X *= -1;
                        obj1.Position.X   = obj2.box.Max.X;
                        obj1.box.Min.X    = obj1.Position.X;
                        obj1.box.Max.X    = obj2.box.Max.X + obj2.get_Texture().Width;
                    }

                    // Find Top/Bottom side
                    if (obj1.Prev_Pos_max.Y < obj2.box.Min.Y)
                    {
                        // Do top side computation
                        obj1.Direction.Y *= -1;
                        obj1.Position.Y   = obj2.box.Min.Y - obj1.get_Texture().Height;
                        obj1.box.Min.Y    = obj1.Position.Y;
                        obj1.box.Max.Y    = obj2.box.Min.Y;
                    }
                    else if (obj1.Prev_Pos_min.Y > obj2.box.Max.Y)
                    {
                        // Do bottom side computation
                        obj1.Direction.Y *= -1;
                        obj1.Position.Y   = obj2.box.Max.Y;
                        obj1.box.Min.Y    = obj1.Position.Y;
                        obj1.box.Max.Y    = obj2.box.Max.Y + obj1.get_Texture().Height;
                    }
                }
            }
        }
Пример #3
0
        protected override void Initialize()
        {
            height = graphics.GraphicsDevice.Viewport;
            height.Height = 800;
            graphics.GraphicsDevice.Viewport = height;

            this.graphics.PreferredBackBufferHeight = 800;
            this.graphics.ApplyChanges();

            ball_1 = new Ball(new Vector2(400, 400),  // init Position

                                2,                      // Speed multi, multiplies final speed vector
                                                        // after all other modifications in the game lifetime
                                new Vector2(1, 1));     // init Direction

            ball_2 = new Ball(new Vector2(400, 400),
                                2,
                                new Vector2(1, 1));

            paddle = new Paddle(this.graphics);
            theBrick_Manager = new Brick_Manager(this.graphics);
            theScore_Manager = new Score_Manager(this.graphics);
            theMenu_Manager = new Menu_Manager(this.graphics);

            // Initializing audio objects
            theAudioEngine = new AudioEngine("Content\\Audio\\Breakout_Audio.xgs");
            theWaveBank = new WaveBank(theAudioEngine, "Content\\Audio\\Wave Bank.xwb");
            theSoundBank = new SoundBank(theAudioEngine, "Content\\Audio\\Sound Bank.xsb");

            theMusic_Manager = new Music_Manager();
            gameover = false;
            base.Initialize();
        }