levelconverter-0.0.6_0.0.7.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/python
  2. import sys
  3. translate_array \
  4. =[['.', "none", 0],
  5. ['0', "enemy0", 0],
  6. ['1', "enemy1", 1],
  7. ['2', "enemy2", 2],
  8. ['x', "brick0.png", 105],
  9. ['X', "brick0.png", 77],
  10. ['y', "brick1.png", 104],
  11. ['Y', "brick1.png", 78],
  12. ['A', "box-full.png", 83],
  13. ['B', "box-full.png", 102],
  14. ['!', "box-full.png", 103],
  15. ['a', "box-empty.png", 84],
  16. ['C', "cloud-00.png", 85],
  17. ['D', "cloud-00.png", 86],
  18. ['E', "cloud-00.png", 87],
  19. ['F', "cloud-00.png", 88],
  20. ['c', "cloud-00.png", 89],
  21. ['d', "cloud-00.png", 90],
  22. ['e', "cloud-00.png", 91],
  23. ['f', "cloud-00.png", 92],
  24. ['G', "bkgd-00.png", 93],
  25. ['H', "bkgd-01.png", 94],
  26. ['I', "bkgd-02.png", 95],
  27. ['J', "bkgd-03.png", 96],
  28. ['g', "bkgd-10.png", 97],
  29. ['h', "bkgd-11.png", 98],
  30. ['i', "bkgd-12.png", 99],
  31. ['j', "bkgd-13.png", 100],
  32. ['#', "solid0.png", 11],
  33. ['[', "solid1.png", 13],
  34. ['=', "solid2.png", 14],
  35. [']', "solid3.png", 15],
  36. ['$', "distro", 82],
  37. ['^', "water", 76],
  38. ['*', "poletop.png", 80],
  39. ['|', "pole.png", 79],
  40. ['\\',"flag.png", 81],
  41. ['&', "water.png", 75]]
  42. def translate(c):
  43. for i in translate_array:
  44. if c == i[0]:
  45. return i[2]
  46. print >>sys.stderr, "Couldn't translate tile %s" % c
  47. return 0
  48. if len(sys.argv) != 2:
  49. print "Usage: %s FILENAME" % sys.argv[0]
  50. sys.exit()
  51. print ";; Converting:", sys.argv[1]
  52. f = open(sys.argv[1], 'r')
  53. mycontent = f.readlines()
  54. content = []
  55. for i in mycontent:
  56. content.append(i[:-1])
  57. name = content[0]
  58. theme = content[1]
  59. time = content[2]
  60. music = content[3]
  61. background = content[4]
  62. red = content[5]
  63. green = content[6]
  64. blue = content[7]
  65. width = content[8]
  66. height = "15"
  67. gravity = content[9]
  68. print "(supertux-level"
  69. print " (version 1)"
  70. print " (name \"%s\")" % name
  71. print " (theme \"%s\")" % theme
  72. print " (music \"%s\")" % music
  73. print " (background \"%s\")" % background
  74. print " (bkgd_red %s)" % red
  75. print " (bkgd_green %s)" % green
  76. print " (bkgd_blue %s)" % blue
  77. print " (time %s)" % time
  78. print " (width %s)" % width
  79. print " (gravity %s)" % gravity
  80. print " (interactive-tm "
  81. for i in content[10:]:
  82. for x in i:
  83. sys.stdout.write("%3d" % translate(x))
  84. sys.stdout.write(" ")
  85. print ""
  86. print " )"
  87. print " (objects"
  88. for y in range(0, 15):
  89. for x in range(0, int(width)):
  90. val = content[10 + y][x]
  91. if val == '0':
  92. print " (bsod (x %d) (y %d))" % (x*32, y*32)
  93. elif val == '1':
  94. print " (laptop (x %d) (y %d))" % (x*32, y*32)
  95. elif val == '2':
  96. print " (money (x %d) (y %d))" % (x*32, y*32)
  97. print " )"
  98. print ")"
  99. # EOF #