<?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="A-way" el:subtitle="Sunken Atlantis" el:id="richi06"/>
      <el:version el:score="1" el:release="2" el:revision="4" el:status="released"/>
      <el:author  el:name="Richi Bützer" el:email="" el:homepage="enigma.mal2.ch"/>
      <el:copyright>Copyright © 2005 Richi Bützer</el:copyright>
      <el:license el:type="GPL v2.0 or above" el:open="true"/>
      <el:compatibility el:enigma="1.10"/>
      <el:modes el:easy="true" el:single="true" el:network="false"/>
      <el:comments><el:code>New API converted by R. Bourquin</el:code></el:comments>
      <el:score el:easy="-" el:difficult="-"/>
    </el:info>
    <el:luamain><![CDATA[
ti[" "] = {"fl_water"}
ti["."] = {"fl_water", name="line1#"}
ti[","] = {"fl_water", name="line2#"}
ti["-"] = {"fl_sahara"}
ti["#"] = {"st_bluesand"}
ti["O"] = {"st_oxyd", flavor="d"}
ti["@"] = {"#ac_marble_black", name="ball"}

wo(ti, "-", {
    "####################",
    "#--    .    ,    -O#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#@-    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    --#",
    "#--    .    ,    -O#",
    "####################"})

function generate_way()
    x = 2
    y = math.random(1, 11)
    prev_prev_dir = 2
    prev_dir = 2
    dir = 2

    while x < 16 do
        if x < 4 then
            x = x+1
        elseif prev_dir == 2 then
            if dir == 1 and prev_prev_dir ~=3 then y = y-1
            elseif dir == 3 and prev_prev_dir ~= 1 then y = y+1
            else x = x+1 end
        elseif prev_dir == 1 then
            if dir == 1 and prev_prev_dir ~= 3 then y = y-1
            else x = x+1 end
        else
            if dir == 3 and prev_prev_dir ~= 1 then y = y+1
            else x = x+1 end
        end

        prev_prev_dir = prev_dir
        prev_dir = dir
        dir = math.random(1,3)

        if y < 1 then y = y+1
        elseif y > 11 then y = y-1
        else
            wo[{x, y}] = {"fl_dark", name="way#"} .. ti({"it_trigger", target="clear_way", invisible=true})
        end
    end
end

function clear_way(value, sender)
    sender.target = DEFAULT
    if not wo["IsDifficult"] then
        easy_islands()
    end
    wo[sender] = ti["-"]
    wo[no["way#*"]] = {"fl_water"} .. ti({"it_trigger", target="walk_way", invisible=true})
end

function walk_way(value, sender)
    sender.target = DEFAULT
    wo[sender] = ti["-"]
end

function easy_islands()
    island1 = no["way#*"] * fl(po["line1#*"])
    island2 = no["way#*"] * fl(po["line2#*"]) 
    wo[ island1:shuffle():sub(1) ] = ti["-"] .. {"it_extralife"}
    wo[ island2:shuffle():sub(1) ] = ti["-"] .. {"it_extralife"}
end

generate_way()
 ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
