info = { type = "image", title = "Baby dino", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A baby dino hops with an eggshell hat", api = 33, } local tr = ({ sk = { ["Dino colour"] = "Farba dina", ["Eggs"] = "Vajíčka", ["Hopping"] = "Skákanie" }, cs = { ["Dino colour"] = "Barva dina", ["Eggs"] = "Vajíčka", ["Hopping"] = "Skákání" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "tone", label = T("Dino colour"), type = "color", default = "#3F9E48" }, { key = "eggs", label = T("Eggs"), type = "int", min = 0, max = 3, default = 3 }, { key = "hop", label = T("Hopping"), type = "bool", default = true }, } local rect, px, blend = gfx.rect, gfx.px, gfx.blend local blit = gfx.blit_indexed local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local rep = string.rep local TAU = 6.28318 local function c3(c) return c[1], c[2], c[3] end local function art(rows, keys) local map = { ["."] = 0 } for i = 1, #keys do map[keys:sub(i, i)] = i end local w = 0 for i = 1, #rows do for _, seg in ipairs(rows[i]) do if seg[1] + #seg[2] > w then w = seg[1] + #seg[2] end end end local out = {} for i = 1, #rows do local r = {} for x = 1, w do r[x] = 0 end for _, seg in ipairs(rows[i]) do for k = 1, #seg[2] do r[seg[1] + k] = map[seg[2]:sub(k, k)] end end out[i] = string.char(table.unpack(r, 1, w)) end return table.concat(out), w, #rows end local function G(n) return rep("g", n) end local DINO, DW, DH = art({ { { 7, rep("d", 8) } }, { { 5, "d" .. G(10) .. "d" } }, { { 4, "d" .. G(12) .. "d" } }, { { 3, "d" .. G(14) .. "d" } }, { { 3, "d" .. G(14) .. "d" } }, { { 3, "d" .. G(14) .. "d" } }, { { 3, "d" .. G(14) .. "d" } }, { { 3, "d" .. G(14) .. "d" } }, { { 3, "d" .. G(1) .. "pp" .. G(8) .. "pp" .. G(1) .. "d" } }, { { 3, "d" .. G(4) .. "d" .. G(4) .. "d" .. G(4) .. "d" } }, { { 3, "d" .. G(5) .. "dddd" .. G(5) .. "d" } }, { { 4, "d" .. G(12) .. "d" } }, { { 5, rep("d", 12) } }, { { 6, "d" .. G(8) .. "d" } }, { { 6, "d" .. G(8) .. "d" }, { 8, "bbbb" }, { 4, "dd" }, { 16, "dd" } }, { { 6, "d" .. G(8) .. "d" }, { 7, "bbbbbbbb" }, { 3, "dggd" }, { 15, "dggd" } }, { { 6, "d" .. G(8) .. "d" }, { 7, "bbbbbbbb" }, { 4, "dd" }, { 16, "dd" } }, { { 6, "d" .. G(8) .. "d" }, { 7, "bbbbbbbb" } }, { { 6, "d" .. G(8) .. "d" }, { 7, "bbbbbbbb" } }, { { 6, "d" .. G(8) .. "d" }, { 7, "bbbbbbbb" } }, { { 6, "d" .. G(8) .. "d" }, { 8, "bbbb" } }, { { 6, "d" .. G(8) .. "d" } }, { { 4, "dgggd" }, { 13, "dgggd" } }, { { 3, "dddddd" }, { 13, "dddddd" } }, }, "gdbp") local SHELL, SW, SH = art({ { { 8, "pp" } }, { { 6, "wwwwww" } }, { { 4, "wwwwwwwwws" } }, { { 3, "wwpwwwwwwwss" } }, { { 2, "wwwwwwwwwwpwss" } }, { { 1, rep("s", 16) } }, { { 1, "ww.ww.ww.ww.ww.w" } }, }, "wsp") local EGGROWS = { { { 3, "ww" } }, { { 2, "wwww" } }, { { 1, "wwwwws" } }, { { 0, "wwwwwwws" } }, { { 0, "wwpwwwws" } }, { { 0, "wwwwwpws" } }, { { 0, "wwwwwwss" } }, { { 0, "wpwwwwss" } }, { { 1, "wwwwss" } }, { { 2, "wsss" } }, } local EGG0, EW, EH = art(EGGROWS, "wspkb") local EGG1 = art({ { { 3, "ww" } }, { { 2, "wwww" } }, { { 1, "wwwwws" } }, { { 0, "wwwwwwws" } }, { { 0, "wkwkwkws" } }, { { 0, "wwkwkwws" }, { 1, "wk" } }, { { 0, "wwwwwwss" } }, { { 0, "wpwwwwss" } }, { { 1, "wwwwss" } }, { { 2, "wsss" } }, }, "wspkb") local EGG2, EW2 = art({ {}, { { 2, "bbbb" } }, { { 1, "bbbbbb" } }, { { 1, "bkbbkb" } }, { { 1, "pbbbbp" } }, { { 0, "w.ww.ww." } }, { { 0, "wwwwwwws" } }, { { 0, "wwwwwwss" }, { 8, "www" } }, { { 1, "wwwwss" }, { 9, "w" } }, { { 2, "wsss" } }, }, "wspkb") local EPAL = { 0, 0, 0, 252, 250, 244, 224, 210, 184, 240, 150, 160, 120, 84, 52, 255, 232, 224 } local SKY, SUN, CLOUD = { 250, 238, 188 }, { 255, 214, 96 }, { 255, 252, 238 } local SAND, TUFT, SHAD = { 238, 214, 150 }, { 212, 184, 120 }, { 214, 190, 130 } local EYE = { 30, 38, 30 } local DX, DY = 21, 24 local EX = { 6, 49, 27 } local EY = { 49, 50, 53 } local EOFF = { 0, 100, 200 } local BG = nil local function build_bg() rect(0, 0, W, H, c3(SKY)) rect(8, 6, 6, 10, c3(SUN)); rect(6, 8, 10, 6, c3(SUN)); rect(7, 7, 8, 8, c3(SUN)) rect(42, 9, 14, 3, c3(CLOUD)); rect(45, 7, 8, 2, c3(CLOUD)); rect(40, 11, 3, 1, c3(CLOUD)) rect(0, 40, W, H - 40, c3(SAND)) for i = 0, 13 do local h = hash32(i * 0x9E3779B1 + 3) local x, y = umod(h, W - 4) + 2, 44 + umod(h >> 8, 18) px(x, y, c3(TUFT)); px(x - 1, y - 1, c3(TUFT)); px(x + 1, y - 1, c3(TUFT)) end BG = gfx.snapshot(0, 0, W, H) end local DPAL, TG, TD = nil, nil, nil function on_settings() local c = cfg.tone or { r = 63, g = 158, b = 72 } TG = { c.r, c.g, c.b } TD = { c.r * 58 // 100, c.g * 58 // 100, c.b * 58 // 100 } DPAL = { 0, 0, 0, c.r, c.g, c.b, TD[1], TD[2], TD[3], 246, 226, 170, 240, 150, 150 } end local function hopf(t) local u = (t + 20) % 90 if u < 14 then return floor(6 * sin(3.14159 * u / 14) + 0.5) end return 0 end local function egg(i, t) local ex, ey = EX[i], EY[i] local u = (t + EOFF[i]) % 300 if u < 120 then local dx = 0 if u >= 70 then dx = ((u // 3) % 2 == 0) and -1 or 1 end blit(u < 100 and EGG0 or EGG1, EPAL, ex + dx, ey, EW, EH, EW, EH, true) elseif u < 250 then blit(EGG2, EPAL, ex, ey, EW2, EH, EW2, EH, true) if u < 127 then local d = 2 + (u - 120) px(ex + 4 - d, ey + 1, 255, 255, 255); px(ex + 3 + d, ey + 1, 255, 255, 255) px(ex + 2 - d // 2, ey - d // 2, 255, 230, 120); px(ex + 5 + d // 2, ey - d // 2, 255, 230, 120) end elseif u < 270 then gfx.clip(ex, ey, EW2, EH) blit(EGG2, EPAL, ex, ey + (u - 250) // 2, EW2, EH, EW2, EH, true) gfx.clip() else gfx.clip(ex, ey, EW, EH) blit(EGG0, EPAL, ex, ey + 10 - (u - 270) // 3, EW, EH, EW, EH, true) gfx.clip() end end local function tail(t, dy) local x0, y0 = DX + 16, DY + 20 + dy local sway = sin(t * TAU / 70) for k = 0, 5 do local f = k / 5 local yc = y0 - f * 3.5 + sway * 3.2 * f * f local th = k < 3 and 3 or 2 local top = yc - th / 2 local iy = floor(top) local fr = top - iy local c = k >= 5 and TD or TG local x = x0 + k * 2 rect(x, iy + 1, 2, th - 1, c3(c)) local a1, a2 = 1 - fr, fr gfx.blend_rect(x, iy, 2, 1, c[1], c[2], c[3], a1) gfx.blend_rect(x, iy + th, 2, 1, c[1], c[2], c[3], a2) end end function render() if not BG then build_bg() end if not DPAL then on_settings() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS local n = cfg.eggs or 3 for i = 1, n do egg(i, t) end local lift = (cfg.hop ~= false) and hopf(t) or 0 local dy = -lift local y = DY + dy local sh = lift >= 3 and 4 or 0 rect(DX + 1 + sh // 2, DY + 24, 20 - sh, 1, c3(SHAD)) rect(DX - 1 + sh // 2, DY + 25, 24 - sh, 1, c3(SHAD)) rect(DX + 3 + sh // 2, DY + 26, 16 - sh, 1, c3(SHAD)) tail(t, dy) blit(DINO, DPAL, DX, y, DW, DH, DW, DH, true) local sy = y - 3 + (hopf(t - 2) - lift) * -1 blit(SHELL, EPAL, DX + 2, sy, SW, SH, SW, SH, true) if t % 75 < 3 then rect(DX + 6, y + 6, 2, 1, c3(EYE)); rect(DX + 14, y + 6, 2, 1, c3(EYE)) else rect(DX + 6, y + 5, 2, 3, c3(EYE)); rect(DX + 14, y + 5, 2, 3, c3(EYE)) px(DX + 6, y + 5, 255, 255, 255); px(DX + 14, y + 5, 255, 255, 255) end end