<?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="1" el:revision="0" 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="0.92">
      </el:compatibility>
      <el:modes el:easy="true" 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[
create_world(20, 13)
oxyd_default_flavor="d"

-- Designs
normalFloor="fl-sahara"
visibleFloor="fl-black"
stone="st-blue-sand"
borderFloor="fl-sahara"

-- Trick zum definieren von Fake-Floor
world.DefineSimpleFloor("fl-water-1", 6.4, 2.0, false, "")
display.DefineAlias("fl-water-1", "fl-water")

-- Floor Layer
fill_floor( normalFloor, 0, 0, 3, levelh)
fill_floor( "fl-water", 3, 0, 17, levelh)
fill_floor( normalFloor, 17, 0, levelw, levelh)

fill_floor( borderFloor, 0, 0, levelw,1)
fill_floor( borderFloor, 0, 12, levelw, 1)
fill_floor( borderFloor, 0, 0, 1, levelh)
fill_floor( borderFloor, 19, 0, 1, levelh)

-- Stone Layer
draw_border(stone) --Rand

oxyd(18,1)
oxyd(18,11)

-- Actor Layer
set_actor("ac-blackball", 1.5, 6.5, {player="0", mouseforce="1", name="actor"})

-- Code-Sektion
actor=enigma.GetNamedObject("actor")
verschwunden=false
verdeckt={}
weg={}
anz_felder=0

-- finde Weg
function find_way()
    i=0
    aktX=2
    aktY=1+random(10)
    vorvorrichtung=2
    vorrichtung=2
    rnd=2

    while aktX<16 do
        if aktX<4 then
            aktX=aktX+1
        elseif vorrichtung==2 then
            if rnd==1 and vorvorrichtung~=3 then aktY=aktY-1
            elseif rnd==3 and vorvorrichtung~=1 then aktY=aktY+1
            else aktX=aktX+1 end
        elseif vorrichtung==1 then
            if rnd==1 and vorvorrichtung~=3 then aktY=aktY-1
            else aktX=aktX+1 end
        else
            if rnd==3 and vorvorrichtung~=1 then aktY=aktY+1
            else aktX=aktX+1 end
        end

        vorvorrichtung=vorrichtung
        vorrichtung=rnd
        rnd=random(3)

        if(aktY<1) then aktY=aktY+1
        elseif(aktY>11) then aktY=aktY-1
        else
            i=i+1
            weg[i]={aktX,aktY}
            anz_felder=anz_felder+1 
        end
    end
end

-- zeichne Weg
function draw_way()
    for i,val in pairs(weg) do
        set_floor(visibleFloor,weg[i][1],weg[i][2])
        set_item("it-trigger", weg[i][1],weg[i][2], {action="callback", target="einzelanzeige", invisible=TRUE})
    end
end

-- loesche Weg
function verschwinde()
    if verschwunden==false then
        for i, val in pairs(weg) do
            set_floor("fl-water-1",weg[i][1],weg[i][2])
            verdeckt[weg[i][1]..weg[i][2]]=true
        end
        if not difficult then
            index_i=bin_search_in_weg(7)
            set_floor(normalFloor,7,weg[index_i][2]) 
            set_item("it-extralife",7,weg[index_i][2])
            index_i=bin_search_in_weg(12)
            set_floor(normalFloor,12,weg[index_i][2]) 
            set_item("it-extralife",12,weg[index_i][2])
        end
    end
    verschwunden=true
end

-- mache aktuelles Feld sichtbar
function einzelanzeige()
    if verschwunden==false then
        verschwinde()
    end
    x,y=enigma.GetPos(actor)
    if verdeckt[x..y]==true then
        set_floor(normalFloor,x,y)
    end
    verdeckt[x..y]=false
end

-- suche feld [x=bekannt, y=?]
function bin_search_in_weg(feld)
    found=false
    first=1
    middle=nil
    last=anz_felder

    while found==false and first<=last do 
        middle=first+(math.floor((last-first)/2))    
        if weg[middle][1]==feld then
            found=true
        else
            if feld <= weg[middle][1] then      
                last=middle-1       
            else
                first=middle+1
            end
        end
    end
    return middle
end

-- DO IT
find_way()
draw_way()
    ]]></el:luamain>
    <el:i18n>
      <el:string el:key="title">
        <el:english el:translate="false"/>
      </el:string>
    </el:i18n>
  </el:protected>
</el:level>
