using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input.Touch; using Penguloon.Controls; using Penguloon.Levels; using Penguloon.Scenes; namespace Penguloon.Scenes { internal class GameScene : SceneBase { public LevelBase Level { get; set; } public Button StartRoundBtn { get; set; } public GameScene(Main main, LevelBase level) : base(main) { this.Level = level; this.Level.Initialize(this); StartRoundBtn = new Button(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), "Start"); StartRoundBtn.OnClick += StartRoundBtn_OnClick; } private void StartRoundBtn_OnClick(object sender, ClickArgs e) { Level.Map.WaveManager.StartSpawningEnemies(); Button btn = (Button)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); } private void DrawUI(float deltaTime) { //background Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/red"), destinationRectangle: new Rectangle(Level.Map.MapWidth + StaticUIValues.BorderWidth, 0, StaticUIValues.IngameUIWidth, (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, StaticUIValues.IngameUIWidth, 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, StaticUIValues.IngameUIWidth, 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.CenterTop, 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.CenterMiddle, 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.CenterBottom, 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); } if (StartRoundBtn.ControlState == ControlState.Disabled && !Level.Map.WaveManager.RoundActive && !Level.Finished) { StartRoundBtn.ControlState = ControlState.Idle; Level.Map.WaveManager.FinishRound(); } this.Level.Update(deltaTime, touchLocations); } } }