Sector.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // $Id: foo.cpp 2979 2006-01-10 00:00:04Z sommer $
  2. //
  3. // Cobble - A simple SuperTux level editor
  4. // Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.de>
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU General Public License
  8. // as published by the Free Software Foundation; either version 2
  9. // of the License, or (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. // 02111-1307, USA.
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Text;
  23. using Lisp;
  24. namespace Cobble {
  25. public class Sector {
  26. public string name;
  27. public string music;
  28. public float gravity;
  29. public List<Tilemap> tilemaps;
  30. public Background background;
  31. public List<GameObject> gameObjects;
  32. //FIXME: More to come
  33. public Sector(Parser parser) {
  34. this.tilemaps = new List<Tilemap>();
  35. this.gameObjects = new List<GameObject>();
  36. int d = parser.Depth;
  37. while (parser.Parse() && parser.Depth >= d) {
  38. if (parser.Depth == d + 1) {
  39. if (parser.Type != Parser.LispType.SYMBOL)
  40. throw new Exception("expected SYMBOL");
  41. string symbol = parser.SymbolValue;
  42. parser.Parse();
  43. switch (symbol) {
  44. case "name":
  45. this.name = parser.StringValue;
  46. break;
  47. case "music":
  48. this.music = parser.StringValue;
  49. break;
  50. case "gravity":
  51. this.gravity = parser.FloatValue;
  52. break;
  53. case "tilemap":
  54. this.tilemaps.Add(new Tilemap(parser));
  55. break;
  56. case "background":
  57. this.background = new Background(parser);
  58. break;
  59. default:
  60. //this.gameObjects.Add(new GameObject(symbol, parser));
  61. this.gameObjects.Add(GameObject.Parse(symbol, parser));
  62. //Console.WriteLine("WARNING: Unknown tile element " + symbol + ", skipping");
  63. //SkipList(parser);
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. public Sector(string name) {
  70. this.name = name;
  71. this.music = "music/chipdisko.ogg";
  72. this.gravity = 10.0F;
  73. this.tilemaps = new List<Tilemap>();
  74. this.tilemaps.Add(new Tilemap(-100, false, 310, 19));
  75. this.tilemaps.Add(new Tilemap(0, true, 310, 19));
  76. this.tilemaps.Add(new Tilemap(100, false, 310, 19));
  77. this.background = new Background("images/background/arctis.jpg", 0.5F);
  78. this.gameObjects = new List<GameObject>();
  79. this.gameObjects.Add(new Spawnpoint("main", 100, 100));
  80. }
  81. public void Write(LispWriter writer) {
  82. writer.StartList("sector");
  83. writer.Write("name", this.name);
  84. writer.Write("music", this.music);
  85. writer.Write("gravity", this.gravity);
  86. foreach (Tilemap tilemap in this.tilemaps) {
  87. tilemap.Write(writer);
  88. }
  89. background.Write(writer);
  90. writer.StartList("camera");
  91. writer.Write("mode", "normal");
  92. writer.EndList("camera");
  93. foreach (GameObject gameObject in this.gameObjects) {
  94. gameObject.Write(writer);
  95. }
  96. writer.EndList("sector");
  97. }
  98. public override string ToString() {
  99. return this.name;
  100. }
  101. private static void SkipList(Lisp.Parser parser) {
  102. int d = parser.Depth;
  103. while (parser.Parse() && parser.Depth >= d)
  104. ;
  105. }
  106. }
  107. }