Ejemplo n.º 1
0
 // Main Ball Movement Logic, Calls Sub Functions changeAngel() && move() //
 // Checks If The Ball Is Moving Left || Right, Then Checks The Appropriate Paddle Hitbox For Collision //
 public void moveBall(double gametime, Paddle Rpaddle, Paddle Lpaddle, CriticalArea crit)
 {
     if (direction == (int)Direction.Right)
     {
         if (!this.collisionRect.Intersects(Rpaddle.collisionRect))
         {
             changeAngle(crit.checkCrits(this));
             move(gametime);
         }
         else
         {
             direction = (int)Direction.Left;
         }
     }
     if (direction == (int)Direction.Left)
     {
         if (!this.collisionRect.Intersects(Lpaddle.collisionRect))
         {
             changeAngle(crit.checkCrits(this));
             move(gametime);
         }
         else
         {
             direction = (int)Direction.Right;
         }
     }
 }
Ejemplo n.º 2
0
        // Content Loading Method (Via Content Pipeline) //
        protected override void LoadContent()
        {
            // Set The Spritebatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load Music & Sound Effects
            jukebox.maintheme  = Content.Load <Song>("Audio/MainTheme");
            Jukebox.beginsound = Content.Load <SoundEffect>("Audio/beginsound");
            Jukebox.wallhit    = Content.Load <SoundEffect>("Audio/WallHit");
            Jukebox.paddlehit  = Content.Load <SoundEffect>("Audio/PaddleHit");
            Jukebox.score      = Content.Load <SoundEffect>("Audio/Score");

            jukebox.playMainTheme();

            // Load Fonts //
            font     = Content.Load <SpriteFont>("Fonts/Font");
            timefont = Content.Load <SpriteFont>("Fonts/TimeFont");

            initScore(font, timefont);

            // Animated Count Down //
            countdown.setImg(Content.Load <Texture2D>("Sprites/countdownShort"), new Rectangle(0, 0, 200, 200), 3);

            // Load Paddles //
            Lpaddle.setImg(Content.Load <Texture2D>("Sprites/Paddle"), new Rectangle(0, 50, 22, 94), 1);
            Rpaddle.setImg(Content.Load <Texture2D>("Sprites/Paddle"), new Rectangle(618, 50, 22, 94), 1);

            // Load Background & Pause Screen //
            background  = Content.Load <Texture2D>("Sprites/Background");
            pausescreen = Content.Load <Texture2D>("Sprites/PauseScreen");

            // Load Scoreboards //
            scoreboard.setImg(Content.Load <Texture2D>("Sprites/Pallet"), new Rectangle(0, 0, 44, 1098), 1);
            lscore.setImg(Content.Load <Texture2D>("Sprites/Player1Score"), new Rectangle(0, 0, 44, 50), 1);
            rscore.setImg(Content.Load <Texture2D>("Sprites/Player2Score"), new Rectangle(0, 0, 44, 50), 1);

            // Load & Prepare The Crystals And Their Respective Containers //
            for (int counter = 0; counter < 6; counter++)
            {
                animatedcrystalarr[counter].setImg(Content.Load <Texture2D>("Sprites/blackedit"), new Rectangle(0, 0, 21, 16), 32);
                outlinedcrystalarr[counter].setImg(Content.Load <Texture2D>("Sprites/outlinedblackemerald"), new Rectangle(0, 0, 21, 16), 1);
                if (counter < 3)
                {
                    outlinedcrystalarr[counter].setVector(new Vector2(60 + lscore.positionholder, 5));
                    lscore.positionholder += outlinedcrystalarr[counter].boundingrect.Width;
                    animatedcrystalarr[counter].setVector(outlinedcrystalarr[counter].position);
                }
                else
                {
                    outlinedcrystalarr[counter].setVector(new Vector2(520 + rscore.positionholder, 5));
                    rscore.positionholder += outlinedcrystalarr[counter].boundingrect.Width;
                    animatedcrystalarr[counter].setVector(outlinedcrystalarr[counter].position);
                }
            }

            rscore.setVector(new Vector2(635 - rscore.boundingrect.Width, 0));

            // Different Sizes Of Sphere //
            // ball.setImg(Content.Load<Texture2D>("Sprites/Large_Sized_Sphere"), new Rectangle(0, 0, 64, 63), 32); //Large Ball
            // ball.setImg(Content.Load<Texture2D>("Sprites/Small_Sized_Sphere"), new Rectangle(0, 0, 16, 17), 32); // Small Ball
            ball.setImg(Content.Load <Texture2D>("Sprites/Medium_Sized_Sphere"), new Rectangle(0, 0, 32, 32), 32); // Medium Ball

            // Set Collision Rectangles //
            ball.setCollisionRect(ball.boundingrect);
            Lpaddle.setCollisionRect(Lpaddle.boundingrect);
            Rpaddle.setCollisionRect(Rpaddle.boundingrect);

            // Critical Areas Set //
            // Example: A Critical Area Would Be 1 Of The 4 Sides Of The Bounding Rectangle Of The Playing Field OR The Paddle's Hitboxes
            critical = new CriticalArea(new Rectangle(0, 0, 1, 480), new Rectangle(640, 0, 1, 480), new Rectangle(0, 43, 640, 1), new Rectangle(0, 481, 640, 1));

            TimeCalculator.softPause();
        }