Exemple #1
0
        public void LoadContent(Level level)
        {
            string groundTextureName    = string.Format(level.ContentNameFormat_Ground, GridPosition.Y, GridPosition.X);
            string collisionContentName = string.Format(level.ContentNameFormat_Collision, GridPosition.Y, GridPosition.X);
            string layoutContentName    = string.Format(level.ContentNameFormat_Layout, GridPosition.Y, GridPosition.X);

            //
            // Screen game object
            //
            {
                _screenGameObject = new BackgroundScreen();
                _screenGameObject.Spatial.Position        += WorldPosition;
                _screenGameObject.ShapeContentName         = collisionContentName;
                _screenGameObject.Sprite.SpriteContentName = groundTextureName;

                Global.Game.AddGameObject(_screenGameObject);
            }

            List <ScreenLayoutInfo> layoutInfos = Global.Game.Content.Load <List <ScreenLayoutInfo> >(layoutContentName);

            foreach (ScreenLayoutInfo layout in layoutInfos)
            {
                var deco = GameObjectFactory.CreateKnown(layout.ObjectType);

#if false
                SpriteAnimationComponent sa = deco.GetComponent <SpriteAnimationComponent>();
                // Choose random initial frame
                sa.OnPostInitialize += delegate()
                {
                    int startFrame = level.Random.Next(3);
                    for (int frameIndex = 0; frameIndex < startFrame; frameIndex++)
                    {
                        sa.ActiveAnimation.AdvanceFrameIndex();
                    }
                };
#endif
                deco.Spatial.Position += layout.OffsetInMeters;
                deco.AttachTo(_screenGameObject);

                Global.Game.AddGameObject(deco);

                _decorationObjects.Add(deco);
            }
        }
Exemple #2
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);
        }