diff options
Diffstat (limited to 'Penguloon/Scenes/GameScene.cs')
| -rw-r--r-- | Penguloon/Scenes/GameScene.cs | 116 |
1 files changed, 6 insertions, 110 deletions
diff --git a/Penguloon/Scenes/GameScene.cs b/Penguloon/Scenes/GameScene.cs index 0f65f1a..3aa8511 100644 --- a/Penguloon/Scenes/GameScene.cs +++ b/Penguloon/Scenes/GameScene.cs @@ -20,6 +20,8 @@ namespace Penguloon.Scenes public ObjectSelector ObjectSeletor { get; set; } + public UpgradeMenu UpgradeMenu { get; set; } + public GameScene(Main main, LevelBase level) : base(main) { this.Level = level; @@ -28,7 +30,6 @@ namespace Penguloon.Scenes 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)); @@ -47,6 +48,8 @@ namespace Penguloon.Scenes (StaticUIValues.ScreenViewport.Y / 2) - (StaticUIValues.IngameOptionsSize.Y / 2)), StaticUIValues.IngameOptionsSize); + UpgradeMenu = new UpgradeMenu(Level, this, new Vector2(), new Vector2()); + ChangeSpeedBtn.OnClick += ChangeSpeedBtn_OnClick; StartRoundBtn.OnClick += StartRoundBtn_OnClick; OptionsBtn.OnClick += OptionsBtn_OnClick; @@ -116,54 +119,13 @@ namespace Penguloon.Scenes // show upgrade menu of object is selected else { - DrawUpgradeUI(); + UpgradeMenu.Draw(deltaTime); } // draw "game over" controls here IngameEndStats.Draw(deltaTime); } - private void DrawUpgradeUI() - { - //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)); - - if (Level.SelectedObject != null) - { - for (int i = 0; i < Level.SelectedObject.UpgradeList.Count; i++) - { - Level.SelectedObject.UpgradeList[i].Draw(Main.SpriteBatch, i); - } - } - - //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)); - - DrawText(ContentManager.GetFont(StaticUIValues.IngameFont), Main.Resources.GetString(Resource.String.IngameGold) + ": " + Level.Money, - new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 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), Main.Resources.GetString(Resource.String.IngameWave) + ": " + Level.Map.WaveManager.CurrentWave.ToString(), - new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 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), Main.Resources.GetString(Resource.String.IngameHealth) + ": " + Level.Health, - new Vector2(Level.Map.MapWidth + StaticUIValues.BorderWidth + 5, 0), - new Vector2(StaticUIValues.ScreenViewport.X - Level.Map.MapWidth - StaticUIValues.BorderWidth, StaticUIValues.IngameUITextAreaHeight), - TextAllignment.LeftBottom, Color.White, Color.Black, 2); - } - private void DrawUI(float deltaTime) { //background @@ -229,7 +191,7 @@ namespace Penguloon.Scenes // update upgrade menu here else { - UpdateUpgradeMenu(touchLocations); + UpgradeMenu.Update(deltaTime, touchLocations); } if (StartRoundBtn.ControlState == ControlState.Disabled && !Level.Map.WaveManager.RoundActive && !Level.Finished) @@ -240,71 +202,5 @@ namespace Penguloon.Scenes this.Level.Update(deltaTime * Speed, touchLocations); } - - private void UpdateUpgradeMenu(TouchLocation[] touchLocations) - { - int startY = StaticUIValues.IngameUITextAreaHeight + StaticUIValues.BorderWidth; - - if (Level.SelectedObject != null) - { - // for each available upgrade in selected object - for (int i = 0; i < Level.SelectedObject.UpgradeList.Count; i++) - { - Level.SelectedObject.UpgradeList[i].State = Objects.UpgradeState.Idle; - - Rectangle upgradeBox = new Rectangle( - (int)Level.Map.MapWidth, - startY + (int)StaticUIValues.UpgradePanelSize.Y * i, - (int)StaticUIValues.UpgradePanelSize.X, - (int)StaticUIValues.UpgradePanelSize.Y); - - for (int x = 0; x < touchLocations.Length; x++) - { - // if finger is released on upgrade box - if (touchLocations[x].State == TouchLocationState.Released) - { - if (upgradeBox.Contains(touchLocations[x].Position.ToPoint())) - { - // continue of we cant afford this upgrade - if (Level.SelectedObject.UpgradeList[i].Cost > Level.Money) - { - SoundManager.PlayUnavailableSound(); - continue; - } - - Level.SelectedObject.UpgradeList[i].Click(); - - // pay upgrade cost - Level.Money -= Level.SelectedObject.UpgradeList[i].Cost; - - // play buy sound here - SoundManager.PlayUpgradeSound(); - - // insert next upgrade if present - if (Level.SelectedObject.UpgradeList[i].NextUgrade != null) - { - Level.SelectedObject.UpgradeList.Insert(i, Level.SelectedObject.UpgradeList[i].NextUgrade); - - // remove clicked upgrade - if (Level.SelectedObject.UpgradeList.Count > i + 1) - Level.SelectedObject.UpgradeList.RemoveAt(i + 1); - } - else - // remove clicked upgrade - if (Level.SelectedObject.UpgradeList.Count > i) - Level.SelectedObject.UpgradeList.RemoveAt(i); - } - } - else - { - if (upgradeBox.Contains(touchLocations[x].Position.ToPoint())) - { - Level.SelectedObject.UpgradeList[i].State = Objects.UpgradeState.Pressed; - } - } - } - } - } - } } }
\ No newline at end of file |
