Exemple #1
0
 public bool Collides(ClassSprite other)  //回傳當圖片碰到板子的時候的反應
 {
     return(this.position.X + texture.Width > other.position.X &&
            this.position.X < other.position.X + other.texture.Width &&
            this.position.Y + texture.Height > other.position.Y &&
            this.position.Y < other.position.Y + other.texture.Height);
 }
Exemple #2
0
        /// <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);

            Sf         = Content.Load <SpriteFont>("SpriteFont1");//將文字給讀取進來
            myt        = Content.Load <Texture2D>("BOLL");
            brickImage = Content.Load <Texture2D>("brick1");
            //做一個板子
            int gx = 64;
            int gy = 16;

            myt1 = new Texture2D(this.GraphicsDevice, gx, gy, true, this.graphics.PreferredBackBufferFormat);
            Color[] color = new Color[gx * gy];
            for (int i = 0; i < gx * gy; i++)
            {
                color[i] = new Color(150, 0, 255, 255);
            }
            myt1.SetData(color);

            myclass2 = new ClassSprite(myt1, new Vector2(graphics.GraphicsDevice.Viewport.Width / 2 - myt1.Width / 2, graphics.GraphicsDevice.Viewport.Height - 20), new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height)); //設定ClassSprite的三個參數

            myclass          = new ClassSprite(myt, new Vector2(myclass2.position.X, myclass2.position.Y - 200), new Vector2(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height));                                                         //設定ClassSprite的三個參數
            myclass.velocity = new Vector2(5, 3);                                                                                                                                                                                                                       //設定球的移動速度

            /*for (int i = 0; i < 6; i++)
             * {
             *  for(int j = 0; j<0; j++)
             *  {
             *      block[i, j] = new ClassSprite();
             *  }
             * }*/
            // TODO: use this.Content to load your game content here
        }