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 | |
| parent | a0217e8ffaceb6bc109eec270c754935a54eb404 (diff) | |
upgrades working
| -rw-r--r-- | Penguloon/Objects/ObjectUpgrade.cs | 35 | ||||
| -rw-r--r-- | Penguloon/Objects/PenguinObject.cs | 6 | ||||
| -rw-r--r-- | Penguloon/Scenes/GameScene.cs | 67 |
3 files changed, 97 insertions, 11 deletions
diff --git a/Penguloon/Objects/ObjectUpgrade.cs b/Penguloon/Objects/ObjectUpgrade.cs index c1f701a..278a1fb 100644 --- a/Penguloon/Objects/ObjectUpgrade.cs +++ b/Penguloon/Objects/ObjectUpgrade.cs @@ -11,6 +11,7 @@ using Android.Views; using Android.Widget; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; +using Penguloon.Levels; namespace Penguloon.Objects { @@ -22,6 +23,12 @@ namespace Penguloon.Objects Money, } + public enum UpgradeState + { + Idle, + Pressed, + } + public class ObjectUpgrade { public int Cost { get; set; } @@ -29,18 +36,29 @@ namespace Penguloon.Objects public event EventHandler OnClick; public UpgradeType Type { get; set; } public string Text { get; set; } + public UpgradeState State { get; set; } = UpgradeState.Idle; private Texture2D Background { get; set; } + private Texture2D BackgroundPressed { get; set; } private Texture2D Icon { get; set; } - public ObjectUpgrade(int Cost, UpgradeType Type, string Text, ObjectUpgrade NextUgrade) + public LevelBase ParentLevel { get; set; } + + public ObjectUpgrade(int Cost, UpgradeType Type, string Text, ObjectUpgrade NextUgrade, LevelBase parentLevel) { + // something is fucked up in staticUiValues.IngameUIWidth but we can workaround that issue with this line + StaticUIValues.UpgradePanelSize = new Vector2( + StaticUIValues.ScreenViewport.X - parentLevel.Map.MapWidth, + StaticUIValues.UpgradePanelSize.Y); + this.Cost = Cost; this.Type = Type; this.Text = Text; this.NextUgrade = NextUgrade; + this.ParentLevel = parentLevel; Background = ContentManager.GetTexture("UI/lightred"); + BackgroundPressed = ContentManager.GetTexture("UI/objectSelectionBackground"); switch (Type) { @@ -63,26 +81,33 @@ namespace Penguloon.Objects SpriteFont font = ContentManager.GetFont(StaticUIValues.IngameFont); int textHeight = (int)font.MeasureString(Text).Y; + if (State == UpgradeState.Idle) spriteBatch.Draw(Background, destinationRectangle: new Rectangle( - (int)StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth, + ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, startY + (int)StaticUIValues.UpgradePanelSize.Y * index, (int)StaticUIValues.UpgradePanelSize.X, (int)StaticUIValues.UpgradePanelSize.Y)); + else + spriteBatch.Draw(BackgroundPressed, destinationRectangle: new Rectangle( + ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, + startY + (int)StaticUIValues.UpgradePanelSize.Y * index, + (int)StaticUIValues.UpgradePanelSize.X, + (int)StaticUIValues.UpgradePanelSize.Y)); spriteBatch.Draw(Icon, destinationRectangle: new Rectangle( - (int)StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth + 20, + ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth + 20, startY + ((int)StaticUIValues.UpgradePanelSize.Y * index) + (int)(StaticUIValues.UpgradePanelSize.Y / 4), (int)StaticUIValues.UpgradePanelSize.Y / 2, (int)StaticUIValues.UpgradePanelSize.Y / 2)); spriteBatch.DrawString(ContentManager.GetFont(StaticUIValues.IngameFont), - Text, new Vector2((int)StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth + 90, + Text, new Vector2(ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth + 90, startY + ((int)StaticUIValues.UpgradePanelSize.Y * index) + (int)(StaticUIValues.UpgradePanelSize.Y / 2) - textHeight / 2), Color.FromNonPremultiplied(20, 20, 20, 255)); spriteBatch.Draw(ContentManager.GetTexture("UI/objectSelectionBorder"), destinationRectangle: new Rectangle( - (int)StaticUIValues.ScreenViewport.X - StaticUIValues.IngameUIWidth, + ParentLevel.Map.MapWidth + StaticUIValues.BorderWidth, startY + (int)StaticUIValues.UpgradePanelSize.Y * index + (int)StaticUIValues.UpgradePanelSize.Y - 2, (int)StaticUIValues.UpgradePanelSize.X, 2)); diff --git a/Penguloon/Objects/PenguinObject.cs b/Penguloon/Objects/PenguinObject.cs index 0fc1078..7d3f259 100644 --- a/Penguloon/Objects/PenguinObject.cs +++ b/Penguloon/Objects/PenguinObject.cs @@ -29,8 +29,10 @@ namespace Penguloon.Objects public override void CreateUpgrades() { - UpgradeList.Add(new ObjectUpgrade(100, UpgradeType.PopCount, "+1 pop", null)); - UpgradeList.Add(new ObjectUpgrade(100, UpgradeType.Speed, "+15 Speed", null)); + ObjectUpgrade upg = new ObjectUpgrade(100, UpgradeType.PopCount, "+2 pop", null, Map.Level); + + UpgradeList.Add(new ObjectUpgrade(100, UpgradeType.PopCount, "+1 pop", upg, Map.Level)); + UpgradeList.Add(new ObjectUpgrade(100, UpgradeType.Speed, "+15 Speed", null, Map.Level)); } public override void DrawUnique(float deltaTime) 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 |
