home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Geschicklichkeit / Enigma / Enigma-081.exe / data / levels / ralf03.lua < prev    next >
Text File  |  2003-03-28  |  5KB  |  217 lines

  1. -- A level for Enigma
  2. -- Name:        Welcome to the machine
  3. -- Filename:     ralf03.lua
  4. -- Copyright:     (C) Mar 2003 Ralf Westram
  5. -- Contact:     amgine@reallysoft.de
  6. -- License:     GPL v2.0 or above
  7.  
  8. dofile(enigma.FindDataFile("levels/ralf.lua"))
  9.  
  10. --debug_mode()
  11.  
  12. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  13.  
  14. first = 1
  15.  
  16. lightfloorface = "fl-sahara"
  17. darkfloorface  = "fl-tigris"
  18. bluefloorface  = "fl-bluegray"
  19.  
  20. stonefaces   = { "st-rock1", "st-rock6", "st-rock2", "st-rock3"}
  21. rotdirection = { 1, -1, 1, -1 }
  22. switchface   = "st-switch"
  23. borderface   = "st-rock5"
  24.  
  25. lightfloor   = cell{floor={face = lightfloorface}}
  26. border       = cell{stone={face = borderface}}
  27. --marble       = cell{item={face  = "ac-blackball", attr={player=0}, actor=1}}
  28. marble       = cell{actor={face="ac-blackball", attr={player=0}}}
  29.  
  30. test = 0 -- test layout
  31. easy = 1 -- 1=easy 0=hard
  32.  
  33. mx,my = 1,1
  34.  
  35. if (test==0) then
  36.    floormap={
  37.       "**   **",
  38.       "*     *",
  39.       "   !   ",
  40.       "  !!!  ",
  41.       "   !   ",
  42.       "*     *",
  43.       "**   **"
  44.    }
  45.    stonemap={
  46.       "  #    ",
  47.       " ##### ",
  48.       "##   ##",
  49.       " # O   ",
  50.       " #   ##",
  51.       " $# ## ",
  52.       "  & #  "
  53.    }
  54.    metamap={
  55.       "2413",
  56.       "4324",
  57.       "3112",
  58.    }
  59.    mx,my = 2,2
  60.  
  61. elseif (test==1) then
  62.    easy = 1
  63.    floormap={
  64.       "* ! *",
  65.       "  !  ",
  66.       "!!!!!",
  67.       "  !  ",
  68.       "* ! *"
  69.    }
  70.    stonemap={
  71.       " & & ",
  72.       " # ##",
  73.       "  O  ",
  74.       "#$ # ",
  75.       " # # "
  76.    }
  77.    metamap={
  78.       "4231",
  79.       "3421",
  80.       "1234",
  81.       "3142",
  82.    }
  83.    mx,my = 3,2
  84.  
  85. end
  86.  
  87. floorcells={}
  88. floorcells["*"] = cell{parent = lightfloor}
  89. floorcells[" "] = cell{floor={face = darkfloorface}}
  90. floorcells["!"] = cell{floor={face = bluefloorface}}
  91.  
  92. -- ---------------
  93. --     metamap
  94. -- ---------------
  95.  
  96. usedmap   = nil
  97. usedcells = nil
  98. currmetacell = nil
  99.  
  100. function draw_used_metamap_oriented(x,y,flipx,flipy,rotate)
  101.    draw_metamap_oriented(x,y,usedmap,usedcells,flipx, flipy,rotate)
  102. end
  103.  
  104. metacellstate={1,2,3,4}
  105. nextState={2,3,4,1} -- rotate
  106. --nextState={2,1,4,3} -- toggle
  107.  
  108. function draw_metacell(x,y,metacellnum)
  109.    currmetacell = metacellnum --store for switch callback
  110.    draw_metamap_oriented(x,y,usedmap,usedcells,0,0,metacellstate[metacellnum])
  111. end
  112.  
  113. metacells={}
  114. metacells["1"] = cell{parent={{draw_metacell,1}}}
  115. metacells["2"] = cell{parent={{draw_metacell,2}}}
  116. metacells["3"] = cell{parent={{draw_metacell,3}}}
  117. metacells["4"] = cell{parent={{draw_metacell,4}}}
  118.  
  119. function draw_my_metamap()
  120.    draw_map(0,0,metamap,metacells)
  121. end
  122.  
  123. -- ----------------
  124. --     rotation
  125. -- ----------------
  126.  
  127. function rot(cellnum)
  128.    local oldstate = metacellstate[cellnum]
  129.    local newstate = oldstate + rotdirection[cellnum]
  130.    if (newstate < 1) then newstate = 4
  131.    elseif (newstate > 4) then newstate = 1
  132.    end
  133.  
  134.    metacellstate[cellnum] = newstate
  135.    debug("rot cell #"..cellnum.." from state "..oldstate.." to "..newstate)
  136.  
  137.    draw_my_metamap()
  138. end
  139.  
  140. function rot1() rot(1) end
  141. function rot2() rot(2) end
  142. function rot3() rot(3) end
  143. function rot4() rot(4) end
  144. function rot0() error("illegal rotation callback (0)")  end
  145. function rot5() error("illegal rotation callback (5)")  end
  146.  
  147. function add_oxyd(x,y) if (first==1) then oxyd(x,y) end end
  148. function add_stone(x,y) set_stone(stonefaces[currmetacell],x,y) end
  149. function rem(x,y) if (first==0) then enigma.KillStone(x,y) end end
  150.  
  151. function repby_switch(x,y)
  152.    rem(x,y)
  153.    set_stone(switchface,x,y,{action="callback", target="rot"..currmetacell})
  154. end
  155. function repby_stone(x,y)
  156.    rem(x,y)
  157.    set_stone(stonefaces[currmetacell],x,y)
  158. end
  159. function repby_stone_or_gap(x,y)
  160.    rem(x,y)
  161.    if (currmetacell ~= 2) then
  162.       set_stone(stonefaces[currmetacell],x,y)
  163.    end
  164. end
  165.  
  166.  
  167. stonecells={}
  168. stonecells["O"]=cell{parent={{add_oxyd}}}
  169. stonecells[" "]=cell{parent={{rem}}}
  170. stonecells["#"]=cell{parent={{repby_stone}}}
  171. stonecells["$"]=cell{parent={{repby_switch}}}
  172. if (easy==1) then
  173.    stonecells["&"]=cell{parent={{repby_stone_or_gap}}}
  174. else
  175.    stonecells["&"]= stonecells["#"]
  176. end
  177.  
  178. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  179. -- build the level
  180.  
  181. mapw,maph       = get_map_size(metamap)
  182. blockw,blockh   = get_map_size(stonemap)
  183. blockw2,blockh2 = get_map_size(floormap)
  184.  
  185. if ((blockh ~= blockh2) or (blockw ~= blockw2)) then
  186.    error("floormap and stonemap must be of same size");
  187. end
  188.  
  189. worldw,worldh = mapw*blockw+2,maph*blockh+2
  190.  
  191. create_world(worldw, worldh)
  192. oxyd_default_flavor = "a"
  193. enigma.ConserveLevel = FALSE
  194.  
  195. fill_world_func(lightfloor)
  196. draw_border_func(border)
  197.  
  198. -- draw the floor
  199. usedmap   = floormap
  200. usedcells = floorcells
  201. draw_my_metamap()
  202.  
  203. -- draw the items
  204. usedmap = stonemap
  205. usedcells = stonecells
  206. draw_my_metamap()
  207.  
  208. first = 0
  209.  
  210. document(4*blockw,1*blockh,"Sections which have the same color always turn at the same time and in the same way.")
  211.  
  212. oxyd_shuffle()
  213. display.SetFollowMode(display.FOLLOW_SCROLLING)
  214. marble(mx*blockw+0.5,my*blockh+0.5)
  215.  
  216.  
  217.