-- The Turtle -- the Enigma Level -- (c) 2002 Petr Machata/ant_39 -- Licensed under GPL v2.0 or above floortile = "fl-sand" bordertile = "st-rock1" walltile = bordertile levelw = 20 levelh = 13 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- create_world(levelw, levelh) fill_floor(floortile, 0, 0, level_width, level_height) draw_border(bordertile) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --constants and preparations x1 = 6 y1 = 0 --turtle state ingame = nil --command constants command_clean = -1 command_north = enigma.NORTH command_south = enigma.SOUTH command_west = enigma.WEST command_east = enigma.EAST --default command value command=command_clean --table to translate current command to stone properties function new_command(flx0, fly0, face0, params0) ret = {} ret.face = face0 ret.par = params0 ret.x = flx0 ret.y = fly0 return ret end buftable = {} buftable [command_clean] = new_command(nil, nil, "st-grate1", {}) buftable [command_north] = new_command(x1-3, y1+4, "st-bolder", {direction=NORTH}) buftable [command_south] = new_command(x1-3, y1+8, "st-bolder", {direction=SOUTH}) buftable [command_east] = new_command(x1-1, y1+6, "st-bolder", {direction=EAST }) buftable [command_west] = new_command(x1-5, y1+6, "st-bolder", {direction=WEST }) --buffer to remember commands commandbuffer={n=20} --command selection via the trigger "gamepad" function setcommand(newcmd) local flx0, fly0 = buftable[newcmd].x, buftable[newcmd].y local clx0, cly0 = buftable[command].x, buftable[command].y if (not(ingame)) then if ((clx0 or cly0) ~= nil) then set_floor(floortile, clx0, cly0); end if ((flx0 or fly0) ~= nil) then set_floor("fl-normal", flx0, fly0); end command = newcmd end end function commandnorth() setcommand(command_north); end function commandsouth() setcommand(command_south); end function commandeast() setcommand(command_east); end function commandwest() setcommand(command_west); end function commandclean() setcommand(command_clean); end --magic stones eyecandy function draw_magic() enigma.KillStone(x1, y1+12) set_stone("st-magic", x1, y1+12) end function erase_magic() enigma.KillStone(x1, y1+12) set_stone(bordertile, x1, y1+12) end function invalid_magic() enigma.KillStone(x1, y1+12) set_stone("st-death", x1, y1+12) end --bufferworks first_free_element = function (buf,i) return buf[i] ~= command_clean end first_command = function (buf,i) return buf[i] == command_clean end function draw_buffer() for i=1,commandbuffer.n do local x,y = i,1 while (x>5) do x = x-5; y = y+1; end if (y>2) then y = y+7; end x,y = x1-6+x, y1+y local tab = buftable[commandbuffer[i]] enigma.KillStone(x, y) set_stone(tab.face, x, y, tab.par) end end function generic_buf_test(buf,test) local i=1 while test(buf,i) do --(commandbuffer[i] ~= command_clean) do i=i+1 if (not(buf[i])) then return nil end end return i end function addcommand() if (not(ingame)) then local i = generic_buf_test(commandbuffer, first_free_element) if (i) then commandbuffer[i] = command draw_buffer() commandclean() end end end function clearbuffer() ingame = nil for i=1,commandbuffer.n do commandbuffer[i] = command_clean end draw_buffer() erase_magic() end counter = 0 function boldercommand(startcommand) if (startcommand==1) then counter = 0 end if (mod(counter,2) == 0) then --trigger works twice: upon enter and upon leave local i = generic_buf_test(commandbuffer, first_command) if (i) then set_attribs(enigma.GetNamedObject("bolder1"), buftable[commandbuffer[i]].par) commandbuffer[i] = command_clean draw_buffer() draw_magic() else invalid_magic() end end counter = counter + 1 end function startbolder() if (not(ingame)) then ingame = 1 boldercommand(1) end end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- and finally, the map itself -- arena draw_stones(walltile, {x1,y1+1},{0,1},5) draw_stones(walltile, {x1,y1+7},{0,1},5) draw_stones(walltile, {x1+10,y1+5}, {0,-1}, 3) draw_stones(walltile, {x1+10,y1+7}, {0,1}, 3) set_stone("st-bolder", x1+3, y1+6, {name="bolder1", direction=WEST}) draw_stones(walltile, {x1+1,y1+5}, {1,0}, 2) draw_stones(walltile, {x1+1,y1+7}, {1,0}, 2) -- triggers triggers = { { 1, 1}, { 8, 1}, {12, 1}, { 2, 2}, { 9, 2}, {11, 2}, {12, 2}, { 1, 3}, { 4, 3}, { 7, 3}, { 5, 4}, { 2, 4}, { 3, 5}, { 8, 5}, { 7, 6}, {12, 6}, { 3, 7}, { 6, 7}, { 1, 8}, { 5, 8}, { 2, 9}, { 7, 9}, { 1,10}, { 9,10}, {11,10}, {12,10}, { 1,11}, { 8,11}, {12,11} } for key, coord in triggers do set_item("it-trigger", x1+coord[1], y1+coord[2], {action="callback", target="boldercommand"}) end -- control room draw_stones(walltile, {x1-1,y1+3}, {-1,0}, 5) draw_stones(walltile, {x1-1,y1+9}, {-1,0}, 5) set_stone("st-switch", x1-1, y1+3, {action="callback", target="addcommand"}) set_stone("st-switch", x1+2, y1+6, {action="callback", target="startbolder"}) set_stone("st-switch", x1-1, y1+9, {action="callback", target="clearbuffer"}) set_item("it-trigger", x1-4, y1+6, {action="callback", target="commandwest"}) set_item("it-trigger", x1-2, y1+6, {action="callback", target="commandeast"}) set_item("it-trigger", x1-3, y1+5, {action="callback", target="commandnorth"}) set_item("it-trigger", x1-3, y1+7, {action="callback", target="commandsouth"}) document(x1-1, y1+4, "Welcome to the control room. Use the triggers and switches to plan the movement of the turtle. The switches are, clockwise: Add, Run and Restart.") -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- oxyd, marble, init clearbuffer() set_actor("ac-blackball", x1-2.5, y1+6.5, {player=0}) oxyd_default_flavor="a" oxyd (x1+2,y1) oxyd (x1+2,y1+12) oxyd (x1+11,y1) oxyd (x1+11,y1+12) oxyd_shuffle() -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- enough :)