Пример #1
0
        // Basic Init //
        protected override void Initialize()
        {
            MediaPlayer.IsRepeating = true;

            hardpausedcalc = new TimeCalculator();
            softpausedcalc = new TimeCalculator();
            countdowntimer = new TimeCalculator();

            countdowntimer.pausedtime = 1;

            backgroundVector = new Vector2(0, 0);
            Lpaddle.setVector(new Vector2(0, 185));
            Rpaddle.setVector(new Vector2(618, 185));
            ball.setVector(new Vector2(320, 240));

            for (int counter = 0; counter < 6; counter++)
            {
                animatedcrystalarr[counter] = new PongSprite();
                outlinedcrystalarr[counter] = new PongSprite();
            }

            paddlemovespeed = 650;

            graphics.PreferredBackBufferWidth  = 640;
            graphics.PreferredBackBufferHeight = 480;
            graphics.ApplyChanges();

            base.Initialize();
        }
Пример #2
0
        // Time Calculation //
        private void updateTimes(GameTime gameTime)
        {
            if (ScoreBoard.gtime >= 0)
            {
                if (!TimeCalculator.hardpaused)
                {
                    ScoreBoard.gtime        = (GAME_LENGTH + lastpausedtime) - getTime(gameTime);
                    hardpausedcalc.lasttime = getTime(gameTime);
                }
                else
                {
                    hardpausedcalc.pausedtime = getTime(gameTime) - hardpausedcalc.lasttime;
                }

                if (TimeCalculator.softpaused)
                {
                    if (getTime(gameTime) - softpausedcalc.lasttime >= 3)
                    {
                        TimeCalculator.softResume();
                    }
                }
                else if (!TimeCalculator.softpaused)
                {
                    softpausedcalc.lasttime = getTime(gameTime);
                }
                else
                {
                }
            }
            else
            {
                if (RScore.score > LScore.score)
                {
                    RScore.incrementRGames();
                }
                else if (LScore.score > RScore.score)
                {
                    LScore.incrementLGames();
                }
                else if (LScore.score == RScore.score)
                {
                    LScore.incrementLGames();
                    RScore.incrementRGames();
                }
                else
                {
                }

                resetValues(gameTime);
                TimeCalculator.softPause();
            }
        }
Пример #3
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();
        }
Пример #4
0
        // Check Keyboard Input //
        private void checkKeys(GameTime gameTime)
        {
            keyState = Keyboard.GetState();

            // KeyPresses Allow For Paddle Movement //
            if (keyState.IsKeyDown(Keys.W))
            {
                if (!TimeCalculator.hardpaused)
                {
                    Lpaddle.alterVectorY(-paddlemovespeed * (float)gameTime.ElapsedGameTime.TotalSeconds);

                    if (Lpaddle.position.Y < 0 + lscore.boundingrect.Width)
                    {
                        Lpaddle.position.Y = 1 + lscore.boundingrect.Width;
                    }
                }
            }
            if (keyState.IsKeyDown(Keys.S))
            {
                if (!TimeCalculator.hardpaused)
                {
                    Lpaddle.alterVectorY(paddlemovespeed * (float)gameTime.ElapsedGameTime.TotalSeconds);

                    if (Lpaddle.position.Y > (480 - Lpaddle.boundingrect.Height))
                    {
                        Lpaddle.position.Y = (480 - Lpaddle.boundingrect.Height);
                    }
                }
            }
            if (keyState.IsKeyDown(Keys.Up))
            {
                if (!TimeCalculator.hardpaused)
                {
                    Rpaddle.alterVectorY(-paddlemovespeed * (float)gameTime.ElapsedGameTime.TotalSeconds);

                    if (Rpaddle.position.Y < 0 + lscore.boundingrect.Width)
                    {
                        Rpaddle.position.Y = 1 + lscore.boundingrect.Width;
                    }
                }
            }
            if (keyState.IsKeyDown(Keys.Down))
            {
                if (!TimeCalculator.hardpaused)
                {
                    Rpaddle.alterVectorY(paddlemovespeed * (float)gameTime.ElapsedGameTime.TotalSeconds);

                    if (Rpaddle.position.Y > (480 - Lpaddle.boundingrect.Height))
                    {
                        Rpaddle.position.Y = (480 - Lpaddle.boundingrect.Height);
                    }
                }
            }
            if (keyState.IsKeyDown(Keys.Escape))
            {
                if (!TimeCalculator.hardpaused)
                {
                    hardpausedcalc.pausedtime = 0;
                    TimeCalculator.hardPause();
                }
            }
            if (keyState.IsKeyDown(Keys.F1))
            {
                if (TimeCalculator.hardpaused)
                {
                    lastpausedtime += hardpausedcalc.pausedtime;
                    TimeCalculator.hardResume();
                }
            }
        }
Пример #5
0
        // Angular Collision Logic. Passed An Enumerator That Denotes What Critical Area Was Hit (Either A Wall, Paddle, Or Score Zone) //
        private void changeAngle(int condition)
        {
            if (condition == (int)Intersection.Left)
            {
                Jukebox.playScore();
                RScore.incrementRScore();
                ballmovespeed = 200;
                this.setVector(new Vector2(320, 240));

                if (!TimeCalculator.softpaused)
                {
                    TimeCalculator.softPause();
                }
            }
            else if (condition == (int)Intersection.Right)
            {
                Jukebox.playScore();
                LScore.incrementLScore();
                ballmovespeed = 200;
                this.setVector(new Vector2(320, 240));

                if (!TimeCalculator.softpaused)
                {
                    TimeCalculator.softPause();
                }
            }
            else if (condition == (int)Intersection.Top)
            {
                Jukebox.playWallHit();
                if (lastX - position.X < 0)
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.UpLeft;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.DownRight;
                    }
                }
                else
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.UpRight;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.DownLeft;
                    }
                }
            }
            else if (condition == (int)Intersection.Bot)
            {
                Jukebox.playWallHit();
                if (lastX - position.X < 0)
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.UpRight;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.DownLeft;
                    }
                }
                else
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.UpLeft;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.UpLeft;
                    }
                }
            }
            else if (condition == (int)Intersection.LeftPaddle)
            {
                Jukebox.playPaddleHit();
                if (lastX - position.X < 0)
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.DownLeft;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.UpLeft;
                    }
                }
                else
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.DownRight;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.UpRight;
                    }
                }

                increaseSpeed();
            }
            else if (condition == (int)Intersection.RightPaddle)
            {
                Jukebox.playPaddleHit();
                if (lastX - position.X < 0)
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.DownLeft;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.UpLeft;
                    }
                }
                else
                {
                    if (lastY - position.Y < 0)
                    {
                        diagonal = (int)Diagonal.UpRight;
                    }
                    else
                    {
                        diagonal = (int)Diagonal.DownRight;
                    }
                }

                increaseSpeed();
            }
            else
            {
            }
        }