home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Geschicklichkeit / Enigma / Enigma-081.exe / data / levels / natmaze6.lua < prev    next >
Text File  |  2003-01-05  |  4KB  |  166 lines

  1. -- Magritte
  2. -- A level for Enigma
  3. -- Copyright (c) 2002 Nat Pryce
  4. -- License: GPL v2.0 or above
  5.  
  6. dofile( enigma.FindDataFile("levels/natmaze.lua") )
  7.  
  8.  
  9. maze = new_kruskal_maze( 12, 12 )
  10. startx, starty = random(maze.width-2), random(maze.height-2)
  11. offsetx = 2
  12. offsety = 2
  13. cell_side = 5
  14. cell_gap = 1
  15. last_trigger = nil
  16.  
  17.  
  18. function cell_to_level( cellx, celly )
  19.     local x = offsetx + cellx * cell_side + (cellx-1) * cell_gap
  20.     local y = offsety + celly * cell_side + (celly-1) * cell_gap
  21.     return x, y
  22. end
  23.  
  24. function at_corner( x, y )
  25.     return x == 0 and y == 0
  26.         or x == 0 and y == maze.height - 1
  27.         or x == maze.width-1 and y == 0
  28.         or x == maze.width-1 and y == maze.height-1
  29. end
  30.  
  31. function at_start( x, y )
  32.     return x == startx and y == starty
  33. end
  34.  
  35. random_stones = {
  36.     "st-grate1",
  37.     "st-fakeoxyd",
  38.     "st-brownie",
  39.     "st-glass",
  40.     "st-chameleon",
  41.     "st-greenbrown",
  42.     "st-greenbrown_hole",
  43.     "st-greenbrown_move",
  44.     "st-invisible"
  45. }
  46.  
  47. random_floors = {
  48.     "fl-rough",
  49.     "fl-leaves",
  50.     "fl-gray",
  51.     "fl-dunes",
  52.     "fl-sand",
  53. }
  54.  
  55. function draw_cell( cellx, celly )
  56.     local x,y = cell_to_level( cellx, celly )
  57.     
  58.     fill_floor( "fl-wood", x, y, cell_side, cell_side )
  59.     fill_floor( random_element(random_floors),
  60.                 x+1, y+1, cell_side-2, cell_side-2 )
  61.     
  62.     if not at_corner(cellx,celly) and not at_start(cellx,celly) then
  63.         if random() < 0.5 then
  64.             set_stone( random_element(random_stones), x+2, y+2 )
  65.         end
  66.     end
  67. end
  68.  
  69. function draw_cells()
  70.     for celly = 0,maze.height-1 do
  71.         for cellx = 0,maze.width-1 do
  72.             draw_cell( cellx, celly )
  73.         end
  74.     end
  75. end
  76.  
  77. function draw_link( cellx, celly, test_link, x, y )
  78.     if test_link( maze, cellx, celly ) then
  79.         set_floor( "fl-wood", x, y )
  80.     else
  81.         set_floor( "fl-water", x, y )
  82.     end
  83. end
  84.  
  85. function draw_links_for_cell( cellx, celly )
  86.     local x,y = cell_to_level( cellx, celly )
  87.     local offset = cell_side/2 + 1
  88.     
  89.     x = x + 2
  90.     y = y + 2
  91.     
  92.     draw_link( cellx, celly, maze.can_go_north, x, y-3 )
  93.     draw_link( cellx, celly, maze.can_go_south, x, y+3 )
  94.     draw_link( cellx, celly, maze.can_go_west, x-3, y )
  95.     draw_link( cellx, celly, maze.can_go_east, x+3, y )
  96. end
  97.  
  98. function draw_links()
  99.     for celly = 0,maze.height-1 do
  100.         for cellx = 0,maze.width-1 do
  101.             draw_links_for_cell( cellx, celly )
  102.         end
  103.     end
  104. end
  105.  
  106.  
  107.  
  108. last_regenerate_id = nil
  109.  
  110. function regenerate_maze( trigger_pressed, id )
  111.     if trigger_pressed == 1 and id ~= last_regenerate_id then
  112.         maze = new_kruskal_maze( maze.width, maze.height )
  113.         draw_links()
  114.         last_regenerate_id = id
  115.     end
  116. end
  117.  
  118. function trigger_callback_1( trigger_pressed )
  119.     regenerate_maze( trigger_pressed, 1 )
  120. end
  121. function trigger_callback_2( trigger_pressed )
  122.     regenerate_maze( trigger_pressed, 2 )
  123. end
  124. function trigger_callback_3( trigger_pressed )
  125.     regenerate_maze( trigger_pressed, 3 )
  126. end
  127. function trigger_callback_4( trigger_pressed )
  128.     regenerate_maze( trigger_pressed, 4 )
  129. end
  130.  
  131.  
  132. function set_oxyd( cellx, celly, callback )
  133.     local x,y = cell_to_level( cellx, celly )
  134.     oxyd(x+2,y+2)
  135.     
  136.     set_regenerate_trigger( x, y+cell_side/2, callback )
  137.     set_regenerate_trigger( x+cell_side/2, y, callback )
  138.     set_regenerate_trigger( x+cell_side-1, y+cell_side/2, callback )
  139.     set_regenerate_trigger( x+cell_side/2, y+cell_side-1, callback )
  140. end
  141.  
  142. function set_regenerate_trigger( x, y, callback )
  143.     set_item( "it-trigger", x, y, 
  144.               {target=callback, action="callback"} )
  145. end
  146.  
  147.  
  148. create_world( maze.width*cell_side + (maze.width-1)*cell_gap + 2*offsetx + 2,
  149.               maze.height*cell_side + (maze.height-1)*cell_gap + 2*offsety )
  150.  
  151. fill_floor( "fl-water", 0, 0, level_width, level_height )
  152. draw_cells()
  153. draw_links()
  154.  
  155. set_oxyd( 0, 0, "trigger_callback_1" )
  156. set_oxyd( 0, maze.height-1, "trigger_callback_2" )
  157. set_oxyd( maze.width-1, 0, "trigger_callback_3" )
  158. set_oxyd( maze.width-1, maze.height-1, "trigger_callback_4" )
  159.  
  160.  
  161. actorx, actory = cell_to_level( startx, starty )
  162. set_actor( "ac-blackball", actorx + 2.5, actory + 2.5, { player=0 } )
  163. display.SetFollowMode(display.FOLLOW_SCROLLING)
  164.  
  165.  
  166.