Пример #1
0
 public void Load()
 {
     if (!LevelLoaded)
     {
         try
         {
             if (IOHelper.Instance.CreateDirectory(levelDir))
             {
                 if (IOHelper.Instance.DoesFileExist(levelDir + "level" + levelID + ".json"))
                 {
                     level = JsonConvert.DeserializeObject<LevelFormat>(IOHelper.Instance.ReadFile(levelDir + "level" + levelID + ".json"));
                     LevelLoaded = true;
                 }
                 else
                 {
                     throw new FileNotFoundException(levelDir + "level" + levelID + ".json doesn't exsist");
                 }
             }
             else
             {
                 throw new Exception("Couldn't create dir");
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
Пример #2
0
 public GameScreen(LevelFormat level, bool test = true)
 {
     loader = new LevelLoader(level);
     GameObjects = new List<object>();
     player = new Player();
     objectives = new List<Objective>();
     drawAbleItems = new List<IDrawAble>();
     levelID = -1;
     testing = test;
 }
Пример #3
0
        public override void LoadLevel(LevelFormat level)
        {
            player.StartPosition = level.playerInfo.position;
            player.StartMovement = level.playerInfo.startMovement;
            player.ChangePosition(level.playerInfo.position);
            player.ChangeMovement(level.playerInfo.startMovement);

            if (level.playerInfo.useCustomBoundingbox)
            {
                player.SetCustomBoundingbox(new Rectangle(level.playerInfo.x, level.playerInfo.y, level.playerInfo.width, level.playerInfo.height));
            }

            base.LoadLevel(level);
        }
Пример #4
0
        private LevelFormat GetLevelFormat()
        {
            LevelFormat lvl = new LevelFormat();

            List<object> allLayerObjects = AllLayerObjects();

            foreach (object o in allLayerObjects)
            {
                if (o is Player)
                {
                    lvl.playerInfo = (o as Player).Info;
                }
                else if (o is ClickableObject)
                {
                    lvl.clickObjectsInfo.Add((o as ClickableObject).Info);
                }
                else if (o is MovementTile)
                {
                    lvl.moveTiles.Add((o as MovementTile).Info);
                }
                else if (o is WinTile)
                {
                    lvl.moveTiles.Add((o as WinTile).Info);
                }
                else if (o is Decoration)
                {
                    lvl.decoration.Add((o as Decoration).Info);
                }
                else if (o is GridTileInfo)
                {
                    lvl.Grid.Add((o as GridTileInfo));
                }
            }

            return lvl;
        }
        public override void LoadLevel(LevelFormat level)
        {
            foreach (ClickAbleInfo info in level.clickObjectsInfo)
            {
                ClickableObject clickObj = new ClickableObject();

                bool found = false;
                foreach(Tuple<string,Texture2D> tup in textures)
                {
                    if(tup.Item1 == info.texturePath)
                    {
                        found = true;
                        clickObj.Image = tup.Item2;
                        clickObj.TexturePath = tup.Item1;
                    }
                }

                // Texture not found just drop it
                if (!found)
                    continue;

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }

                clickObj.StartPosition = info.position;
                clickObj.Position = info.position;
                clickObj.moveToPosition = info.moveToPosition;
                clickObj.TexturePath = info.texturePath;

                // Check if the object has an animation
                if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                {
                    AnimationInfo aInfo = JsonConvert.DeserializeObject<AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                    clickObj.Animation = new Animation(Game1.Instance.Content.Load<Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                }

                clickObj.ObjectiveID = info.objectiveID;

                if (info.useCustomBounds)
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                clickables.Add(clickObj);
                clickablesCount++;
            }

            base.LoadLevel(level);
        }
Пример #6
0
 public LevelLoader(LevelFormat level)
 {
     this.level = level;
     LevelLoaded = true;
 }
Пример #7
0
        public void SaveLevel()
        {
            LevelFormat lvl = new LevelFormat();
            lvl.playerInfo = player.Info;
            lvl.clickObjectsInfo = new List<ClickAbleInfo>();

            foreach(object o in GameObjects)
            {
                if (o is ClickableObject)
                {
                    lvl.clickObjectsInfo.Add((o as ClickableObject).Info);
                }
                else if (o is MovementTile)
                {
                    lvl.moveTiles.Add((o as MovementTile).Info);
                }
                else if(o is WinTile)
                {
                    lvl.moveTiles.Add((o as WinTile).Info);
                }
            }

            LevelManager.Instance.SaveLevel(lvl, levelID);
        }
Пример #8
0
 public void LoadFromLevelInfo(LevelFormat lvl)
 {
     if (lvl.Grid != null && lvl.Grid.Count > 0)
     {
         foreach (GridTileInfo info in lvl.Grid)
         {
             grid[info.column, info.row] = info.cliprect;
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Save an level
 /// </summary>
 /// <param name="lvl">The level file</param>
 /// <param name="levelID">The ID of the level</param>
 public void SaveLevel(LevelFormat lvl, int levelID)
 {
     IOHelper.Instance.WriteFile(@"\levels\" + "level"+levelID+".json", JsonConvert.SerializeObject(lvl,Formatting.Indented));
 }
Пример #10
0
 public virtual void LoadLevel(LevelFormat level)
 {
 }
 public override void LoadLevel(LevelFormat level)
 {
     base.LoadLevel(level);
 }
Пример #12
0
        public override void LoadLevel(LevelFormat level)
        {
            foreach(DecorationInfo d in level.decoration)
            {
                Decoration decoration = new Decoration(d.ImagePath);
                decoration.Position = d.position;

                for (int i = 0; i < decorationImages.Count; i++)
                {
                    if (decorationImages[i].Item1 == d.ImagePath)
                    {
                        decoration.Image = decorationImages[i].Item2;
                        break;
                    }
                }

                tiles.Add(decoration);
            }

            base.LoadLevel(level);
        }