/// <summary> /// Updates the loading screen. /// </summary> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); // If all the previous screens have finished transitioning // off, it is time to actually perform the load. if (otherScreensAreGone) { TankWars.RemoveScreen(this); foreach (GameScreen screen in screensToLoad) { if (screen != null) { TankWars.AddScreen(screen); } } // Once the load has finished, we use ResetElapsedTime to tell // the game timing mechanism that we have just finished a very // long frame, and that it should not try to catch up. TankWars.ResetElapsedTime(); } }
int reloadTime; //remaining time till reloaded /// <summary> /// Tank Constructor /// <param name="inGame"> /// Game this tank belongs to /// </param> /// <param name="playerNumber"> /// Sets whether tank is tank 1 or tank 2 /// </param> /// </summary> public Tank(TankWars inGame, Byte playerNumber) : base(inGame) { game = inGame; sprite = game.Content.Load <Texture2D>("Tank"); direction = 0; switch (playerNumber) { case 1: forward = Keys.Up; backward = Keys.Down; turnLeft = Keys.Left; turnRight = Keys.Right; fire = Keys.Space; break; case 2: forward = Keys.W; backward = Keys.S; turnLeft = Keys.A; turnRight = Keys.D; fire = Keys.LeftShift; break; } }
int reloadTime; //remaining time till reloaded /// <summary> /// Tank Constructor /// <param name="inGame"> /// Game this tank belongs to /// </param> /// <param name="playerNumber"> /// Sets whether tank is tank 1 or tank 2 /// </param> /// </summary> public Tank(TankWars inGame, Byte playerNumber) : base(inGame) { game = inGame; sprite = game.Content.Load<Texture2D>("Tank"); direction = 0; switch (playerNumber) { case 1: forward = Keys.Up; backward = Keys.Down; turnLeft = Keys.Left; turnRight = Keys.Right; fire = Keys.Space; break; case 2: forward = Keys.W; backward = Keys.S; turnLeft = Keys.A; turnRight = Keys.D; fire = Keys.LeftShift; break; } }
/// <summary> /// Bullet Constructor /// </summary> /// <param name="game"> /// Game this bullet belongs to /// </param> /// <param name="inPosition"> /// Starting position /// </param> /// <param name="inDirection"> /// Starting direction /// </param> public Bullet(TankWars game, Vector2 inPosition, float inDirection) : base(game) { sprite = game.Content.Load<Texture2D>("Bullet"); direction = inDirection; position = inPosition; }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (TankWars game = new TankWars()) { game.Run(); } }
public override void Draw(GameTime gameTime) { SpriteBatch spriteBatch = TankWars.SpriteBatch; SpriteFont font = TankWars.Font; TankWars.FadeBackBufferToBlack(TransitionAlpha * 2 / 3); Viewport viewport = TankWars.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = font.MeasureString(message); Vector2 textPosition = (viewportSize - textSize) / 2; const int hPad = 32; const int vPad = 16; Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad, (int)textPosition.Y - vPad, (int)textSize.X + hPad * 2, (int)textSize.Y + vPad * 2); Color color = Color.White * TransitionAlpha; spriteBatch.Begin(); spriteBatch.Draw(gradientTexture, backgroundRectangle, Color.Orange); spriteBatch.DrawString(font, message, textPosition, color); spriteBatch.End(); }
/// <summary> /// Bullet Constructor /// </summary> /// <param name="game"> /// Game this bullet belongs to /// </param> /// <param name="inPosition"> /// Starting position /// </param> /// <param name="inDirection"> /// Starting direction /// </param> public Bullet(TankWars game, Vector2 inPosition, float inDirection) : base(game) { sprite = game.Content.Load <Texture2D>("Bullet"); direction = inDirection; position = inPosition; }
protected override void OnCancel() { const string message = "Are you sure you want to exit Tank Wars?"; MessageBoxScreen confirmExitMessageBox = new MessageBoxScreen(message); confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted; TankWars.AddScreen(confirmExitMessageBox); }
void QuitGameMenuEntrySelected(object sender, EventArgs e) { const string message = "Are you sure you want to quit current game?"; MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message); confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted; TankWars.AddScreen(confirmQuitMessageBox); }
void RestartMissionMenuEntrySelected(object sender, EventArgs e) { GameplayScreen gameplayScreen = (GameplayScreen)TankWars.GetScreen(typeof(GameplayScreen)); if (gameplayScreen != null) { gameplayScreen.Initialize(); ExitScreen(); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(TankWars.Services, "Content"); } // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. TankWars.ResetElapsedTime(); }
// Xử lý trường hợp người chơi nhấn Esc public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } if (!Player.IsDead) { Player.HandleInput(input); Cursor.HandleInput(input); } if (input.IsPauseGame) { Content.Audio.BackgroundBattlefieldLoop.Pause(); TankWars.AddScreen(new PauseMenuScreen()); } }
/// <summary> /// Draws the loading screen. /// </summary> public override void Draw(GameTime gameTime) { // If we are the only active screen, that means all the previous screens // must have finished transitioning off. We check for this in the Draw // method, rather than in Update, because it isn't enough just for the // screens to be gone: in order for the transition to look good we must // have actually drawn a frame without them before we perform the load. if ((ScreenState == ScreenState.Active) && (TankWars.GetScreens().Length == 1)) { otherScreensAreGone = true; } // The gameplay screen takes a while to load, so we display a loading // message while that is going on, but the menus load very quickly, and // it would look silly if we flashed this up for just a fraction of a // second while returning from the game to the menus. This parameter // tells us how long the loading is going to take, so we know whether // to bother drawing the message. if (loadingIsSlow) { SpriteBatch spriteBatch = TankWars.SpriteBatch; SpriteFont font = TankWars.Font; const string message = "Loading..."; // Center the text in the viewport. Viewport viewport = TankWars.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = font.MeasureString(message); Vector2 textPosition = (viewportSize - textSize) / 2; Color color = Color.White * TransitionAlpha; // Draw the text. spriteBatch.Begin(); spriteBatch.DrawString(font, message, textPosition, color); spriteBatch.End(); } }
/// <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)*/); 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> /// 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()); } } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(TankWars.Services, "Content"); } Content = new Content(); Content.Font.HUDFont = content.Load <SpriteFont>(@"Fonts\HUDFont"); // Load tất cả các Textures cần thiết Content.Texture.Cursor = content.Load <Texture2D>(@"Texture\Cursor"); Content.Texture.Direction = content.Load <Texture2D>(@"Texture\Direction"); Content.Texture.TankBot = content.Load <Texture2D>(@"Texture\TankBot"); Content.Texture.TankTop = content.Load <Texture2D>(@"Texture\TankTop"); Content.Texture.HumveeBot = content.Load <Texture2D>(@"Texture\HumveeBot"); Content.Texture.HumveeTop = content.Load <Texture2D>(@"Texture\HumveeTop"); Content.Texture.Bullet = content.Load <Texture2D>(@"Texture\Bullet"); Content.Texture.Missile = content.Load <Texture2D>(@"Texture\Missile"); Content.Texture.SmallLaserRay = content.Load <Texture2D>(@"Texture\SmallLaserRay"); Content.Texture.BigLaserRay = content.Load <Texture2D>(@"Texture\BigLaserRay"); Content.Texture.MiniMapRectangle = content.Load <Texture2D>(@"Texture\MiniMapRectangle"); Content.Texture.Dirt = content.Load <Texture2D>(@"Texture\Dirt"); Content.Texture.TileSheet = content.Load <Texture2D>(@"Texture\TileSheet"); Content.Texture.PowerSheet = content.Load <Texture2D>(@"Texture\PowerSheet"); Content.Texture.BarSheet = content.Load <Texture2D>(@"Texture\BarSheet"); Content.Texture.SmallFlameSheet = content.Load <Texture2D>(@"Texture\SmallFlameSheet"); Content.Texture.BigFlameSheet = content.Load <Texture2D>(@"Texture\BigFlameSheet"); Content.Texture.BulletImpactSheet = content.Load <Texture2D>(@"Texture\BulletImpactSheet"); Content.Texture.MissileImpactSheet = content.Load <Texture2D>(@"Texture\MissileImpactSheet"); Content.Texture.LaserImpactSheet = content.Load <Texture2D>(@"Texture\LaserImpactSheet"); Content.Texture.EnergyImpactSheet = content.Load <Texture2D>(@"Texture\EnergyImpactSheet"); Content.Texture.ExplosionSheet = content.Load <Texture2D>(@"Texture\ExplosionSheet"); Content.Texture.Blank = content.Load <Texture2D>(@"Texture\Blank"); // Load tất cả các Sounds cần thiết Content.Audio.BulletFiring = content.Load <SoundEffect>(@"Audio\BulletFiring"); Content.Audio.BulletImpact = content.Load <SoundEffect>(@"Audio\BulletImpact"); Content.Audio.MissileFiring = content.Load <SoundEffect>(@"Audio\MissileFiring"); Content.Audio.MissileImpact = content.Load <SoundEffect>(@"Audio\MissileImpact"); Content.Audio.SmallLaserRayFiring = content.Load <SoundEffect>(@"Audio\SmallLaserRayFiring"); Content.Audio.SmallLaserRayImpact = content.Load <SoundEffect>(@"Audio\SmallLaserRayImpact"); Content.Audio.BigLaserRayFiring = content.Load <SoundEffect>(@"Audio\BigLaserRayFiring"); Content.Audio.BigLaserRayImpact = content.Load <SoundEffect>(@"Audio\BigLaserRayImpact"); Content.Audio.Explosion = content.Load <SoundEffect>(@"Audio\Explosion"); Content.Audio.PowerSwitch = content.Load <SoundEffect>(@"Audio\PowerSwitch"); Content.Audio.TankMove = content.Load <SoundEffect>(@"Audio\TankMove"); Content.Audio.TankMoving = Content.Audio.TankMove.CreateInstance(); Content.Audio.Regenerate = content.Load <SoundEffect>(@"Audio\Regenerate"); Content.Audio.Regenerating = Content.Audio.Regenerate.CreateInstance(); Content.Audio.BackgroundBattlefield = content.Load <SoundEffect>(@"Audio\BackgroundBattlefield"); Content.Audio.BackgroundBattlefieldLoop = Content.Audio.BackgroundBattlefield.CreateInstance(); Content.Audio.BackgroundBattlefieldLoop.IsLooped = true; Content.Audio.BackgroundBattlefieldLoop.Volume = 0.2f; Content.Audio.MissionAccomplish = content.Load <SoundEffect>(@"Audio\MissionAccomplish"); Content.Audio.MissionAccomplished = Content.Audio.MissionAccomplish.CreateInstance(); Content.Audio.MissionFail = content.Load <SoundEffect>(@"Audio\MissionFail"); Content.Audio.MissionFailed = Content.Audio.MissionFail.CreateInstance(); Initialize(); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. TankWars.ResetElapsedTime(); }
public override void FinishedLaunching (MonoMac.Foundation.NSObject notification) { game = new TankWars(); game.Run (); }
void SinglePlayerMenuEntrySelected(object sender, EventArgs e) { TankWars.AddScreen(new SinglePlayerMenuScreen()); }
void OptionsMenuEntrySelected(object sender, EventArgs e) { TankWars.AddScreen(new OptionsMenuScreen()); }
void AboutMenuEntrySelected(object sender, EventArgs e) { TankWars.AddScreen(new AboutMenuScreen()); }
public override void FinishedLaunching(MonoMac.Foundation.NSObject notification) { game = new TankWars(); game.Run(); }
void ConfirmExitMessageBoxAccepted(object sender, EventArgs e) { TankWars.Exit(); }