From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/screens/GameplayScreen.cs | 81 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 source/screens/GameplayScreen.cs (limited to 'source/screens/GameplayScreen.cs') 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("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().Target = _chunkMap.GetSpawnpoint(); + _gameGui.SetReferenceInventory(player.Get()); + 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 -- cgit v1.2.3