Ejemplo n.º 1
0
        /// <summary>
        /// Initialize
        /// </summary>
        protected override void Initialize( )
        {
            base.Initialize( );

            _config = new ConfigurationService(_deviceMNG);
            _config.LoadConfiguration( );
            _config.AssignIngameConfiguration( );

            _canvas = new SpriteBatch(GraphicsDevice);

            _input   = new InputService( );
            _content = new ContentService(Content, GraphicsDevice, _canvas);

            // Console
            LOG.Add("Initializing console commands...");
            _console = new GameConsole(_input, _content, _config);
            _console.Initialize(_content);
            _console.SetAction("hide", 0, (args) => _console.IsVisible = false);
            _console.SetAction("exit", 0, (args) => Exit( ));
            _console.SetAction("debug", 0, (args) => _config.Change("debug_mode", !_config.DebugMode));
            _console.SetAction("translate", 1, (args) => LOG.Add(TranslationService.Get(args[0]), LogType.Success));
            _console.SetAction("new_game", 0, (args) => {
                _state.ChangeState(GameStateType.Gameplay);
                ((GameplayState)_state.GetCurrentState( )).NewGame(args.Length >= 1 ? args[0] : null);
                MediaPlayer.Stop( );
            });

            // Content
            LOG.Add("Loading application's content");
            DH.Content = _content;
            _content.LoadContent( );
            _content.UpdateDynamicContent(_config);

            // States
            LOG.Add("Initializing states...");
            _state = new StateService( );
            _state.Register(GameStateType.MainMenu, new MainMenuState(_content, _input, _config, _state, _console));
            _state.Register(GameStateType.Gameplay, new GameplayState(_content, _input, _config, _state, _console));
            _state.Register(GameStateType.Credits, new CreditsState( ));
            _state.Register(GameStateType.Settings, new SettingsState(_content, _input, _config, _state));
            _state.Register(GameStateType.Tutorial, new TutorialState( ));
            _state.Register(GameStateType.Pause, new PauseState(_content, _input, _config));
            _state.ChangeState(GameStateType.MainMenu);

            // Audio
            LOG.Add("Initializing audio...");
            MediaPlayer.IsRepeating = true; // Temporary
            AudioHelper.Music(_content.GetRandomSong( ));

            // Common
            LOG.Add("Finalizing initialization...");
            RandomService.Random = new Random( );
            TranslationService.LoadTranslations <LanguageModel>(_config.Language);

            LOG.Add($"App ready, version {VERSION}", LogType.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// State's initialization
        /// </summary>
        /// <param name="content"><see cref="ContentServiceBase"/></param>
        public override void Initialize(ContentServiceBase content)
        {
            Width  = _config.ViewWidth;
            Height = _config.ViewHeight;
            base.Initialize(content);

            _backButton = new MenuButton(_input, _content)
            {
                X = 32, Y = Height - 96, Width = 256, Height = 48, Text = "back", Align = AlignType.CM, OnClick = () => OnResume?.Invoke( )
            };
            _saveButton = new MenuButton(_input, _content)
            {
                X = 32, Y = Height - 144, Width = 256, Height = 48, Text = "save_changes", Align = AlignType.CM, OnClick = () => {
                    _changedConfig.ForEach(key => _config.Configuration[key] = _cfg[key]);
                    _config.AssignIngameConfiguration( );
                    _content.UpdateDynamicContent(_config);
                    _state.ReinitializeStates(_content, _config);
                }
            };
        }