Example #1
0
        public static GameObject CreateKnown(KnownGameObject type)
        {
            GameObject go = new GameObject();

            switch (type)
            {
            case KnownGameObject.Owliver:
            {
                go = new Owliver();
            }
            break;

            case KnownGameObject.Shop:
            {
                go = new Shop();
            }
            break;

            case KnownGameObject.Slurp:
            {
                go = new Slurp();
            }
            break;

            case KnownGameObject.Tankton:
            {
                go = new Tankton();
            }
            break;

            case KnownGameObject.DeathConfetti:
            {
                go = new DeathConfetti();
            }
            break;

            case KnownGameObject.Projectile:
            {
                go = new Projectile();
            }
            break;

            case KnownGameObject.BackgroundScreen:
            {
                go = new BackgroundScreen();
            }
            break;

            case KnownGameObject.Gate:
            {
                go = new Gate();
            }
            break;

            case KnownGameObject.Flora_Fir:
            case KnownGameObject.Flora_FirAlt:
            case KnownGameObject.Flora_Conifer:
            case KnownGameObject.Flora_ConiferAlt:
            case KnownGameObject.Flora_Oak:
            case KnownGameObject.Flora_Orange:
            case KnownGameObject.Flora_Bush:
            {
                FloraType floraType = (FloraType)(type - KnownGameObject.Flora_Fir);
                go = new Flora()
                {
                    TreeType = floraType,
                };
            }
            break;

            case KnownGameObject.Bonbon_Gold:
            case KnownGameObject.Bonbon_Red:
            {
                BonbonType bonbonType = (BonbonType)(type - KnownGameObject.Bonbon_Gold);
                go = new BonbonPickup()
                {
                    BonbonType = bonbonType,
                };
            }
            break;

            case KnownGameObject.Key_Gold:
            {
                KeyType keyType = (KeyType)(type - KnownGameObject.Key_Gold);
                go = new KeyPickup()
                {
                    KeyType = keyType,
                };
            }
            break;

            case KnownGameObject.ShopItem_FruitBowl:
            case KnownGameObject.ShopItem_FishingRod:
            case KnownGameObject.ShopItem_Stick:
            {
                ShopItemType itemType = (ShopItemType)(type - KnownGameObject.ShopItem_FruitBowl);
                go = new ShopItem()
                {
                    ItemType = itemType
                };
            }
            break;

            case KnownGameObject.Random_FirTree:
            {
                FloraType floraType = _random.Choose(FloraType.Fir, FloraType.Conifer);
                go = new Flora()
                {
                    TreeType = floraType,
                };
            }
            break;

            case KnownGameObject.Random_FirTreeAlt:
            {
                FloraType floraType = _random.Choose(FloraType.FirAlt, FloraType.ConiferAlt);
                go = new Flora()
                {
                    TreeType = floraType,
                };
            }
            break;

            case KnownGameObject.Random_OakTree:
            {
                FloraType floraType = _random.Choose(FloraType.Oak, FloraType.Orange);
                go = new Flora()
                {
                    TreeType = floraType,
                };
            }
            break;

            default:
                throw new ArgumentException("Unknown game object type.");
            }

            int instanceID = _knownCreationCount[(int)type]++;

            go.Name = $"{type}_{instanceID}";

            return(go);
        }
Example #2
0
        /// <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);
            };
        }