0,]']±>Sæ}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3D øØ‹Õ$ø�J0 øÞÈ$ø�Ð2 øñ'Ó$øE#õøïø¿Ã$ø_Û: ø°�¡™ôÎÌÌÌÌx—ˆ¬ªªª¬ˆx—¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌ쑈ÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ<“ˆˆ¬ªªª¬x—ˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀ‘¨Àî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒx—ˆ<ÀÌÎÌÌÎÌ\̪ªÀ쬪ÀÀÀ‘ˆÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªª|—ˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî-- author: Varya Dianova & Ivan Dianov -- title: Rabbit in a carrot labyrinth -- desc: Viking is searching his wife in a labirynth -- site: ivandianov.com -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua -- Global variables mapOffX = 0 mapOffY = 0 t = 0 tkey = 0 x = 2 y = 2 isDead = false isExplode = false tDead = 0 tExplode = 0 history = {} table.insert(history, {x = x, y = y, mapOffX = mapOffX, mapOffY = mapOffY}) carrots = {} carrotTraps = {} carrotsI = {} carrotTrapsI = {} for j = 0, 17 do for i = 0, 30 do local sp = mget(i, j) if sp == 112 then table.insert(carrotsI, {i = i, j = j}) mset(i, j, 0) end if sp == 128 then table.insert(carrotTrapsI, {i = i, j = j}) mset(i, j, 0) end if sp == 32 then x = i y = j mset(i, j, 0) end end end function deepCopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in next, orig, nil do copy[deepCopy(orig_key)] = deepCopy(orig_value) end setmetatable(copy, deepCopy(getmetatable(orig))) else -- number, string, boolean, etc copy = orig end return copy end carrotTraps = deepCopy(carrotTrapsI) carrots = deepCopy(carrotsI) -- Main game loop function TIC() eatCarrots() eatCarrotTraps() drawMap() explosion() processInput() updateMapOffset() handleDeath() drawPlayer() t = t + 1 print('',4,4) end function explosion() if isExplode then tExplode = tExplode + 1 if(tExplode > 50) then isDead = true isExplode = false tDead = 200 tExplode = 0 end end end function eatCarrotTraps() for k, carrot in ipairs(carrotTraps) do if carrot.i == x and carrot.j == y then table.remove(carrotTraps, k) isExplode = true music(0, 0, -1, false) break end end end function eatCarrots() for k, carrot in ipairs(carrots) do if carrot.i == x and carrot.j == y then table.remove(carrots, k) break end end for k, carrot in ipairs(carrotTraps) do if carrot.i == x and carrot.j == y then table.remove(carrots, k) break end end end -- Draw the map function drawMap() map(mapOffX, mapOffY, 30, 17, 0, 0) for i, carrot in ipairs(carrots) do spr(112+((t/20%10+i)/5)%2, 8*carrot.i, 8*carrot.j, 0) end for i, carrot in ipairs(carrotTraps) do spr(128+(t/40+i)%2, 8*carrot.i, 8*carrot.j, 0) end end -- Process player input function processInput() local dx = 0 local dy = 0 if not isDead then if btn(0) or btn(1) or btn(2) or btn(3) then if tkey % 5 == 0 then if btn(0) then dy = -1 end if btn(1) then dy = 1 end if btn(2) then dx = -1 end if btn(3) then dx = 1 end end tkey = tkey + 1 if mget(x + dx + mapOffX, y + dy + mapOffY) == 16 then dx = dx * 0.5 dy = dy * 0.5 isDead = true music(0, 0, -1, false) end x = x + dx y = y + dy if dx ~= 0 or dy ~= 0 then table.insert(history, {x = x, y = y, mapOffX = mapOffX, mapOffY = mapOffY}) end else tkey = 0 end end end -- Update player position function drawPlayer() if isDead then spr(33, x * 8, y * 8, 0, 1, 0, 0, 1, 1) else if isExplode then spr(96 + tExplode/5, x * 8, y * 8, 0, 1, 0, 0, 1, 1) else spr(32, x * 8, y * 8, 0, 1, 0, 0, 1, 1) end end end -- Handle player death function handleDeath() if isDead then tDead = tDead + 1 if tDead > 50 then if #history > 0 then local lastPos = table.remove(history) x = lastPos.x y = lastPos.y mapOffX = lastPos.mapOffX mapOffY = lastPos.mapOffY if #history == 0 then table.insert(history, {x = x, y = y, mapOffX = mapOffX, mapOffY = mapOffY}) tDead = 0 isDead = false carrotTraps = deepCopy(carrotTrapsI) carrots = deepCopy(carrotsI) end end end end end -- Update map offset based on player position function updateMapOffset() local w = 30 local h = 17 if x < 0 then mapOffX = mapOffX - w x = x + w elseif x >= w then mapOffX = mapOffX + w x = x - w end if y < 0 then mapOffY = mapOffY - h y = y + h elseif y >= h then mapOffY = mapOffY + h y = y - h end end