summaryrefslogtreecommitdiff
path: root/source/screens
diff options
context:
space:
mode:
Diffstat (limited to 'source/screens')
-rw-r--r--source/screens/GameplayScreen.cs81
-rw-r--r--source/screens/MainMenuScreen.cs85
-rw-r--r--source/screens/SplashScreen.cs100
-rw-r--r--source/screens/TextTestScreen.cs73
4 files changed, 339 insertions, 0 deletions
diff --git a/source/screens/GameplayScreen.cs b/source/screens/GameplayScreen.cs
new file mode 100644
index 0000000..ea1a278
--- /dev/null
+++ b/source/screens/GameplayScreen.cs
@@ -0,0 +1,81 @@
+using System.Diagnostics;
+using Celesteia.Game.Systems;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using Celesteia.Game.ECS;
+using MonoGame.Extended.Entities;
+using MonoGame.Extended.Screens;
+using Celesteia.Resources;
+using Celesteia.Graphics;
+using Celesteia.Game.Components;
+using Celesteia.Game.Systems.Physics;
+using Celesteia.GUIs.Game;
+using Celesteia.Game.Systems.UI;
+using Celesteia.Game.Components.Items;
+using Celesteia.Game.Planets;
+using Microsoft.Xna.Framework.Media;
+
+namespace Celesteia.Screens {
+ public class GameplayScreen : GameScreen {
+ private new GameInstance Game => (GameInstance) base.Game;
+
+ private GameWorld _gameWorld;
+ private ChunkMap _chunkMap;
+ public GameplayScreen(GameInstance game, GameWorld gameWorld) : base(game) {
+ _gameWorld = gameWorld;
+ _chunkMap = gameWorld.ChunkMap;
+ }
+
+ private SpriteBatch SpriteBatch => Game.SpriteBatch;
+ private Camera2D Camera;
+ private GameGUI _gameGui;
+
+ public override void LoadContent()
+ {
+ base.LoadContent();
+
+ Song overworldMusic = Content.Load<Song>("music/landing_light");
+ Game.Music.PlayNow(overworldMusic);
+
+ Camera = new Camera2D(GraphicsDevice);
+
+ _gameGui = new GameGUI(Game);
+ _gameGui.LoadContent(Content);
+
+ LocalPlayerSystem lps = new LocalPlayerSystem(Game, _chunkMap, Camera, SpriteBatch, _gameGui);
+
+ _gameWorld.BeginBuilder()
+ .AddSystem(new PhysicsSystem())
+ .AddSystem(new PhysicsWorldCollisionSystem(_chunkMap))
+ .AddSystem(new TargetPositionSystem(_chunkMap))
+ .AddSystem(new ChunkMapRenderSystem(Camera, SpriteBatch, _chunkMap))
+ .AddSystem(new CameraSystem(Camera))
+ .AddSystem(new CameraRenderSystem(Camera, SpriteBatch))
+ .AddSystem(new LightingSystem(Camera, SpriteBatch, _chunkMap))
+ .AddSystem(lps)
+ .AddSystem(new GameGUIDrawSystem(_gameGui));
+ _gameWorld.EndBuilder();
+
+ Entity player = new EntityFactory(_gameWorld).CreateEntity(NamespacedKey.Base("player"));
+ player.Get<TargetPosition>().Target = _chunkMap.GetSpawnpoint();
+ _gameGui.SetReferenceInventory(player.Get<Inventory>());
+ lps.Player = player;
+ }
+
+ public override void Update(GameTime gameTime) => _gameWorld.Update(gameTime);
+
+ public override void Draw(GameTime gameTime)
+ {
+ GraphicsDevice.Clear(Color.SkyBlue);
+ _gameWorld.Draw(gameTime);
+ }
+
+ public override void Dispose()
+ {
+ Debug.WriteLine("Unloading GameplayScreen content...");
+ base.UnloadContent();
+ Debug.WriteLine("Disposing GameplayScreen...");
+ base.Dispose();
+ }
+ }
+} \ No newline at end of file
diff --git a/source/screens/MainMenuScreen.cs b/source/screens/MainMenuScreen.cs
new file mode 100644
index 0000000..0d2a69b
--- /dev/null
+++ b/source/screens/MainMenuScreen.cs
@@ -0,0 +1,85 @@
+using System.Diagnostics;
+using Celesteia.GUIs;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.Screens;
+using Microsoft.Xna.Framework.Media;
+using Celesteia.Graphics;
+using MonoGame.Extended.Entities;
+using Celesteia.Game.Systems.MainMenu;
+using Celesteia.Game.ECS;
+using MonoGame.Extended;
+using Celesteia.Game.Components.Skybox;
+using Celesteia.Resources;
+
+namespace Celesteia.Screens {
+ public class MainMenuScreen : GameScreen
+ {
+ private new GameInstance Game => (GameInstance) base.Game;
+ public MainMenuScreen(GameInstance game) : base(game) {}
+
+ private MainMenu mainMenu;
+
+ private Song mainMenuTheme;
+
+ private Camera2D Camera;
+ private World _world;
+
+ public override void LoadContent()
+ {
+ base.LoadContent();
+
+ mainMenuTheme = Content.Load<Song>("music/stargaze_symphony");
+ Game.Music.PlayNow(mainMenuTheme);
+
+ Camera = new Camera2D(GraphicsDevice);
+
+ _world = new WorldBuilder()
+ .AddSystem(new MainMenuBackgroundSystem())
+ .AddSystem(new MainMenuRenderSystem(Camera, Game.SpriteBatch))
+ .Build();
+
+ CreateSkyboxPortion("stars", Color.White, -0.1f, .9f);
+ CreateSkyboxPortion("shadow", Color.Black, 5f, .7f);
+ CreateSkyboxPortion("shadow", Color.Black, 3f, .6f);
+ CreateSkyboxPortion("nebula", new Color(165,216,255,45), 3f, .5f);
+ CreateSkyboxPortion("nebula", new Color(255,165,246,45), -2f, .3f);
+
+ mainMenu = new MainMenu(Game);
+ mainMenu.LoadContent(Content);
+ }
+
+ public Entity CreateSkyboxPortion(string name, Color color, float rotation, float depth)
+ {
+ Entity e = _world.CreateEntity();
+
+ e.Attach(new Transform2(Vector2.Zero, 0F, new Vector2(3f, 3f)));
+ e.Attach(new SkyboxRotateZ(rotation));
+ e.Attach(ResourceManager.Skybox.GetAsset(name).Frames.Clone().SetColor(color).SetDepth(depth));
+
+ return e;
+ }
+
+ public override void Draw(GameTime gameTime)
+ {
+ GraphicsDevice.Clear(Color.White);
+
+ _world.Draw(gameTime);
+ mainMenu.Draw(gameTime);
+ }
+
+ public override void Update(GameTime gameTime)
+ {
+ _world.Update(gameTime);
+ mainMenu.Update(gameTime, out _);
+ }
+
+ public override void Dispose()
+ {
+ Debug.WriteLine("Unloading MainMenuScreen content...");
+ base.UnloadContent();
+ Debug.WriteLine("Disposing MainMenuScreen...");
+ base.Dispose();
+ }
+ }
+} \ No newline at end of file
diff --git a/source/screens/SplashScreen.cs b/source/screens/SplashScreen.cs
new file mode 100644
index 0000000..46fb519
--- /dev/null
+++ b/source/screens/SplashScreen.cs
@@ -0,0 +1,100 @@
+using System;
+using System.Diagnostics;
+using Celesteia.Game.Input;
+using Celesteia.UI;
+using Celesteia.UI.Elements;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.Screens;
+
+namespace Celesteia.Screens {
+ public class SplashScreen : GameScreen {
+ private new GameInstance Game => (GameInstance) base.Game;
+ public SplashScreen(GameInstance game) : base(game) {}
+
+ private Texture2D leafalLogo;
+ private SoundEffect splashSound;
+ private Image logoElement;
+ private Rect logoRect;
+
+ private float logoRatio;
+
+ public override void LoadContent()
+ {
+ base.LoadContent();
+
+ leafalLogo = Game.Content.Load<Texture2D>("branding/leafal/leafal_text_logo");
+ splashSound = Game.Content.Load<SoundEffect>("branding/leafal/splash");
+
+ logoRatio = leafalLogo.Height / (float) leafalLogo.Width;
+
+ logoRect = new Rect(
+ new ScreenSpaceUnit(0.25f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
+ new ScreenSpaceUnit(0.5f - (logoRatio / 2f), ScreenSpaceUnit.ScreenSpaceOrientation.Vertical),
+ new ScreenSpaceUnit(0.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal),
+ new ScreenSpaceUnit(logoRatio * 0.5f, ScreenSpaceUnit.ScreenSpaceOrientation.Horizontal)
+ );
+ logoElement = new Image(logoRect).SetTexture(leafalLogo).SetColor(Color.White);
+
+ splashSound.Play(0.5f, 0f, 0f);
+ }
+
+ private float timeElapsed = 0f;
+ private float fadeInTime = 1.25f;
+ private float fadeOutTime = 0.75f;
+ private float duration = 6f;
+ private float endTimeout = 1f;
+ private float progress = 0f;
+ private Color color = Color.White;
+
+ public override void Update(GameTime gameTime) {
+ if (progress >= 1f || Game.Input.GetAny()) {
+ Game.LoadScreen(new MainMenuScreen(Game), new MonoGame.Extended.Screens.Transitions.FadeTransition(GraphicsDevice, Color.Black));
+ return;
+ }
+
+ timeElapsed += (float) (gameTime.ElapsedGameTime.TotalMilliseconds / 1000f);
+ float alpha = 1f;
+ if (timeElapsed <= fadeInTime) alpha = Math.Min(timeElapsed / fadeInTime, 1f);
+ if (duration - fadeOutTime <= timeElapsed) alpha = Math.Max((duration - timeElapsed) / fadeOutTime, 0f);
+
+ color.A = (byte) ((int) (alpha * 255));
+
+ progress = timeElapsed / (duration + endTimeout);
+ UpdateLogoRect(progress);
+ }
+
+ private float growFactor = 0f;
+ private void UpdateLogoRect(float progress) {
+ Rect r = logoElement.GetRect();
+
+ r.X.SetValue(0.25f - (progress * (growFactor / 2f)));
+ r.Y.SetValue(0.5f - (logoRatio / 2f) - ((logoRatio / 2f) * progress * (growFactor / 2f)));
+ r.Width.SetValue(0.5f + (progress * growFactor));
+ r.Height.SetValue(0.5f * logoRatio + ((progress * growFactor * logoRatio)));
+
+ logoElement.SetRect(r);
+ }
+
+ public override void Draw(GameTime gameTime)
+ {
+ GraphicsDevice.Clear(Color.Black);
+
+ Game.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearClamp);
+
+ logoElement.SetColor(color);
+ logoElement.Draw(Game.SpriteBatch);
+
+ Game.SpriteBatch.End();
+ }
+
+ public override void Dispose()
+ {
+ Debug.WriteLine("Unloading SplashScreen content...");
+ base.UnloadContent();
+ Debug.WriteLine("Disposing SplashScreen...");
+ base.Dispose();
+ }
+ }
+} \ No newline at end of file
diff --git a/source/screens/TextTestScreen.cs b/source/screens/TextTestScreen.cs
new file mode 100644
index 0000000..2e772df
--- /dev/null
+++ b/source/screens/TextTestScreen.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Diagnostics;
+using Celesteia.Game.Input;
+using Celesteia.Resources;
+using Celesteia.UI;
+using Celesteia.UI.Elements;
+using Celesteia.UI.Properties;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonoGame.Extended.Screens;
+
+namespace Celesteia.Screens {
+ public class TextTestScreen : GameScreen {
+ private new GameInstance Game => (GameInstance) base.Game;
+ public TextTestScreen(GameInstance game) : base(game) {}
+
+ private IContainer Root;
+
+ private Label topLeft;
+ //private Label topCenter;
+ //private Label topRight;
+ //private Label middleLeft;
+ //private Label middle;
+ //private Label middleRight;
+ //private Label bottomLeft;
+ //private Label bottom;
+ private Label bottomRight;
+
+ private TextProperties properties;
+ private float _fontSize = 24f;
+
+ public override void LoadContent()
+ {
+ base.LoadContent();
+
+ Root = new Container(Rect.ScreenFull);
+
+ properties = new TextProperties().SetColor(Color.White).SetFont(ResourceManager.Fonts.GetFontType("Hobo")).SetText("Hello, world!");
+
+ topLeft = new Label(new Rect(AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(100), AbsoluteUnit.WithValue(100)));
+ Root.AddChild(topLeft);
+ bottomRight = new Label(new Rect(AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(150), AbsoluteUnit.WithValue(100), AbsoluteUnit.WithValue(100)));
+ Root.AddChild(bottomRight);
+ }
+
+ public override void Update(GameTime gameTime) {
+ _fontSize += MouseHelper.ScrollDelta;
+ _fontSize = Math.Clamp(_fontSize, 1f, 100f);
+
+ topLeft.SetTextProperties(properties.Clone().SetTextAlignment(TextAlignment.Top | TextAlignment.Left).SetFontSize(_fontSize));
+ bottomRight.SetTextProperties(properties.Clone().SetTextAlignment(TextAlignment.Bottom | TextAlignment.Right).SetFontSize(_fontSize));
+ }
+
+ public override void Draw(GameTime gameTime)
+ {
+ GraphicsDevice.Clear(Color.Black);
+
+ Game.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp);
+
+ Root.Draw(Game.SpriteBatch);
+
+ Game.SpriteBatch.End();
+ }
+
+ public override void Dispose()
+ {
+ Debug.WriteLine("Unloading TextTestScreen content...");
+ base.UnloadContent();
+ Debug.WriteLine("Disposing TextTestScreen...");
+ base.Dispose();
+ }
+ }
+} \ No newline at end of file