Ejemplo n.º 1
0
 public void Draw(SpaceShip spaceShip)
 {
     if (Visible)
     {
         if (!spaceShip.Visible)
         {
             ufoSoundInstance.Pause();
         }
         else if (ufoSoundInstance.State != SoundState.Playing)
         {
             ufoSoundInstance.Play();
         }
         spriteBatch.Draw(imgUFO, new Vector2(X, Y), null, Color.Red, 0, new Vector2(0, 0), 0.2f, SpriteEffects.None, 0);
     }
 }
Ejemplo n.º 2
0
        public void ShootSpaceShip(SpaceShip spaceShip)
        {
            Rectangle blasterRect = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);

            if (spaceShip.Visible && Visible)
            {
                Rectangle spaceShipRect = new Rectangle((int)spaceShip.X, (int)spaceShip.Y, (int)spaceShip.Width, (int)spaceShip.Height);
                if (HitTest(blasterRect, spaceShipRect))
                {
                    PlaySound(gameContent.explodeSound);
                    Visible = false;
                    spaceShip.ExplodeSpaceShip();
                }
            }
        }
Ejemplo n.º 3
0
        public void FireBlasters(SpaceShip spaceShip, Shield[] shields, int fireRate)
        {
            Random random = new Random();

            foreach (Alien alien in aliens)
            {
                int r = random.Next(0, fireRate);
                if (r == 0)
                {
                    alien.fireBlaster();
                }
                foreach (Blaster blaster in alien.blasters)
                {
                    blaster.Fire();
                    foreach (Shield shield in shields)
                    {
                        blaster.ShootShield(shield);
                    }
                    blaster.ShootSpaceShip(spaceShip);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            gameContent  = new GameContent(Content);
            screenWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            screenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            if (screenWidth >= 2500)
            {
                screenWidth = 2500;
            }
            if (screenHeight >= 1250)
            {
                screenHeight = 1250;
            }
            graphics.PreferredBackBufferWidth  = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;
            graphics.ApplyChanges();
            speed1 = gameContent.speed1Sound.CreateInstance();
            speed2 = gameContent.speed2Sound.CreateInstance();
            speed3 = gameContent.speed3Sound.CreateInstance();
            speed4 = gameContent.speed4Sound.CreateInstance();

            int spaceShipX = (screenWidth - gameContent.imgSpaceShip.Width / 4) / 2;
            int spaceShipY = screenHeight - 150;

            spaceShip = new SpaceShip(spaceShipX, spaceShipY, screenWidth, spriteBatch, gameContent);
            shields   = new Shield[3];
            for (int x = 0; x < 3; x++)
            {
                shields[x] = new Shield(screenWidth / 3 * x + screenWidth / 8, spaceShip.Y - 150, spriteBatch, GraphicsDevice);
            }
            alienFleet = new AlienFleet(50, 150, screenWidth, spaceShip.Y, spriteBatch, gameContent);

            ufo = new UFO(0, 60, screenWidth, spriteBatch, gameContent);

            gameBorder = new GameBorder(screenWidth, screenHeight, spriteBatch, gameContent);
        }
Ejemplo n.º 5
0
        public void RestartGame()
        {
            livesRemaining = 3;
            aliensKilled   = 0;
            alienFireRate  = 5000;
            firstTime      = false;
            hitBottom      = false;
            level          = 1;
            score          = 0;
            int spaceShipX = (screenWidth - gameContent.imgSpaceShip.Width / 4) / 2;
            int spaceShipY = screenHeight - 150;

            spaceShip = new SpaceShip(spaceShipX, spaceShipY, screenWidth, spriteBatch, gameContent);
            shields   = new Shield[3];
            for (int x = 0; x < 3; x++)
            {
                shields[x] = new Shield(screenWidth / 3 * x + screenWidth / 8, spaceShip.Y - 150, spriteBatch, GraphicsDevice);
            }
            alienFleet = new AlienFleet(50, 150, screenWidth, spaceShip.Y, spriteBatch, gameContent);

            ufo = new UFO(0, 60, screenWidth, spriteBatch, gameContent);

            gameBorder = new GameBorder(screenWidth, screenHeight, spriteBatch, gameContent);
        }