using System; using MonoGameBlank2dStartKit.Core.Localization; using System.Collections.Generic; using System.Globalization; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonoGameBlank2dStartKit.Core.Content; using MonoGameBlank2dStartKit.Core.Systems; using MoonTools.ECS; using static System.Net.Mime.MediaTypeNames; namespace MonoGameBlank2dStartKit.Core { /// /// The main class for the game, responsible for managing game components, settings, /// and platform-specific configurations. /// public class MonoGameBlank2dStartKitGame : Game { private TextureDrawSystem TextureDrawSystem { get; set; } private VelocitySystem VelocitySystem { get; set; } private RotationSystem RotationSystem { get; set; } // Resources for drawing. private readonly GraphicsDeviceManager graphicsDeviceManager; private SpriteBatch _spriteBatch; private Assets _assets; private World World { get; init; } /// /// Indicates if the game is running on a mobile platform. /// public static readonly bool IsMobile = OperatingSystem.IsAndroid() || OperatingSystem.IsIOS(); /// /// Indicates if the game is running on a desktop platform. /// public static readonly bool IsDesktop = OperatingSystem.IsMacOS() || OperatingSystem.IsLinux() || OperatingSystem.IsWindows(); /// /// Initializes a new instance of the game. Configures platform-specific settings, /// initializes services like settings and leaderboard managers, and sets up the /// screen manager for screen transitions. /// public MonoGameBlank2dStartKitGame() { graphicsDeviceManager = new GraphicsDeviceManager(this); // Share GraphicsDeviceManager as a service. Services.AddService(typeof(GraphicsDeviceManager), graphicsDeviceManager); Content.RootDirectory = "Content"; // Configure screen orientations. graphicsDeviceManager.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; World = new World(); } /// /// Initializes the game, including setting up localization and adding the /// initial screens to the ScreenManager. /// protected override void Initialize() { base.Initialize(); // Load supported languages and set the default language. List cultures = LocalizationManager.GetSupportedCultures(); var languages = new List(); for (int i = 0; i < cultures.Count; i++) { languages.Add(cultures[i]); } // TODO You should load this from a settings file or similar, // based on what the user or operating system selected. var selectedLanguage = LocalizationManager.DEFAULT_CULTURE_CODE; LocalizationManager.SetCulture(selectedLanguage); } /// /// Loads game content, such as textures and particle systems. /// protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _assets = new Assets(Content); TextureDrawSystem = new TextureDrawSystem(World, _assets, _spriteBatch); VelocitySystem = new VelocitySystem(World); RotationSystem = new RotationSystem(World); Scenarios.Basic(World, _assets); base.LoadContent(); } /// /// Updates the game's logic, called once per frame. /// /// /// Provides a snapshot of timing values used for game updates. /// protected override void Update(GameTime gameTime) { // Exit the game if the Back button (GamePad) or Escape key (Keyboard) is pressed. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); var elapsedGameTime = gameTime.ElapsedGameTime; VelocitySystem.Update(elapsedGameTime); RotationSystem.Update(elapsedGameTime); base.Update(gameTime); } /// /// Draws the game's graphics, called once per frame. /// /// /// Provides a snapshot of timing values used for rendering. /// protected override void Draw(GameTime gameTime) { var elapsedGameTime = gameTime.ElapsedGameTime; // Clears the screen with the MonoGame orange color before drawing. GraphicsDevice.Clear(Color.CornflowerBlue); _spriteBatch.Begin(); TextureDrawSystem.Update(elapsedGameTime); _spriteBatch.End(); base.Draw(gameTime); } } }