Exemplo n.º 1
0
        /// <summary>
        /// Initializes the Level.
        /// </summary>
        /// <param name="levelInfoFilepath">The filepath for the
        /// file where this Level is going to get it's information from.</param>
        internal void Initate(string levelInfoFilepath)
        {
            LevelInfo info = Common.ContentManager.Load <LevelInfo>(levelInfoFilepath);

            levelName = info.LevelName;

            for (int i = 0; i < info.LevelObjects.Count; i++)
            {
                object obj = AssemblyManager.CreateInstance(info.LevelObjects[i]);

                if (!(obj is PlayerStart) || !(obj is ILevelAsset) || !(obj is IExit))
                {
                    if (obj is ObjectComponent)
                    {
                        AttachComponent(obj as ObjectComponent);
                    }
                    else
                    {
                        levelObjects.Add(obj);
                    }
                }
                else
                {
                    bool added = false;

                    if (obj is ILevelAsset)
                    {
                        obj = (from a in levelAssets
                               where a.ID == (obj as ILevelAsset).ID
                               select a).FirstOrDefault();

                        if (obj == null)
                        {
                            levelAssets.Add(obj as ILevelAsset);
                            added = true;
                        }
                    }

                    if (obj is PlayerStart && added)
                    {
                        if (playerStart == null)
                        {
                            playerStart = obj as PlayerStart;
                        }
                        else
                        {
                            new DuplicateError("Their is already a PlayerStart object in this Level. The object: "
                                               + (obj as PlayerStart).ID + " is invalid and will not be used.");
                        }
                    }

                    if (obj is IExit && added)
                    {
                        levelExits.Add(obj as IExit);
                    }

                    if (obj is IUpdate && added)
                    {
                        updateables.Add(obj as IUpdate);
                    }

                    if (obj is ObjectComponent)
                    {
                        AttachComponent(obj as ObjectComponent);
                    }
                }
            }

            foreach (ILevelAsset asset in levelAssets)
            {
                asset.LevelTransitionOn(levelName);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the Level.
        /// </summary>
        /// <param name="levelInfoFilepath">The filepath for the
        /// file where this Level is going to get it's information from.</param>
        internal void Initate(string levelInfoFilepath)
        {
            LevelInfo info = Common.ContentManager.Load <LevelInfo>(levelInfoFilepath);

            levelName = info.LevelName;

            for (int i = 0; i < info.LevelObjects.Length; i++)
            {
                object obj = AssemblyManager.CreateInstance(info.LevelObjects[i]);

                if (obj is ILevelAsset)
                {
                    if (levelAssets.Count > 0)
                    {
                        obj = (from a in levelAssets
                               where a.ID == (obj as ILevelAsset).ID
                               select a).FirstOrDefault();

                        if (obj == null)
                        {
                            levelAssets.Add(obj as ILevelAsset);
                        }
                    }
                    else
                    {
                        levelAssets.Add(obj as ILevelAsset);
                    }
                }

                if (obj is PlayerStart)
                {
                    if (playerStart == null)
                    {
                        playerStart = obj as PlayerStart;
                    }
                    else
                    {
                        throw new ArgumentException("Their is already a PlayerStart object in this Level. The object: "
                                                    + (obj as PlayerStart).ID + " is invalid and will not be used.");
                    }
                }

                if (obj is IExit)
                {
                    levelExits.Add(obj as IExit);
                }

                if (obj is IUpdate)
                {
                    updateables.Add(obj as IUpdate);
                }

                if (obj is GameObject)
                {
                    ((GameObject)obj).AddReference(this);
                    gameObjects.Add(obj as GameObject);
                }
            }

            foreach (ILevelAsset asset in levelAssets)
            {
                if (asset != null)
                {
                    asset.LevelTransitionOn(levelName);
                }
            }
        }