0,]']>S}Wup8d%qy)6o;]AsVl3D ؋$J0 $2 '$E#$_: xx̬̬̬̬ 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