Exemplo n.º 1
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
     try {
     //animation.Update(gameTime.ElapsedGameTime.Ticks);
     try
     {
         foreach (NPC npc in new LinkedList<NPC>(npcs))
         {
             npc.Update(gameTime);
         }
     } catch (Exception e) {
         return;
     }
     switch (gameState)
     {
         case GameState.Begin:
             intro.StopVideo();
             if (Keyboard.GetState().IsKeyDown(Keys.End))
             {
                 intro.SkipVideo();
             }
             break;
         case GameState.GameOver:
         case GameState.Highscore:
         case GameState.Select:
         case GameState.Paused:
         case GameState.Upgrade:
         case GameState.Menu:
             IManager.Update();
             break;
         case GameState.InGame:
             IManager.Update();
             gameFrame.UpdateGifGameFrame(gameTime);
             arduino.sendMessage();
             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
             {
                 CurrentGameState = GameState.Paused;
                 break;
             }
             else if (Keyboard.GetState().IsKeyDown(Keys.PrintScreen))
             {
                 ScreenShot(DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                 break;
             }
             else if (Keyboard.GetState().IsKeyDown(Keys.Space))
             {
                 if (player.Wall.getLevel() == 1)
                 {
                     if (player.electricWallTimer == -1)
                     {
                         if (player.evilWall)
                         {
                             if (player.oil - 50 > 0)
                             {
                                 player.Wall.definition.ChangeTextureToElectric();
                                 player.electricWallTimer = 2000;
                                 player.oil -= 50;
                                 gameFrame.UpdateOil(player.oil);
                                 break;
                             }
                         }
                         else
                         {
                             player.Wall.definition.ChangeTextureToElectric();
                             player.electricWallTimer = 2000;
                             break;
                         }
                     }
                 }
             }
             lastWave += gameTime.ElapsedGameTime;
             if (lastWave.TotalMilliseconds >= LevelInformation.forValue(player.currentLevel).waveDelay)
             {
                 LevelInformation wave = LevelInformation.forValue(player.currentLevel);
                 if (!wave.bossSpawned)
                 {
                     bool spawnBoss = wave.currentSpawnedEnemiesAmount >= wave.amountOfEnemies && !wave.bossSpawned;
                     if (spawnBoss)
                     {
                         wave.bossSpawned = spawnBoss;
                         if (player.currentLevel == 1)
                         {
                             EnterFistBoss.PlaySound();
                         }
                         else if (player.currentLevel == 2)
                         {
                             enterSecondBoss.PlaySound();
                         }
                         else if (player.currentLevel == 3)
                         {
                             enterThirdBoss.PlaySound();
                         }
                     }
                     int typeToSpawn = spawnBoss ? wave.bossType : wave.npcTypes[random.Next(wave.npcTypes.Length)];
                     NPC npc = new NPC(typeToSpawn);
                     float maxY = GameFrame.Height - npc.definition.mainTexture.Height - 50;
                     float minY = GameFrame.Height / 2 + 75;
                     float y = random.Next((int)minY, (int)maxY);
                     if (y < minY)
                         y = minY;
                     else if (y > maxY)
                         y = maxY;
                     npc.setLocation(new Vector2(-npc.definition.mainTexture.Width, y));
                     npcs.AddLast(npc);
                     wave.currentSpawnedEnemiesAmount++;
                 }
                 lastWave = TimeSpan.Zero;
             }
             break;
     }
     info.Update(gameTime);
     base.Update(gameTime);
     }
     catch (Exception e)
     {
         return;
     }
 }