<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<el:level xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://enigma-game.org/schema/level/1 level.xsd" xmlns:el="http://enigma-game.org/schema/level/1">
  <el:protected>
    <el:info el:type="level">
      <el:identity el:title="Shoals" el:subtitle="" el:id="nat27"/>
      <el:version el:score="1" el:release="1" el:revision="0" el:status="released"/>
      <el:author  el:name="Nat Pryce" el:email="" el:homepage=""/>
      <el:copyright>Copyright © 2003 Nat Pryce</el:copyright>
      <el:license el:type="GPL version 2" el:open="true"/>
      <el:compatibility el:enigma="0.92">
       <el:dependency el:path="lib/natmaze" el:id="lib/natmaze" el:release="1" el:preload="true"/>
      </el:compatibility>
      <el:modes el:easy="false" el:single="true" el:network="false"/>
      <el:comments>
        <el:code>Lua 5.1 and XML converted by Leveladministrators</el:code>
      </el:comments>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[
maze_width = 19
maze_height = 6

function cellx_to_worldx( cellx )
    return 2*cellx + 1
end

function celly_to_worldy( celly )
    return 2*celly + 1
end

function maze_floor(x,y)
    set_floor("fl-water", x, y)
end

function maze_wall(x,y)
    set_floor("fl-sand", x, y)
end

function render_cell( maze, cellx, celly )
    local x = cellx_to_worldx(cellx)
    local y = celly_to_worldy(celly)
    
    maze_floor(x,y)
    
    if maze:can_go_east(cellx,celly) then
        maze_floor(x+1,y)
    elseif maze:contains_cell(cellx+1,celly) then
        maze_wall(x+1,y)
    end
    
    if maze:can_go_south(cellx,celly) then
        maze_floor(x,y+1)
    elseif maze:contains_cell(cellx,celly+1) then
        maze_wall(x,y+1)
    end
    
    if maze:contains_cell(cellx+1,celly+1) then
        maze_wall(x+1,y+1)
    end
end

function draw_maze()
    render_maze( new_kruskal_maze(maze_width,maze_height), render_cell )
end


cells = {}

function cell_is_clear(x,y)
    for i = 1,getn(cells) do
        cell = cells[i]
        if cell[1] == x and cell[2] == y then
            return nil
        end
    end
    return 1
end

function random_safe_tile()
    repeat
        x = random(0,maze_width-2)
        y = random(0,maze_height-2)
    until cell_is_clear(x,y)
    
    tinsert(cells, {x,y})
    return {cellx_to_worldx(x)+1,celly_to_worldy(y)+1}
end


create_world( 39, 13 )
fill_floor("fl-water")
draw_maze()

for n = 1,8 do
    p = random_safe_tile()
    oxyd(p[1],p[2])
end

start = random_safe_tile()

set_item("it-spring1", start[1], start[2])
set_actor("ac-blackball", start[1]+0.5, start[2]+0.5, {player=0})
oxyd_shuffle()
    ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
