diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2018-01-15 19:57:56 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2018-01-15 19:57:56 +0100 |
| commit | 1f5295752f9052c2b7b64660fa36293f18de73d0 (patch) | |
| tree | 17af827f212f720f9c2f63aaa02fbe723ea7db2f /Penguloon/Scenes | |
| parent | a0217e8ffaceb6bc109eec270c754935a54eb404 (diff) | |
upgrades working
Diffstat (limited to 'Penguloon/Scenes')
| -rw-r--r-- | Penguloon/Scenes/GameScene.cs | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/Penguloon/Scenes/GameScene.cs b/Penguloon/Scenes/GameScene.cs index 20bf7c4..ac29989 100644 --- a/Penguloon/Scenes/GameScene.cs +++ b/Penguloon/Scenes/GameScene.cs @@ -119,6 +119,9 @@ namespace Penguloon.Scenes { DrawUpgradeUI(); } + + // draw "game over" controls here + IngameEndStats.Draw(deltaTime); } private void DrawUpgradeUI() @@ -205,9 +208,6 @@ namespace Penguloon.Scenes 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); - - // draw finished controls here - IngameEndStats.Draw(deltaTime); } public override void Update(float deltaTime, TouchLocation[] touchLocations) @@ -230,7 +230,7 @@ namespace Penguloon.Scenes // update upgrade menu here else { - + UpdateUpgradeMenu(touchLocations); } if (StartRoundBtn.ControlState == ControlState.Disabled && !Level.Map.WaveManager.RoundActive && !Level.Finished) @@ -241,5 +241,64 @@ 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; + + // continue of we cant afford this upgrade + if (Level.SelectedObject.UpgradeList[i].Cost > Level.Money) continue; + + Rectangle upgradeBox = new Rectangle( + (int)StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth, + 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())) + { + Level.SelectedObject.UpgradeList[i].Click(); + + // pay upgrade cost + Level.Money -= Level.SelectedObject.UpgradeList[i].Cost; + + // 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 |
