info = { type = "image", title = "Crab treasure", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A crab finds a treasure chest on the seabed", api = 33, } local tr = ({ sk = { ["Water"] = "Voda", ["Blue"] = "Modrá", ["Teal"] = "Tyrkysová" }, cs = { ["Water"] = "Voda", ["Blue"] = "Modrá", ["Teal"] = "Tyrkysová" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "water", label = T("Water"), type = "int", default = "blue", opts = { keys = { "blue", "teal" }, T("Blue"), T("Teal") } }, } local WATER = { blue = { { 14, 58, 132 }, { 8, 34, 90 } }, teal = { { 10, 84, 120 }, { 6, 48, 78 } }, } local rect, px, blend_rect, blit = gfx.rect, gfx.px, gfx.blend_rect, gfx.blit_indexed local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local LOOP = 540 local CHX, CHY = 36, 33 local STOP_X, CRY = 21, 50 local CRABZ = { [[ 0000004440000444000000 0000004450000445000000 0000000100000010000000 0000000100000010000000 0000001111111111000000 0000133333111111110000 3333331111111111113333 6611111111111111121166 1111111111111111221111 0000022222222222200000 0000020202002020200000 0000200220000220020000 0000002000000002000000 0000002000000002000000]], [[ 3300004440000444000033 1101104450000445011011 1101100100000010011011 1111100100000010011111 0011001111111111001100 0011133333111111111100 0011331111111111111100 0001111111111111122000 0000111111111111220000 0000022222222222200000 0000020202002020200000 0000200220000220020000 0000002000000002000000 0000002000000002000000]], [[ 3333304440000444033333 1161104450000445011611 1111100100000010011111 1111100100000010011111 0011001111111111001100 0011133333111111111100 0011331111111111111100 0001111111111111122000 0000111111111111220000 0000022222222222200000 0000020202002020200000 0000200220000220020000 0000002000000002000000 0000002000000002000000]], [[ 0000004440000444000000 0000004450000445000000 0000000100000010000000 0000000100000010000000 0000001111111111000000 0000133333111111110000 3333331111111111113333 6611111111111111121166 1111111111111111221111 0000022222222222200000 0000020202002020200000 0000022002002002200000 0000200020000200020000 0000200020000200020000]], [[ 3300004440000444000033 1101104450000445011011 1101100100000010011011 1111100100000010011111 0011001111111111001100 0011133333111111111100 0011331111111111111100 0001111111111111122000 0000111111111111220000 0000022222222222200000 0000020202002020200000 0000022002002002200000 0000200020000200020000 0000200020000200020000]], [[ 3333304440000444033333 1161104450000445011611 1111100100000010011111 1111100100000010011111 0011001111111111001100 0011133333111111111100 0011331111111111111100 0001111111111111122000 0000111111111111220000 0000022222222222200000 0000020202002020200000 0000022002002002200000 0000200020000200020000 0000200020000200020000]], } local CHESTZ = { [[ 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00077777777777777000 01133111111111133110 01133111111111133110 01133111111111133110 02233222222222233220 77733777777777733777 11133111133111133111 11133111132111133111 11133111133111133111 22233222222222233222 11133111111111133111 11133111111111133111 22233222222222233222]], [[ 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000000000 00077777777777777000 01133111111111133110 01133111111111133110 01133111111111133110 02233222222222233220 00444444444444444400 77733777777777733777 11133111133111133111 11133111132111133111 11133111133111133111 22233222222222233222 11133111111111133111 11133111111111133111 22233222222222233222]], [[ 00000000000000000000 00000000000000000000 00000000000000000000 01111111111111111110 01122222222222222110 01122222222222222110 01122222222222222110 01111111111111111110 02222222222222222220 02222444644444422220 02233333333353333220 02333333333333333320 77733777777777733777 11133111133111133111 11133111132111133111 11133111133111133111 22233222222222233222 11133111111111133111 11133111111111133111 22233222222222233222]], [[ 01111111111111111110 01122222222222222110 01122222222222222110 01122222222222222110 01111111111111111110 02222222222222222220 02222222222222222220 02222244444444222220 02223333433333332220 02233333333633333220 02333533333335333320 02333333333333333320 77733777777777733777 11133111133111133111 11133111132111133111 11133111133111133111 22233222222222233222 11133111111111133111 11133111111111133111 22233222222222233222]], } local FISHZ = { [[ 0001000000 1111111044 1311111444 2222222444 0002000044]], [[ 0000001000 4401111111 4441111131 4442222222 4400002000]], [[ 0001000004 1111111044 1311111444 2222222444 0002000044]], [[ 4000001000 4401111111 4441111131 4442222222 4400002000]], [[ 000000000 111111044 131111444 222222444 000000044]], [[ 000000000 440111111 444111131 444222222 440000000]], [[ 000000004 111111044 131111444 222222444 000000044]], [[ 400000000 440111111 444111131 444222222 440000000]], [[ 010044 111444 020044]], [[ 440010 444111 440020]], [[ 010044 111444 020044]], [[ 440010 444111 440020]], } local UNZ = { ["\n"] = "" } for i = 0, 9 do UNZ[string.char(48 + i)] = string.char(i) end local function lazy(z, n) return setmetatable({}, { __index = function(t, k) local v = z[n(k)]:gsub(".", UNZ); t[k] = v; return v end }) end local FKIND = { { 10, 5 }, { 9, 5 }, { 6, 3 } } local CRAB = setmetatable({}, { __index = function(t, lp) local v = lazy(CRABZ, function(cs) return 3 * lp + cs + 1 end); t[lp] = v; return v end }) local CHEST = lazy(CHESTZ, function(p) return p + 1 end) local FISH = setmetatable({}, { __index = function(t, k) local v = setmetatable({}, { __index = function(t2, tail) local v2 = lazy(FISHZ, function(d) return 4 * (k - 1) + 2 * tail + d + 1 end); t2[tail] = v2; return v2 end }) t[k] = v; return v end }) local CRAB_PAL = { 0, 0, 0, 200, 44, 36, 128, 24, 30, 240, 104, 72, 240, 240, 250, 12, 12, 24, 70, 10, 18 } local CHEST_PAL = { 0, 0, 0, 112, 76, 56, 70, 46, 40, 214, 172, 64, 255, 226, 110, 232, 56, 76, 90, 220, 240, 150, 104, 76 } local FISH_PAL = { 0, 0, 0, 126, 150, 172, 176, 196, 210, 10, 20, 40, 84, 108, 134 } local BG local WC = WATER.blue function on_settings() WC = WATER[cfg.water] or WATER.blue BG = nil end local function build_bg() local a, b = WC[1], WC[2] for y = 0, 49 do local t = y / 49 rect(0, y, W, 1, floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5)) end for _, ray in ipairs({ { 6, 6 }, { 26, 4 }, { 50, 8 } }) do for y = 0, 48, 2 do blend_rect(ray[1] + y // 3, y, ray[2], 2, 140, 210, 255, 0.05) end end rect(0, 50, W, 14, 108, 120, 108) rect(0, 50, W, 1, 142, 150, 124) rect(0, 56, W, 4, 90, 104, 98) rect(0, 60, W, 4, 66, 82, 84) for i = 1, 9 do local h = hash32(i * 0x9E3779B1) rect(umod(h, 60), 52 + umod(h >> 8, 10), 2 + umod(h >> 16, 3), 1, 74, 88, 84) end blend_rect(CHX - 1, 51, 22, 3, 10, 24, 40, 0.5) rect(0, 44, 7, 8, 40, 66, 78); rect(1, 43, 5, 1, 40, 66, 78); rect(0, 44, 3, 3, 56, 88, 98) for _, p in ipairs({ { 9, 48, 13 }, { 11, 49, 9 }, { 60, 50, 12 }, { 62, 50, 8 }, { 57, 51, 7 } }) do for k = 0, p[3] - 1 do px(p[1] + floor(1.4 * sin(k * 0.55 + p[1]) + 0.5), p[2] - k, 26, 110 + (k % 3) * 8, 78) end end BG = gfx.snapshot(0, 0, W, H) end local function bubble(x, y) blend_rect(x, y, 2, 2, 170, 220, 255, 0.5) px(x, y, 235, 248, 255) end local function ease(u) return u <= 0 and 0 or (u >= 1 and 1 or u * u * (3 - 2 * u)) end local function chest_pose(t) if t < 150 then return 0 elseif t < 158 then return 1 elseif t < 170 then return 2 elseif t < 300 then return 3 elseif t < 310 then return 2 elseif t < 318 then return 1 end return 0 end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local f = frame local t = f % LOOP local FP = { { 1, 11, 5, 0, 8 }, { 2, 24, 6, 1, 6 }, { 1, 16, 7, 1, 21 } } for i = 1, #FP do local q = FP[i] local x = (q[5] * 7 + (q[4] == 1 and 1 or -1) * (f // q[3])) % (W + 24) - 12 local k = q[1] local y = q[2] + floor(1.2 * sin(f * 0.02 + i) + 0.5) blit(FISH[k][(f // 8) % 2][q[4]], FISH_PAL, x, y, FKIND[k][1], FKIND[k][2], FKIND[k][1], FKIND[k][2], true) end for i = 0, 4 do local x = (60 - (f // 5) + i * 5 + (i % 2) * 2) % (W + 24) - 12 local y = 31 + (i * 3) % 7 + floor(1.5 * sin(f * 0.03 + i * 0.4) + 0.5) blit(FISH[3][(f // 6 + i) % 2][0], FISH_PAL, x, y, 6, 3, 6, 3, true) end for i = 1, 4 do local P = 150 + i * 23 local a = (f + i * 61) % P if a < 110 then local bx = umod(hash32(i * 977 + (f + i * 61) // P), 56) + 4 bubble(bx + floor(1.2 * sin(a * 0.08 + i) + 0.5), 49 - a * 4 // 9) end end blit(CHEST[chest_pose(t)], CHEST_PAL, CHX, CHY, 20, 20, 20, 20, true) if t >= 166 and t < 215 then local env = t < 172 and (t - 166) / 6 or (1 - (t - 172) / 43) if env > 0 then blend_rect(CHX + 8, 0, 8, 38, 255, 226, 120, 0.07 * env) blend_rect(CHX + 6, 8, 12, 30, 255, 226, 120, 0.07 * env) for k = 1, 3 do local e = 4 * k blend_rect(CHX + 10 - e, 38 - e // 2, 2 * e, e, 255, 226, 120, 0.12 * env) end for i = 1, 6 do local h = hash32(i * 0x85EBCA6B) local sx, sy = CHX + 4 + umod(h, 13), 24 + umod(h >> 8, 13) if (t // 3 + i) % 3 ~= 0 then px(sx, sy, 255, 250, 200); px(sx - 1, sy, 255, 226, 120); px(sx + 1, sy, 255, 226, 120) px(sx, sy - 1, 255, 226, 120); px(sx, sy + 1, 255, 226, 120) end end end end for i = 0, 11 do local a = t - (170 + i * 3) if a >= 0 and a < 72 then local h = hash32(i * 0x9E3779B1) bubble(CHX + 4 + umod(h, 11) + floor(1.3 * sin(a * 0.1 + i) + 0.5), 38 - a * 6 // 11) end end local cx, lp, cs = nil, 0, 0 if t < 126 then cx, lp = -21 + t // 3, (t // 3) % 2 elseif t < 240 then cx = STOP_X if t >= 170 and t < 200 then cs = 1 elseif t >= 200 and t < 236 then cs = 1 + (t - 200) // 6 % 2 end elseif t < 369 then cx, lp = STOP_X + (t - 240) // 3, ((t - 240) // 3) % 2 end if cx and cx < W then blit(CRAB[lp][cs], CRAB_PAL, cx, CRY, 22, 14, 22, 14, true) end for i = 1, 5 do local h = hash32(i * 0xC2B2AE35) local a = 0.12 + 0.12 * sin(f * 0.07 + i * 1.7) blend_rect(umod(h, 62), 53 + umod(h >> 8, 9), 2, 1, 200, 230, 255, a) end end