コード例 #1
0
ファイル: Game.cs プロジェクト: lab132/owlicity
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            WorldRenderer.Initialize(GraphicsDevice);
            UIRenderer.Initialize(GraphicsDevice);

            PhysicsDebugView.LoadContent(GraphicsDevice, Content);

            CurrentLevel = new Level(Content)
            {
                ContentNameFormat_Ground    = "level01/level1_ground_{0}{1}",
                ContentNameFormat_Collision = "level01/static_collision/static_collision_{0}{1}",
                ContentNameFormat_Layout    = "level01/layout/layout_{0}{1}",
            };

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 7; y++)
                {
                    CurrentLevel.CreateScreen(x, y);
                }
            }

            {
                Owliver = new Owliver();
                Owliver.Spatial.Position += Conversion.ToMeters(450, 600);
                AddGameObject(Owliver);

                CurrentLevel.CullingCenter = Owliver;
            }

            CurrentLevel.LoadContent();

            {
                ActiveCamera = new CameraObject();

                ActiveCamera.CameraComponent.VisibilityBounds = CurrentLevel.LevelBounds;
                ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                Window.ClientSizeChanged += (o, e) =>
                {
                    ActiveCamera.CameraComponent.OnGraphicsDeviceReset(GraphicsDevice);
                };

                ActiveCamera.SpringArm.BeforeInitialize += () =>
                {
                    ActiveCamera.SpringArm.Target = Owliver;
                };

                AddGameObject(ActiveCamera);
            }

#if true
            {
                var testSlurp = GameObjectFactory.CreateKnown(KnownGameObject.Slurp);
                testSlurp.Spatial.Position += Conversion.ToMeters(300, 250);
                AddGameObject(testSlurp);
            }

            {
                var testTankton = new Tankton();
                testTankton.Spatial.Position += Conversion.ToMeters(900, 350);
                AddGameObject(testTankton);
            }

            {
                Random rand = new Random();

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 2.5f,
                    numToSpawn: 15,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });

                Global.SpawnGameObjectsInRingFormation(
                    center: Conversion.ToMeters(2400, 500),
                    radius: 1.0f,
                    numToSpawn: 5,
                    rand: rand,
                    types: new[] { KnownGameObject.Bonbon_Gold, KnownGameObject.Bonbon_Red });
            }

            {
                var testKey = new KeyPickup()
                {
                    KeyType = KeyType.Gold
                };
                testKey.Spatial.Position += Conversion.ToMeters(700, 720);
                AddGameObject(testKey);
            }

            {
                var testGate = new Gate();
                testGate.Spatial.Position += Conversion.ToMeters(2300, 1100);
                AddGameObject(testGate);
            }

            {
                var testShop = new Shop();
                testShop.Spatial.Position += Conversion.ToMeters(1300, 500);
                AddGameObject(testShop);

                var testFruitBowl = new ShopItem()
                {
                    ItemType = ShopItemType.FruitBowl
                };
                testFruitBowl.Price = ShopItemPriceType._20;
                testFruitBowl.AttachTo(testShop);
                testFruitBowl.Spatial.Position += Conversion.ToMeters(-110.0f, -90.0f);
                AddGameObject(testFruitBowl);

                var testRod = new ShopItem()
                {
                    ItemType = ShopItemType.FishingRod
                };
                testRod.Price = ShopItemPriceType._100;
                testRod.AttachTo(testShop);
                testRod.Spatial.Position += Conversion.ToMeters(128.0f, -80.0f);
                AddGameObject(testRod);
            }

            {
                var testSinger = new Singer();
                testSinger.Spatial.Position += Conversion.ToMeters(2600, 300);
                AddGameObject(testSinger);
            }

            {
                var testTrap = new SpikeTrap()
                {
                    Orientation = SpikeTrapOrientation.Vertical,
                    SensorReach = 4.0f,
                };
                testTrap.Spatial.Position += Conversion.ToMeters(1600, 500);
                AddGameObject(testTrap);
            }
#endif

            {
                var BackgroundMusic = Content.Load <Song>("snd/FiluAndDina_-_Video_Game_Background_-_Edit");
                MediaPlayer.IsRepeating = true;
#if false
                MediaPlayer.Play(BackgroundMusic);
#endif
            }

            Hud.Initialize();
            Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            Window.ClientSizeChanged += (o, e) =>
            {
                Hud.ResetLayout(GraphicsDevice.Viewport.Bounds);
            };
        }