Example #1
0
        public static Level LoadLevel(string levelName)
        {
            string path = levelName.ToLower().StartsWith("resources/levels/")
                ? levelName : "resources/levels/" + levelName;

            path += ".json";

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("Level " + levelName + " not found at path: " + path);
            }


            Console.WriteLine("Loading level " + levelName);
            Stopwatch timer = Stopwatch.StartNew();

            string json = File.ReadAllText(path);

            Level level = JsonConvert.DeserializeObject <Level>(json);

            levels.Add(level);

            LevelObject lo = level.levelObjects[0];

            Console.WriteLine("Is {0} collides: {1}", lo.objectName, lo.CollidesPosition(130, 130));


            timer.Stop();
            Console.WriteLine("Loaded in {0} ms", timer.ElapsedMilliseconds);
            timer.Reset();

            return(level);
        }