/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Draw(GameTime gameTime) { // Màu nền TankWars.GraphicsDevice.Clear(Color.Black); // Dùng để vẽ các đối tượng SpriteBatch spriteBatch = TankWars.SpriteBatch; spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend /*, null, null, null, null, Camera.get_transformation(Game.GraphicsDevice)*/); // Vẽ Màn chơi Map.Draw(gameTime, spriteBatch); foreach (PowerIcon power in PowerIconList) { power.Draw(gameTime, spriteBatch); } // Vẽ Minimap Minimap.Draw(gameTime, spriteBatch); // Vẽ cursor người chơi Cursor.Draw(gameTime, spriteBatch); // Vẽ người chơi if (!Player.IsDead) { Player.Draw(gameTime, spriteBatch); Direction.Draw(gameTime, spriteBatch); Minimap.DrawDot(Player, Color.Blue, spriteBatch); } // Vẽ Health Bar HealthBar.Draw(Player.HitPoints, Player.MaxHitPoints, spriteBatch); // Vẽ Energy Bar EnergyBar.Draw(Player.EnergyPoints, Player.MaxEnergyPoints, spriteBatch); // Vẽ đạn foreach (Ammunition ammunition in AmmunitionList) { ammunition.Draw(gameTime, spriteBatch); } // Vẽ các vụ nổ foreach (Sprite effect in EffectList) { effect.Draw(gameTime, spriteBatch); } // Vẽ Enemy foreach (Tank enemy in EnemyList) { enemy.Draw(gameTime, spriteBatch); Minimap.DrawDot(enemy, Color.Red, spriteBatch); } spriteBatch.End(); // If the game is transitioning on or off, fade it out to black. if (TransitionPosition > 0 || pauseAlpha > 0) { float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2); TankWars.FadeBackBufferToBlack(alpha); } }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update (GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, false); // Gradually fade in or out depending on whether we are covered by the pause screen. if (coveredByOtherScreen) { pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1); } else { pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0); } if (IsActive) { Content.Audio.BackgroundBattlefieldLoop.Play(); Camera.Update(gameTime); Cursor.Update(gameTime); Minimap.Update(gameTime); // Update Sprite người chơi và các thao tác điều khiển if (!Player.IsDead) { Player.Update(gameTime); Direction.Update(gameTime); } // Update các viên đạn đã đc bắn ra for (CurrentListItem = 0; CurrentListItem < AmmunitionList.Count; CurrentListItem++) { Ammunition ammunition = AmmunitionList[CurrentListItem]; ammunition.Update(gameTime); } // Update các vụ nổ for (CurrentListItem = 0; CurrentListItem < EffectList.Count; CurrentListItem++) { Sprite effect = EffectList[CurrentListItem]; effect.Update(gameTime); } // Update Enemy RandomMovableEnemy(); for (CurrentListItem = 0; CurrentListItem < EnemyList.Count; CurrentListItem++) { Tank enemy = EnemyList[CurrentListItem]; enemy.Update(gameTime); } foreach (PowerIcon power in PowerIconList) { power.Update(gameTime); } if (Player.IsDead) { MissionEndDelay += gameTime.ElapsedGameTime; if (MissionEndDelay >= TimeSpan.FromSeconds(2)) { Content.Audio.MissionFailed.Play(); Content.Audio.BackgroundBattlefieldLoop.Pause(); TankWars.AddScreen(new MissionFailedMenuScreen()); } } if (IsMissionAccomplished) { MissionEndDelay += gameTime.ElapsedGameTime; if (MissionEndDelay >= TimeSpan.FromSeconds(2)) { Content.Audio.MissionAccomplished.Play(); Content.Audio.BackgroundBattlefieldLoop.Pause(); if (IsCampaignAccomplished) { TankWars.AddScreen(new CampaignAccomplishedMenuScreen()); } else { TankWars.AddScreen(new MissionAccomplishedMenuScreen()); } } } } }