Exemple #1
0
 public int Shot(ref Sight sight, ref UFOList ufoList)
 {
     int shotedUFO = 0;
     var sightCentreVector2 = new Vector2(sight.rectangle.X + sight.rectangle.Width/2, sight.rectangle.Y + sight.rectangle.Height/2);
     if (Mouse.GetState().LeftButton == ButtonState.Pressed)
     {
         foreach (var ufo in ufoList)
         {
             if (ufo.rectangle.Contains(Convert.ToInt32(sightCentreVector2.X), Convert.ToInt32(sightCentreVector2.Y)))
             {
                 if (ufo.state != UFOState.Fall)
                 {
                     ufo.state = UFOState.Fall;
                     shotedUFO++;
                 }
             }
         }
     }
     return shotedUFO;
 }
Exemple #2
0
 public int FlyAway(ref UFOList ufoList, SoundEffectInstance flyAwaySong)
 {
     var flyingUfoesList = new UFOList();
     foreach (var ufo in ufoList)
     {
         if ((((ufo.rectangle.X + ufo.rectangle.Width) < 0) || (ufo.rectangle.Y + ufo.rectangle.Height < 0)) && (ufo.state == UFOState.Fly))
         {
             if (flyingUfoesList.Contains(ufo) == false)
             {
                 flyingUfoesList.Add(ufo);
                 flyAwaySong.Play();
             }
         }
     }
     int flyingufoes = flyingUfoesList.Count;
     foreach (var fly in flyingUfoesList)
     {
         ufoList.Remove(fly);
     }
     return flyingufoes;
 }
Exemple #3
0
 void NewGame()
 {
     levels.NewGame();
     var currentLevel = levels.currentLevel;
     ufoList = new UFOList(currentLevel.ufoCount, currentLevel.minSpeed, currentLevel.maxSpeed,
                         textureForUFO, screenWidth, screenHeight);
     user.lives = 3;
     user.points = 0;
 }
Exemple #4
0
 protected override void Update(GameTime gameTime)
 {
     if (menu.GetState == MenuState.Closed)
     {
         if (MediaPlayer.State == MediaState.Stopped)
         {
             MediaPlayer.Play(mainSong);
         }
         if (levels.isEndGame == false)
         {
             if (ufoList.Count == 0)
             {
                 levels.NextLevel();
                 var currentLevel = levels.currentLevel;
                 if (currentLevel != null)
                 {
                     ufoList = new UFOList(currentLevel.ufoCount, currentLevel.minSpeed, currentLevel.maxSpeed,
                         textureForUFO, screenWidth, screenHeight);
                 }
             }
             if ((user.lives > 0) && (ufoList.Count > 0))
             {
                 if (action.IsPause == false)
                 {
                     sight.Update(screenWidth, screenHeight);
                     ufoList.Update(screenWidth, screenHeight);
                     user.points += action.Shot(ref sight, ref ufoList);
                     user.lives -= action.FlyAway(ref ufoList, flyAwaySoundInstance);
                     if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                     {
                         shotSongInstance.Play();
                     }
                 }
             }
         }
     }
     else
     {
         gameState = menu.Update();
     }
     if ((Keyboard.GetState().IsKeyDown(Keys.R)) || (gameState == GameState.NewGame))
     {
         NewGame();
         gameState = GameState.ContinuePlay;
     }
     else if (gameState == GameState.Exit)
     {
         Exit();
     }
     base.Update(gameTime);
 }
Exemple #5
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     sight = new Sight(Content.Load<Texture2D>("sight"), new Rectangle(0, 0, 50, 50));
     textureForUFO = Content.Load<Texture2D>("ufo");
     var currentLevel = levels.currentLevel;
     ufoList = new UFOList(currentLevel.ufoCount, currentLevel.minSpeed, currentLevel.maxSpeed,
                 textureForUFO, screenWidth, screenHeight);
     backgroundTexture2D = Content.Load<Texture2D>("background");
     backgroundForWinnerTexture2D = Content.Load<Texture2D>("forWinner");
     backgroundForLoserTexture2D = Content.Load<Texture2D>("forLoser");
     shotSongEffect = Content.Load<SoundEffect>("shot");
     shotSongInstance = shotSongEffect.CreateInstance();
     flyAwaySound = Content.Load<SoundEffect>("homer");
     flyAwaySoundInstance = flyAwaySound.CreateInstance();
     mainSong = Content.Load<Song>("mainSong");
     spriteFont = Content.Load<SpriteFont>("font1");
     menu.Load(Content.Load<Texture2D>("logo"), Content.Load<Texture2D>("menuBackground"), Content.Load<Texture2D>("newGame"),
         Content.Load<Texture2D>("exit"), Content.Load<Song>("x-files"));
 }