コード例 #1
0
ファイル: Game1.cs プロジェクト: karlo2k2/1.Zadaca
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var screenBounds = GraphicsDevice.Viewport.Bounds;

            Texture2D paddleTexture = Content.Load<Texture2D>("paddle");
            PaddleBottom = new Paddle(paddleTexture);
            PaddleTop = new Paddle(paddleTexture);
            PaddleBottom.Position = new Vector2(screenBounds.Bottom - PaddleBottom.Size.Height);
            PaddleBottom.Position.X = MathHelper.Clamp(PaddleBottom.Position.X,
                 graphics.GraphicsDevice.Viewport.Bounds.Left,
                 graphics.GraphicsDevice.Viewport.Bounds.Right - PaddleBottom.Size.Width);

            PaddleTop.Position = new Vector2(screenBounds.Top);

            Texture2D ballTexture = Content.Load<Texture2D>("ball");
            Ball = new Ball(ballTexture);
            Ball.Position = screenBounds.Center.ToVector2();

            Texture2D backgroundTexture = Content.Load<Texture2D>("background");
            Background = new Background(backgroundTexture, screenBounds.Width, screenBounds.Height);

            HitSound = Content.Load<SoundEffect>("hit");
            Music = Content.Load<Song>("music");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(Music);

            SpriteForDrawList.Add(Background);
            SpriteForDrawList.Add(PaddleBottom);
            SpriteForDrawList.Add(PaddleTop);
            SpriteForDrawList.Add(Ball);

        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: scoumbassa/1.-Zadaca
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Ask graphics device about screen bounds we are using. 
            var screenBounds = GraphicsDevice.Viewport.Bounds;

            // Load paddle texture using Content.Load static method 
            Texture2D paddleTexture = Content.Load<Texture2D>("paddle");

            // Create bottom and top paddles and set their initial position 
            PaddleBottom = new Paddle(paddleTexture);
            PaddleTop = new Paddle(paddleTexture);

            // Position both paddles with help screenBounds object 
            PaddleBottom.Position = new Vector2(0,screenBounds.Bottom - PaddleBottom.Size.Height);
            PaddleTop.Position = new Vector2(screenBounds.Top);

            // Load ball texture 
            Texture2D ballTexture = Content.Load<Texture2D>("ball");

            // Create new ball object and set its initial position 
            Ball = new Ball(ballTexture);
            Ball.Position = screenBounds.Center.ToVector2();
            // Load background texture and create a new background object. 
            Texture2D backgroundTexture = Content.Load<Texture2D>("background");
            Background = new Background(backgroundTexture, screenBounds.Width, 
                screenBounds.Height);

            // Load sounds 
            HitSound = Content.Load<SoundEffect>("hit");
            Music = Content.Load<Song>("music");
            MediaPlayer.IsRepeating = true;
            // Start playing background music 
            MediaPlayer.Play(Music);

            SpritesForDrawList.Add(Background);
            SpritesForDrawList.Add(PaddleBottom);
            SpritesForDrawList.Add(PaddleTop);
            SpritesForDrawList.Add(Ball);
        }