summaryrefslogtreecommitdiff
path: root/Penguloon/Scenes
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/Scenes
parentc4c0f3c887d627b6432551e96009c7aeecd4cdd8 (diff)
First commit
Diffstat (limited to 'Penguloon/Scenes')
-rw-r--r--Penguloon/Scenes/GameScene.cs36
-rw-r--r--Penguloon/Scenes/LevelSelectionScene.cs47
-rw-r--r--Penguloon/Scenes/LoadingScene.cs71
-rw-r--r--Penguloon/Scenes/MenuScene.cs50
-rw-r--r--Penguloon/Scenes/SceneBase.cs157
5 files changed, 361 insertions, 0 deletions
diff --git a/Penguloon/Scenes/GameScene.cs b/Penguloon/Scenes/GameScene.cs
new file mode 100644
index 0000000..2928b4b
--- /dev/null
+++ b/Penguloon/Scenes/GameScene.cs
@@ -0,0 +1,36 @@
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Levels;
+using Penguloon.Scenes;
+
+namespace Penguloon.Scenes
+{
+ internal class GameScene : SceneBase
+ {
+ public LevelBase Level { get; set; }
+
+ public GameScene(Main main, LevelBase level) : base(main)
+ {
+ this.Level = level;
+ this.Level.Initialize(this);
+ }
+
+ public override void CreateControls()
+ {
+
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ base.Draw(deltaTime);
+
+ this.Level.Draw(deltaTime);
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ base.Update(deltaTime, touchLocations);
+
+ this.Level.Update(deltaTime, touchLocations);
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Scenes/LevelSelectionScene.cs b/Penguloon/Scenes/LevelSelectionScene.cs
new file mode 100644
index 0000000..4df627c
--- /dev/null
+++ b/Penguloon/Scenes/LevelSelectionScene.cs
@@ -0,0 +1,47 @@
+using System;
+using Penguloon.Controls;
+using Microsoft.Xna.Framework;
+
+namespace Penguloon.Scenes
+{
+ public class LevelSelectionScene : SceneBase
+ {
+ public LevelSelectionScene(Main main) : base(main)
+ {
+
+ }
+
+ public override void CreateControls()
+ {
+ Button btnStart = new Button(this,
+ new Vector2(10, 10),
+ StaticUIValues.MenuButtonSize, Main.Resources.GetString(Resource.String.LevelSelectionBack));
+
+ btnStart.OnClick += BtnStart_OnClick;
+
+ int levelSelectorPosY = (int)((StaticUIValues.ScreenViewport.Y - StaticUIValues.MenuButtonSize.Y) - StaticUIValues.LevelSelectorHeight);
+
+ LevelSelector levelSelector = new LevelSelector(this,
+ new Vector2(0, levelSelectorPosY), new Vector2(StaticUIValues.ScreenViewport.X, StaticUIValues.LevelSelectorHeight));
+
+ Controls.Add(levelSelector);
+ Controls.Add(btnStart);
+ }
+
+ private void BtnStart_OnClick(object sender, ClickArgs e)
+ {
+ SceneManager.SelectedScene = SelectedScene.Menu;
+ }
+
+ 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));
+
+ DrawSnowflakes();
+
+ base.Draw(deltaTime);
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Scenes/LoadingScene.cs b/Penguloon/Scenes/LoadingScene.cs
new file mode 100644
index 0000000..19f0215
--- /dev/null
+++ b/Penguloon/Scenes/LoadingScene.cs
@@ -0,0 +1,71 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Scenes;
+using System;
+using System.Collections.Generic;
+
+namespace Penguloon.Scenes
+{
+ public class LoadingScene : SceneBase
+ {
+ public LoadingScene(Main main) : base(main)
+ {
+
+ }
+
+ public override void CreateControls()
+ {
+
+ }
+
+ public override void Draw(float deltaTime)
+ {
+ base.Draw(deltaTime);
+
+ // if were still loading assets for loading screen, return
+ if (!ContentManager.DonePreLoading) return;
+
+ // background
+ Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/background"),
+ destinationRectangle: new Rectangle(0, 0, (int)StaticUIValues.ScreenViewport.X, (int)StaticUIValues.ScreenViewport.Y));
+
+ DrawSnowflakes();
+
+ // draw progressbar
+ DrawProgressbar();
+
+ // draw title
+ DrawText(ContentManager.GetFont("Fonts/GWENT/128"), "Penguloon", new Vector2(0, 100),
+ StaticUIValues.ScreenViewport, TextAllignment.CenterTop, Color.Red, Color.Black, 5);
+ }
+
+ /// <summary>
+ /// Draw progress bar.
+ /// </summary>
+ private void DrawProgressbar()
+ {
+ int barWidth = (int)(StaticUIValues.LoadingProgressbarSize.X * ContentManager.LoadPercentageF);
+
+ Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/red"),
+ destinationRectangle: new Rectangle(StaticUIValues.LoadingProgressbarValuePosition.ToPoint(),
+ new Point(barWidth - 10, (int)StaticUIValues.LoadingProgressbarSize.Y - 10)));
+
+ Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/progressbar"),
+ destinationRectangle: new Rectangle(StaticUIValues.LoadingProgressbarPosition.ToPoint(),
+ StaticUIValues.LoadingProgressbarSize.ToPoint()));
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ base.Update(deltaTime, touchLocations);
+
+ // if loading is completed
+ if (ContentManager.DoneLoading)
+ {
+ SceneManager.MenuScene = new MenuScene(Main);
+ SceneManager.SelectedScene = SelectedScene.Menu;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Scenes/MenuScene.cs b/Penguloon/Scenes/MenuScene.cs
new file mode 100644
index 0000000..24a260c
--- /dev/null
+++ b/Penguloon/Scenes/MenuScene.cs
@@ -0,0 +1,50 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Controls;
+
+namespace Penguloon.Scenes
+{
+ internal class MenuScene : SceneBase
+ {
+ public MenuScene(Main main) : base(main)
+ {
+ if (SoundManager.Baseline == null)
+ SoundManager.StartBaseline();
+ }
+
+ public override void CreateControls()
+ {
+ Button btnStart = new Button(this,
+ new Vector2((StaticUIValues.ScreenViewport.X - StaticUIValues.MenuButtonSize.X) / 2, 100),
+ StaticUIValues.MenuButtonSize, Main.Resources.GetString(Resource.String.MenuBtnPlay));
+
+ btnStart.OnClick += BtnStart_OnClick;
+
+ Controls.Add(btnStart);
+ }
+
+ private void BtnStart_OnClick(object sender, ClickArgs e)
+ {
+ if(SceneManager.LevelSelectionScene == null)
+ SceneManager.LevelSelectionScene = new LevelSelectionScene(Main);
+
+ SceneManager.SelectedScene = SelectedScene.LevelSelection;
+ }
+
+ 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));
+
+ DrawSnowflakes();
+
+ base.Draw(deltaTime);
+ }
+
+ public override void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ base.Update(deltaTime, touchLocations);
+ }
+ }
+} \ No newline at end of file
diff --git a/Penguloon/Scenes/SceneBase.cs b/Penguloon/Scenes/SceneBase.cs
new file mode 100644
index 0000000..4214e97
--- /dev/null
+++ b/Penguloon/Scenes/SceneBase.cs
@@ -0,0 +1,157 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input.Touch;
+using Penguloon.Controls;
+using System;
+using System.Collections.Generic;
+
+namespace Penguloon.Scenes
+{
+ public abstract class SceneBase
+ {
+ public List<Vector2> SnowflakeList { get; set; } = new List<Vector2>();
+ public DateTime LastSnowflakeSpawn { get; set; }
+ public int SnowflakeSpawnDelayMS { get; set; } = 1000;
+ public float SnowflakeRotation { get; set; } = 0f;
+
+ public Main Main { get; set; }
+
+ public List<ControlBase> Controls = new List<ControlBase>();
+
+ /// <summary>
+ /// Base constructor.
+ /// </summary>
+ /// <param name="main">active Main object.</param>
+ protected SceneBase(Main main)
+ {
+ this.Main = main;
+ CreateControls();
+ }
+
+ /// <summary>
+ /// Draw this scene.
+ /// </summary>
+ /// <param name="deltaTime">Delta time.</param>
+ public virtual void Draw(float deltaTime)
+ {
+ for (int i = 0; i < Controls.Count; i++)
+ Controls[i].Draw(deltaTime);
+ }
+
+ /// <summary>
+ /// Update this scene.
+ /// </summary>
+ /// <param name="deltaTime">Delta time.</param>
+ /// <param name="touchLocations">Finger touch locations.</param>
+ public virtual void Update(float deltaTime, TouchLocation[] touchLocations)
+ {
+ for (int i = 0; i < Controls.Count; i++)
+ Controls[i].Update(deltaTime, touchLocations);
+
+ SnowflakeRotation += 5f * deltaTime;
+
+ if ((DateTime.Now - LastSnowflakeSpawn).TotalMilliseconds > SnowflakeSpawnDelayMS)
+ SpawnSnowflake();
+
+ for (int i = 0; i < SnowflakeList.Count; i++)
+ {
+ SnowflakeList[i] = new Vector2(SnowflakeList[i].X, SnowflakeList[i].Y + 5);
+ }
+
+ DeleteOutofBoundSnowflakes();
+ }
+
+ private void DeleteOutofBoundSnowflakes()
+ {
+ for (int i = 0; i < SnowflakeList.Count; i++)
+ {
+ if (SnowflakeList[i].Y - 100 > StaticUIValues.ScreenViewport.Y)
+ SnowflakeList.RemoveAt(i);
+ }
+ }
+
+ /// <summary>
+ /// Draw text at given parameters.
+ /// </summary>
+ /// <param name="font"></param>
+ /// <param name="text"></param>
+ /// <param name="position"></param>
+ /// <param name="size"></param>
+ /// <param name="textAllignment"></param>
+ /// <param name="color"></param>
+ public void DrawText(SpriteFont font, string text, Vector2 position, Vector2 size, TextAllignment textAllignment, Color color, Color borderColor, int borderWidth)
+ {
+ if (font == null) return;
+
+ Vector2 textSize = font.MeasureString(text);
+
+ Vector2 pos = position;
+
+ switch (textAllignment)
+ {
+ case TextAllignment.LeftTop: pos = position; break;
+ case TextAllignment.CenterTop: pos.X += (size.X / 2) - (textSize.X / 2); break;
+ case TextAllignment.RightTop: pos.X += (size.X) - (textSize.X); break;
+
+ case TextAllignment.LeftMiddle: pos.Y += (size.Y / 2) - (textSize.Y / 2) + 5; break;
+ case TextAllignment.CenterMiddle: pos.X += (size.X / 2) - (textSize.X / 2); pos.Y += (size.Y / 2) - (textSize.Y / 2) + 5; break;
+ case TextAllignment.RightMiddle: pos.X += (size.X) - (textSize.X); pos.Y += (size.Y / 2) - (textSize.Y / 2) + 5; break;
+
+ case TextAllignment.LeftBottom: pos.Y += (size.Y) - (textSize.Y); break;
+ case TextAllignment.CenterBottom: pos.X += (size.X / 2) - (textSize.X / 2); pos.Y += (size.Y) - (textSize.Y); break;
+ case TextAllignment.RightBottom: pos.X += (size.X) - (textSize.X); pos.Y += (size.Y) - (textSize.Y); break;
+ }
+
+ // border
+
+ //leftTop
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X - borderWidth, pos.Y - borderWidth), borderColor);
+ //centerTop
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X, pos.Y - borderWidth), borderColor);
+ //rightTop
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X + borderWidth, pos.Y - borderWidth), borderColor);
+
+ //LeftMiddle
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X - borderWidth, pos.Y), borderColor);
+ //RightMiddle
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X + borderWidth, pos.Y), borderColor);
+
+ //LeftBottom
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X - borderWidth, pos.Y + borderWidth), borderColor);
+ //CenterBottom
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X, pos.Y + borderWidth), borderColor);
+ //RightBottom
+ Main.SpriteBatch.DrawString(font, text, new Vector2(pos.X + borderWidth, pos.Y + borderWidth), borderColor);
+
+ // text
+ Main.SpriteBatch.DrawString(font, text, pos, color);
+ }
+
+ protected void DrawSnowflakes()
+ {
+ // draw snowflakes
+ for (int i = 0; i < SnowflakeList.Count; i++)
+ Main.SpriteBatch.Draw(ContentManager.GetTexture("UI/snowflake"),
+ destinationRectangle: new Rectangle((int)SnowflakeList[i].X, (int)SnowflakeList[i].Y,
+ StaticUIValues.SnowflakeSize, StaticUIValues.SnowflakeSize),
+ rotation: SnowflakeRotation,
+ origin: new Vector2(ContentManager.GetTexture("UI/snowflake").Width / 2, ContentManager.GetTexture("UI/snowflake").Height / 2));
+ }
+
+ protected void SpawnSnowflake()
+ {
+ LastSnowflakeSpawn = DateTime.Now;
+
+ int minX = 100, maxX = (int)StaticUIValues.ScreenViewport.X - 200;
+
+ int randomPosX = new Random().Next(minX, maxX);
+
+ SnowflakeList.Add(new Vector2(randomPosX, -100));
+ }
+
+ /// <summary>
+ /// Create the controls for this scene.
+ /// </summary>
+ public abstract void CreateControls();
+ }
+} \ No newline at end of file