Пример #1
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     // TODO: Add your initialization logic here
     graphics.PreferredBackBufferHeight = 700;
     graphics.PreferredBackBufferWidth  = 1200;
     graphics.ApplyChanges();
     this.IsMouseVisible = true;
     gameVelocity        = 0.5f;//0-5->0.7
     myGround            = new Ground(0, 500, gameVelocity);
     myChar     = new Character(200, 500 - myGround.Height - 100, 80);
     myBird     = new Bird(1200, 250, gameVelocity * 1.5f);//pos:350 or 250
     mySaw1     = new Saw(1200, 400 - myGround.Height, gameVelocity);
     mySaw2     = new Saw(1800, 400 - myGround.Height, gameVelocity);
     mySaw3     = new Saw(1900, 400 - myGround.Height, gameVelocity);
     isGameOver = false;
     preScore   = -1;
     curScore   = 0;
     base.Initialize();
 }
        public void AddSawCollisionListener(Saw other)
        {
            bool isCollided = false;

            if (State == 2)
            {
                Rectangle r1 = new Rectangle((int)PosX, (int)PosY + 20, 100, 80);
                Rectangle r2 = new Rectangle((int)other.PosX, (int)other.PosY, 100, 100);
                isCollided = r1.Intersects(r2);
            }
            else
            {
                Rectangle r1 = new Rectangle((int)PosX, (int)PosY, 100, 100);
                Rectangle r2 = new Rectangle((int)other.PosX, (int)other.PosY, 100, 100);
                isCollided = r1.Intersects(r2);
            }

            if (isCollided && Collide != null)
            {
                this.Collide(this, new EventArgs());
            }
        }