示例#1
0
文件: Level.cs 项目: sergik/Cardio
        public void Initialize(Game game, SpriteBatch spriteBatch, ICamera2D camera, GameState gameState)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("This level has already been initialized.");
            }

            _game = game;
            _resourceBuilder = _game.Services.GetService<ResourceBuilder>();
            _game.Services.GetService<RhythmEngine>();
            _reactionCatalog = _game.Services.GetService<ReactionsCatalog>();

            // let action will be inertioned for 2 beats
            gameState.ReactionProgress.ReactionInertia = 1200;

            Background.Initialize(game, spriteBatch, camera);

            // We also initialize all predefined level objects that were specified before Initialize call.
            // Note that this behavior may change in the future.
            for (int index = 0; index < CustomLevelObjects.Count; index++)
            {
                var levelObject = CustomLevelObjects[index];
                levelObject.Initialize(game, spriteBatch, camera);
            }

            foreach (var text in Texts)
            {
                text.Initialize(game);
            }

            var nanobots = gameState.Player.Nanobots;

            foreach (var bot in nanobots)
            {
                bot.DamageTaken += OnNanobotDamage;
            }

            IsInitialized = true;
        }
示例#2
0
        public override void LoadContent()
        {
            var game = ScreenManager.Game;
            GameState = game.Services.GetService<GameState>();

            // *********************************************************
            // DO NOT forget to remove all added here
            // services and game components on UnloadContent
            // *********************************************************

            var services = ScreenManager.Game.Services;

            services.AddService(ScreenManager);

            // Rhythm engine
            _rhythmEngine = new RhythmEngine(ScreenManager.Game);
            _rhythmEngine.Initialize();
            services.AddService(_rhythmEngine);

            _reactionCatalog = new ReactionsCatalog();
            services.AddService(_reactionCatalog);

            // Input
            _touchService = new TouchService();
            services.AddService(_touchService);

            _inputHandler = new WindowsInputHandler(ScreenManager.Game, this);
            _inputHandler.Initialize();

            _comboController = new ComboController(100);
            GameState.Combo = _comboController;

            GameState.Player.AddScript(new CheckForPickableObjectsScript(game));

            // Resources
            services.AddService(new ResourceBuilder(new InventoryMappingService()));

            Level.Initialize(ScreenManager.Game, ScreenManager.SpriteBatch, GameState.Camera, GameState);

            _comboController.Melodies.Clear();
            _comboController.Melodies[0] =
                new ComboLevelMelody(ScreenManager.Game.Content.Load<SoundEffect>(Level.MelodyAsset));
            _comboController.Initialize(ScreenManager.Game);

            GameState.Camera.Initialize(game);
            GameState.Player.Initialize(game, ScreenManager.SpriteBatch);
            _levelUI = new LevelUI(ScreenManager.Game);
            _levelUI.Initialize();

            // Effects
            _bloom = new BloomComponent(ScreenManager.Game);
            _bloom.Initialize();
            services.AddService(_bloom);

            InitializeReactions();
            WireUpEvents();

            ApplyDefaultMatchingStrategy();

            base.LoadContent();
        }