summaryrefslogtreecommitdiff
path: root/Penguloon/Controls/LevelSelector.cs
diff options
context:
space:
mode:
authoraldrikboy <aldrikboy@gmail.com>2017-12-11 22:02:13 +0100
committeraldrikboy <aldrikboy@gmail.com>2017-12-11 22:02:13 +0100
commitfd6fa4e5cebbe3edb65d50c78dcc8a97ce98ce64 (patch)
tree8950f6b9023e0b47e22e1cd4869ab76de0803f4c /Penguloon/Controls/LevelSelector.cs
parentc4c0f3c887d627b6432551e96009c7aeecd4cdd8 (diff)
First commit
Diffstat (limited to 'Penguloon/Controls/LevelSelector.cs')
-rw-r--r--Penguloon/Controls/LevelSelector.cs101
1 files changed, 101 insertions, 0 deletions
diff --git a/Penguloon/Controls/LevelSelector.cs b/Penguloon/Controls/LevelSelector.cs
new file mode 100644
index 0000000..1e26fcc
--- /dev/null
+++ b/Penguloon/Controls/LevelSelector.cs
@@ -0,0 +1,101 @@
+using Penguloon.Scenes;
+using Microsoft.Xna.Framework;
+using System;
+using System.Collections.Generic;
+using Penguloon.Levels;
+using Microsoft.Xna.Framework.Input.Touch;
+
+namespace Penguloon.Controls
+{
+ class LevelSelector : ControlBase
+ {
+ public int PanelWidth { get; set; }
+ public const int PanelMarginX = 30;
+ public const int MaxPanels = 3;
+
+ int selectedMap = 0;
+
+ public List<LevelBase> Levels { get; set; } = new List<LevelBase>();
+
+ public Rectangle Panel1 { get; set; }
+ public Rectangle Panel2 { get; set; }
+ public Rectangle Panel3 { get; set; }
+
+ public LevelSelector(SceneBase parentScene, Vector2 position, Vector2 size) : base(parentScene, position, size)
+ {
+ this.BackgroundIdle = ContentManager.GetTexture("UI/btnIdle");
+ this.BackgroundPressed = ContentManager.GetTexture("UI/btnIdle");
+ this.BackgroundDisabled = ContentManager.GetTexture("UI/btnIdle");
+
+ PanelWidth = (int)(StaticUIValues.ScreenViewport.X - ((MaxPanels + 1) * PanelMarginX)) / MaxPanels;
+
+ int panel1posX = PanelMarginX + (PanelMarginX * 0) + (PanelWidth * 0);
+ int panel2posX = PanelMarginX + (PanelMarginX * 1) + (PanelWidth * 1);
+ int panel3posX = PanelMarginX + (PanelMarginX * 2) + (PanelWidth * 2);
+
+ int sidePanelMarginY = 25;
+
+ Panel1 = new Rectangle(panel1posX, (int)position.Y + (sidePanelMarginY / 2), PanelWidth, (int)size.Y - sidePanelMarginY);
+ Panel2 = new Rectangle(panel2posX, (int)position.Y, PanelWidth, (int)size.Y);
+ Panel3 = new Rectangle(panel3posX, (int)position.Y + (sidePanelMarginY / 2), PanelWidth, (int)size.Y - sidePanelMarginY);
+
+ this.OnClick += LevelSelector_OnClick;
+
+ CreateLevels();
+ }
+
+ private void LevelSelector_OnClick(object sender, ClickArgs e)
+ {
+ Rectangle fingerRec = new Rectangle(e.ClickPosition.ToPoint(), new Point(1, 1));
+
+ if (Panel1.Intersects(fingerRec) && selectedMap > 0)
+ {
+ selectedMap--;
+ }
+
+ if (Panel2.Intersects(fingerRec))
+ {
+ SceneManager.GameScene = new GameScene(ParentScene.Main, Levels[selectedMap]);
+ SceneManager.SelectedScene = SelectedScene.Ingame;
+ }
+
+ if (Panel3.Intersects(fingerRec) && selectedMap < Levels.Count - 1)
+ {
+ selectedMap++;
+ }
+ }
+
+ private void CreateLevels()
+ {
+ Levels.Add(new IceLevel());
+ //Levels.Add(new IceLevel());
+ //Levels.Add(new IceLevel());
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ // We dont need to draw text or a background
+ //base.Draw(deltaTime);
+
+ DrawPanels();
+ }
+
+ private void DrawPanels()
+ {
+ if (selectedMap - 1 >= 0)
+ {
+ ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap - 1].SplashArt,
+ destinationRectangle: Panel1);
+ }
+
+ ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap].SplashArt,
+ destinationRectangle: Panel2);
+
+ if (selectedMap + 1 < Levels.Count)
+ {
+ ParentScene.Main.SpriteBatch.Draw(Levels[selectedMap + 1].SplashArt,
+ destinationRectangle: Panel3);
+ }
+ }
+ }
+} \ No newline at end of file