using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Controls; using Penguloon.Levels; using Penguloon.Scenes; using System; namespace Penguloon.Scenes { public class GameScene : SceneBase { public LevelBase Level { get; set; } public float Speed { get; set; } = 1f; public ButtonIngame StartRoundBtn { get; set; } public SpeedButton ChangeSpeedBtn { get; set; } public ButtonIngame OptionsBtn { get; set; } public IngameOptions OptionsMenu { get; set; } public ObjectSelector ObjectSeletor { get; set; } public GameScene(Main main, LevelBase level) : base(main) { this.Level = level; this.Level.Initialize(this); StartRoundBtn = new ButtonIngame(this, new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight), new Vector2(StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), StaticUIValues.IngameUIPlayButtonHeight), Main.Resources.GetString(Resource.String.IngameStart)); OptionsBtn = new ButtonIngame(this, new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth), new Vector2(StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), StaticUIValues.IngameUIPlayButtonHeight), Main.Resources.GetString(Resource.String.IngameOptions)); ChangeSpeedBtn = new SpeedButton(this, new Vector2(Level.Map.MapWidth - StaticUIValues.ChangeSpeedButtonWidth, StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight), new Vector2(StaticUIValues.ChangeSpeedButtonWidth, StaticUIValues.IngameUIPlayButtonHeight), "X1"); OptionsMenu = new IngameOptions(this, new Vector2((StaticUIValues.ScreenViewport.X / 2) - (StaticUIValues.IngameOptionsSize.X / 2), (StaticUIValues.ScreenViewport.Y / 2) - (StaticUIValues.IngameOptionsSize.Y / 2)), StaticUIValues.IngameOptionsSize); ChangeSpeedBtn.OnClick += ChangeSpeedBtn_OnClick; StartRoundBtn.OnClick += StartRoundBtn_OnClick; OptionsBtn.OnClick += OptionsBtn_OnClick; ObjectSeletor = new ObjectSelector(level.Map, this, new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight + StaticUIValues.BorderWidth), new Vector2((int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUITextAreaHeight - StaticUIValues.BorderWidth - StaticUIValues.BorderWidth - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth - StaticUIValues.IngameUIPlayButtonHeight)); } private void OptionsBtn_OnClick(object sender, ClickArgs e) { if (OptionsMenu.State == IngameOptionsState.Hide) { OptionsMenu.ShowTime = DateTime.Now; OptionsMenu.State = IngameOptionsState.Show; } } private void ChangeSpeedBtn_OnClick(object sender, ClickArgs e) { switch (Speed) { case 1f: Speed = 2f; break; case 2f: Speed = 3f; break; case 3f: Speed = 1f; break; default: Speed = 1f; break; } ChangeSpeedBtn.Text = "X" + Math.Round(Speed, 0).ToString(); } private void StartRoundBtn_OnClick(object sender, ClickArgs e) { Level.Map.WaveManager.StartSpawningEnemies(); ButtonIngame btn = (ButtonIngame)sender; btn.ControlState = ControlState.Disabled; } public override void CreateControls() { } public override void Draw(float deltaTime) { // background Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/background"), destinationRectangle: new Rectangle(0, 0, (int)StaticUIValues.ScreenViewport.X, (int)StaticUIValues.ScreenViewport.Y)); base.Draw(deltaTime); this.Level.Draw(deltaTime); DrawUI(deltaTime); StartRoundBtn.Draw(deltaTime); ObjectSeletor.Draw(deltaTime); ChangeSpeedBtn.Draw(deltaTime); OptionsBtn.Draw(deltaTime); OptionsMenu.Draw(deltaTime); } private void DrawUI(float deltaTime) { //background Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBackground"), destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth), (int)StaticUIValues.ScreenViewport.Y)); //border Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border"), destinationRectangle: new Rectangle(Level.Map.MapWidth, 0, StaticUIValues.BorderWidth, (int)StaticUIValues.ScreenViewport.Y)); //border under text Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, StaticUIValues.IngameUITextAreaHeight, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth - 5), StaticUIValues.BorderWidth)); //border above options Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, (int)StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth - 5), StaticUIValues.BorderWidth)); //border above button Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/border-horizontal"), destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth - 4, (int)StaticUIValues.ScreenViewport.Y - StaticUIValues.IngameUIPlayButtonHeight - StaticUIValues.BorderWidth, (int)StaticUIValues.ScreenViewport.X - (Level.Map.MapWidth + StaticUIValues.BorderWidth - 5), StaticUIValues.BorderWidth)); DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Gold: " + Level.Money, new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 10), new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), TextAllignment.LeftTop, Color.White, Color.Black, 2); DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Wave: " + Level.Map.WaveManager.CurrentWave.ToString(), new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0), new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), TextAllignment.LeftMiddle, Color.White, Color.Black, 2); DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), "Health: " + Level.Health, new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0), new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), TextAllignment.LeftBottom, Color.White, Color.Black, 2); } public override void Update(float deltaTime, TouchLocation[] touchLocations) { // We shouldn't update controls when the game is finished to prevent the user from placing any more objects if (!Level.Finished) { base.Update(deltaTime, touchLocations); StartRoundBtn.Update(deltaTime, touchLocations); ObjectSeletor.Update(deltaTime, touchLocations); ChangeSpeedBtn.Update(deltaTime, touchLocations); OptionsBtn.Update(deltaTime, touchLocations); OptionsMenu.Update(deltaTime, touchLocations); } if (StartRoundBtn.ControlState == ControlState.Disabled && !Level.Map.WaveManager.RoundActive && !Level.Finished) { StartRoundBtn.ControlState = ControlState.Idle; Level.Map.WaveManager.FinishRound(); } this.Level.Update(deltaTime * Speed, touchLocations); } } }