Beispiel #1
0
 public Layer(Game game, string filename, int number)
     : base(game)
 {
     Size = Vector2.Zero;
     Tiles = new List<Tile>();
     Enemies = new List<Enemy>();
     Doors = new List<Door>();
     goal = null;
     hasStart = false;
     LayerNumber = number;
     LoadLayer(filename);
 }
Beispiel #2
0
 /// <summary>
 /// Parse an individual line from the file
 /// </summary>
 /// <param name="line">The text in the line</param>
 /// <param name="lineNum">The line number to allow placement of objects</param>
 private void ParseLine(string line, int lineNum)
 {
     for (int x = 0; x < line.Length; x++)
     {
         switch (line[x])
         {
             case ' ':
                 continue;
             case '.':
                 continue;
             case 'p':
                 //TODO add platform
                 break;
             case 'x':
                 Tiles.Add(new Tile(
                         Game,
                         new Vector2(x / 2, lineNum),
                         Collision.Platform));
                 break;
             case 's':
                 hasStart = true;
                 Start = new Vector2(x / 2, lineNum);
                 Debug.WriteLine("start: " + Start);
                 break;
             case 'b':
                 Enemies.Add(new Enemy(Game, x/2, lineNum));
                 break;
             case 'w':
                 goal = new GoalDoor(Game, -1, x / 2, lineNum);
                 break;
             default:
                 try
                 {
                     int integer = Int32.Parse(line[x].ToString());
                     Doors.Add(new Door(Game, integer, x / 2, lineNum));
                 }
                 catch
                 {
                     Debug.WriteLine("Malformed input file");
                 }
                 break;
         }
     }
 }