예제 #1
0
파일: Level.cs 프로젝트: kallotec/Bonsai
        public override void Load(IContentLoader loader)
        {
            _loader = loader;

            var defaultFont = loader.Load <SpriteFont>(ContentPaths.FONT_UI_GENERAL);

            varShowLootTip = new GameVariable <bool>();
            varShowLootTip.Load(loader);
            GameObjects.Add(varShowLootTip);

            // Player
            player = new Player(eventBus, varShowLootTip);
            player.Load(loader);
            GameObjects.Add(player);

            // Bot
            bot = new Bot(eventBus, Camera);
            bot.Load(loader);
            GameObjects.Add(bot);

            // Message manager
            textPopupManager = new TextPopupManager(ContentPaths.FONT_UI_GENERAL, StackingMethod.Parallel);
            textPopupManager.Load(loader);
            GameObjects.Add(textPopupManager);

            // Physics
            phys = new MapPhysics(chunkMap, physSettings);
            GameObjects.Add(chunkMap);

            // Camera
            GameObjects.Add(Camera);

            // Services
            setupKeyListeners();

            // Event listeners
            eventBusSubscriptionIds.AddRange(new[] {
                eventBus.Subscribe(Events.PlayerPickedUpCoin, (p) => Debug.WriteLine("picked up coin!")),
                eventBus.Subscribe(Events.PlayerDied, (p) => playerDied()),
                eventBus.Subscribe(Events.CreateProjectile, (p) => playerCreatedProjectile(p as Projectile)),
            });

            // Game variables
            var tipLootBoxOpen = "Press <E> to open loot box";

            txtDisplayTipLootBoxOpen = new TextElement <string>(tipLootBoxOpen, defaultFont, new TextElementSettings())
            {
                Position           = new Vector2(10, 10),
                IsAttachedToCamera = true,
                IsHidden           = true,
            };
            txtDisplayTipLootBoxOpen.Load(loader);
            GameObjects.Add(txtDisplayTipLootBoxOpen);

            // Map
            loadMap();
        }
예제 #2
0
파일: Level.cs 프로젝트: kallotec/Bonsai
        public override void Load(IContentLoader loader)
        {
            _loader = loader;

            // Player
            player = new Player(eventBus, Camera);
            player.Load(loader);
            GameObjects.Add(player);

            // Game variables
            Jumps = new GameVariable <int>();
            Jumps.Load(loader);
            GameObjects.Add(Jumps);
            CoinsCount = new GameVariable <int>();
            CoinsCount.Load(loader);
            GameObjects.Add(CoinsCount);

            // Message manager
            textPopupManager = new TextPopupManager(ContentPaths.FONT_UI_GENERAL, StackingMethod.Parallel);
            textPopupManager.Load(loader);
            GameObjects.Add(textPopupManager);

            // HUD
            hud = new HUD(this);
            hud.ScreenBounds = base.Game.GraphicsDevice.Viewport.Bounds;
            hud.DrawOrder    = DrawOrderPosition.HUD;
            hud.Load(loader);
            GameObjects.Add(hud);

            // Physics
            phys = new MapPhysics(chunkMap, physSettings);
            GameObjects.Add(chunkMap);

            // Camera
            GameObjects.Add(Camera);

            // Services
            setupKeyListeners();

            // Event listeners
            eventBusSubscriptionIds.AddRange(new[] {
                eventBus.Subscribe(Events.PlayerPickedUpCoin, (p) => CoinsCount.Value += 1),
                eventBus.Subscribe(Events.PlayerJumped, (p) => Jumps.Value            += 1),
                eventBus.Subscribe(Events.PlayerEnteredDoor, (p) => playerTouchedDoor()),
                eventBus.Subscribe(Events.PlayerDied, (p) => playerDied()),
                eventBus.Subscribe(Events.CreateProjectile, (p) => playerCreatedProjectile(p as Projectile)),
            });

            // Load first map
            loadMap(ContentPaths.PATH_MAP_1);

            startGameTimer = new MillisecCounter(1500);
            Camera.SetFocus(playerExit, immediateFocus: true);
            isPlayerFocused = false;
        }