function getDirName(dir) if (dir == 1) then return "север"; elseif (dir == 2) then return "восток"; elseif (dir == 3) then return "юг"; elseif (dir == 4) then return "запад"; end; end; stealthroom = function(tab) tab.nolamp = true; tab.pic = function(s) local pl_y = math.floor(tonumber(s.pos) / 10); local pl_x = tonumber(s.pos) % 10; local pl_xm = pl_x * 2 + 1; local deltax = 0; local deltay = 0; if pl_x == 0 then pl_xm = 2; deltax = -32; elseif pl_x == 5 then pl_xm = 10; deltax = 32; end; local pl_ym = pl_y * 2 + 1; if pl_y == 0 then pl_ym = 2; deltay = 32; elseif pl_y == 5 then pl_ym = 10; deltay = -32; end; local rval = "images/" .. s.background .. ".png"; for x = 0, 8 do for y = 0, 8 do if pl_xm - 4 + x > 0 and pl_ym - 4 + y > 0 and pl_xm - 4 + x < 12 and pl_ym - 4 + y < 12 then if s.map[pl_ym - 4 + y][pl_xm - 4 + x] == 1 then rval = rval .. ";images/" .. s.wall .. ".png@" .. tostring((x) * 32) .. "," .. tostring(256 - (y) * 32); elseif s.map[pl_ym - 4 + y][pl_xm - 4 + x] == 2 then rval = rval .. ";images/" .. s.door .. ".png@" .. tostring((x) * 32) .. "," .. tostring(256 - (y) * 32); elseif s.map[pl_ym - 4 + y][pl_xm - 4 + x] == 3 then rval = rval .. ";images/" .. s.obstacle .. ".png@" .. tostring((x) * 32) .. "," .. tostring(256 - (y) * 32); end; else rval = rval .. ";box:32x32,black,255@" .. tostring((x) * 32) .. "," .. tostring(256 - (y) * 32); end; end; end; for i = 1, #s.guards do local g_y = math.floor(tonumber(s.guards[i].pos) / 10); local g_x = tonumber(s.guards[i].pos) % 10; if pl_y - g_y == 0 or pl_x - g_x == 0 and math.abs(pl_y - g_y) + math.abs(pl_x - g_x) < 3 then rval = rval .. ";images/" .. s.guard .. tostring(s.guards[i].dir) .. ".png@" .. tostring((g_x - pl_x) * 64 + 128 + deltax) .. ",".. tostring((pl_y - g_y) * 64 + 128 + deltay); end; if math.abs(pl_y - g_y) == 1 and math.abs(pl_x - g_x) == 1 then rval = rval .. ";images/unseen_enemy.png@" .. tostring((g_x - pl_x) * 64 + 128 + deltax) .. ",".. tostring((pl_y - g_y) * 64 + 128 + deltay); end; end; rval = rval .. ";images/" .. s.player .. ".png@128,128"; return rval .. ";images/wh32_mask.png"; end; tab.disp = function(s) return s.definitions[s.pos].name; end; tab.checkGuardSight = function(s) --Проверить область зрения каждого стражника, если игрок находится в области зрения - FAIL for i = 1, #s.guards do if (s.guards[i].pos == s.pos) then --detected walk(s.game_over); return false; end; if (s.guards[i].dir == 1) then if (not s.hidden and s.definitions[s.guards[i].pos].e1 and s.pos == s.definitions[s.guards[i].pos].e1) then --detected walk(s.game_over); return false; end; elseif (s.guards[i].dir == 2) then if (not s.hidden and s.definitions[s.guards[i].pos].e2 and s.pos == s.definitions[s.guards[i].pos].e2) then --detected walk(s.game_over); return false; end; elseif (s.guards[i].dir == 3) then if (not s.hidden and s.definitions[s.guards[i].pos].e3 and s.pos == s.definitions[s.guards[i].pos].e3) then --detected walk(s.game_over); return false; end; elseif (s.guards[i].dir == 4) then if (not s.hidden and s.definitions[s.guards[i].pos].e4 and s.pos == s.definitions[s.guards[i].pos].e4) then --detected walk(s.game_over); return false; end; end; end; return true; end; makeTurn = tab.makeTurn; tab.makeTurn = function(s) if (s:checkGuardSight()) then s:guardTurn(); if (s:checkGuardSight()) then if (s.definitions[s.pos].e1 or s.definitions[s.pos].ex1) then path("На север"):enable(); else path("На север"):disable(); end; if (s.definitions[s.pos].e2 or s.definitions[s.pos].ex2) then path("На восток"):enable(); else path("На восток"):disable(); end; if (s.definitions[s.pos].e3 or s.definitions[s.pos].ex3) then path("На юг"):enable(); else path("На юг"):disable(); end; if (s.definitions[s.pos].e4 or s.definitions[s.pos].ex4) then path("На запад"):enable(); else path("На запад"):disable(); end; if (s.definitions[s.pos].corner) then path("Спрятаться"):enable(); else path("Спрятаться"):disable(); end; if (s.hidden) then path("Спрятаться"):disable(); path("Выбраться из укрытия"):enable(); path("На запад"):disable(); path("На восток"):disable(); path("На север"):disable(); path("На юг"):disable(); else path("Выбраться из укрытия"):disable(); end; end; end; makeTurn(s); end; tab.way = { kh_vroom("На север", function(s) if (rm.definitions[rm.pos].ex1) then return rm.definitions[rm.pos].ex1; else rm.pos = rm.definitions[rm.pos].e1; end; return rm; end); kh_vroom("На юг", function(s) if (rm.definitions[rm.pos].ex3) then return rm.definitions[rm.pos].ex3; else rm.pos = rm.definitions[rm.pos].e3; end; return rm; end); kh_vroom("На запад", function(s) if (rm.definitions[rm.pos].ex4) then return rm.definitions[rm.pos].ex4; else rm.pos = rm.definitions[rm.pos].e4; end; return rm; end); kh_vroom("На восток", function(s) if (rm.definitions[rm.pos].ex2) then return rm.definitions[rm.pos].ex2; else rm.pos = rm.definitions[rm.pos].e2; end; return rm; end); kh_vroom("Ждать", function(s) return rm; end); kh_vroom("Спрятаться", function(s) rm.hidden = true; return rm; end); kh_vroom("Выбраться из укрытия", function(s) rm.hidden = false; return rm; end); }; rm = room(tab); return rm; end;