Пример #1
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            /*  LOAD TEXTURES, SOUNDS AND FONTS */
            ScreenTexture = new Texture2D(ScreenManager.GraphicsDevice, 1, 1);
            ScreenTexture.SetData(new Color[] { Color.White });
            paddle = content.Load <Texture2D>("Pong\\Textures\\pongpaddle");
            ball   = content.Load <Texture2D>("Pong\\Textures\\pongball");

            pause     = content.Load <SoundEffect>("DuckHunt\\Sounds\\pause");
            paddlehit = content.Load <SoundEffect>("Pong\\Sounds\\paddlehit");
            wallhit   = content.Load <SoundEffect>("Pong\\Sounds\\wallbounce");
            balldie   = content.Load <SoundEffect>("Pong\\Sounds\\deadball");

            m_score_fnt = content.Load <SpriteFont>("Fonts\\hugenesfont");

            /* Create Players */
            m_player1 = new Paddle(0, paddle, boxrec);
            m_player2 = new Paddle(1, paddle, boxrec);

            CollisionData[] temp = new CollisionData[4];

            temp[0] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + -81, 1024, 80));
            temp[1] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + 613, 1024, 80));
            temp[2] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + -81, HelperUtils.SafeBoundary.Y, 80, 612));
            temp[3] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.Y, 80, 612));

            /* Create Ball */
            m_ball = new PongBall(temp, paddlehit, wallhit);
            m_ball.AddAnimation(new Sprite(ball));
            m_ball.SetCurrentAnimation(0);
            m_ball.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2;
            m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Height - ball.Height);

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            Thread.Sleep(1000);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #2
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            /*  LOAD TEXTURES, SOUNDS AND FONTS */
            ScreenTexture = new Texture2D(ScreenManager.GraphicsDevice, 1, 1);
            ScreenTexture.SetData(new Color[] { Color.White });
            paddle = content.Load<Texture2D>("Pong\\Textures\\pongpaddle");
            ball = content.Load<Texture2D>("Pong\\Textures\\pongball");

            pause = content.Load<SoundEffect>("DuckHunt\\Sounds\\pause");
            paddlehit = content.Load<SoundEffect>("Pong\\Sounds\\paddlehit");
            wallhit = content.Load<SoundEffect>("Pong\\Sounds\\wallbounce");
            balldie = content.Load<SoundEffect>("Pong\\Sounds\\deadball");

            m_score_fnt = content.Load<SpriteFont>("Fonts\\hugenesfont");

              /* Create Players */
            m_player1 = new Paddle(0, paddle, boxrec);
            m_player2 = new Paddle(1, paddle, boxrec);

            CollisionData[] temp = new CollisionData[4];

            temp[0] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + -81, 1024, 80));
            temp[1] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + 613, 1024, 80));
            temp[2] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + -81, HelperUtils.SafeBoundary.Y, 80, 612));
            temp[3] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.Y, 80, 612));

              /* Create Ball */
            m_ball = new PongBall(temp , paddlehit, wallhit);
            m_ball.AddAnimation(new Sprite(ball));
            m_ball.SetCurrentAnimation(0);
            m_ball.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2;
            m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Height - ball.Height);

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            Thread.Sleep(1000);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }