info = { type = "image", title = "Fluffy", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A fuzzy one-eyed monster hops and looks around", api = 33, } local ltr = ({ sk = { ["Fur colour"] = "Farba srsti", ["Hops"] = "Skoky", ["Never"] = "Nikdy", ["Sometimes"] = "Občas", ["Often"] = "Často" }, cs = { ["Fur colour"] = "Barva srsti", ["Hops"] = "Skoky", ["Never"] = "Nikdy", ["Sometimes"] = "Občas", ["Often"] = "Často" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "fur", label = LT("Fur colour"), type = "color", default = "#7FCBF5" }, { key = "hops", label = LT("Hops"), type = "int", default = 1, opts = { LT("Never"), LT("Sometimes"), LT("Often") } }, } local rect, px, blit = gfx.rect, gfx.px, gfx.blit_indexed local floor, sin, cos, sqrt, atan = math.floor, math.sin, math.cos, math.sqrt, math.atan local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local WALL, DOTC = { 66, 32, 86 }, { 88, 46, 110 } local FLOOR, FLOOR_L, SHADOW = { 108, 58, 116 }, { 132, 76, 140 }, { 74, 36, 84 } local IRIS, IRIS_D, PUPIL = { 255, 188, 56 }, { 214, 120, 24 }, { 30, 18, 46 } local PAL = {} local C = {} local CX, BOT = 32.5, 55.6 local VAR = { { 16.5, 15.0 }, { 16.8, 15.35 }, { 17.1, 15.7 }, { 18.6, 13.3 }, { 15.3, 16.7 } } local GX, GY, GW, GH = 10, 6, 45, 54 local BODY, EYEY, CY = {}, {}, {} local function wob(th) return 1 + 0.05 * sin(11 * th + 0.7) + 0.03 * sin(17 * th + 2.1) end local RUNS = { { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 59, 270, 521 }, { 1, 1, 2, 3, 4, 5, 6, 7, 9 }, { 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 3, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13 }, { 4, 1, 2, 3, 4, 5, 6, 7, 8, 10 }, { 5, 1, 2, 3, 4, 5, 6, 7, 9 }, { 6, 1, 2, 3, 4 }, { 7, 1, 2, 3, 7, 11, 13, 15 }, { 8, 1, 2, 3, 5, 11 }, { 9, 1, 2, 3, 5 } } local UNZ = { ["\n"] = "" } do local c = 33 for _, r in ipairs(RUNS) do local v = string.char(r[1]) for k = 2, #r do if c == 93 then c = 94 end UNZ[string.char(c)] = v:rep(r[k]) c = c + 1 end end end local function unz(s) return (s:gsub(".", UNZ)) end for v = 1, #VAR do CY[v] = BOT - VAR[v][2] EYEY[v] = floor(CY[v] - 3.0) end local BODYZ = { [[ =;;Y8O1[4Q1\2R1Yk[0QkO1Yl[.QlO1Zl[$ZO$QlP1Znb"RmP2YnkgZO\QmO3[j[cZRlO3Zic~\PYFkO3Yi}q}YU3YeYd|r|YSF2 hY{s{PYQF/ZeYd|s|SG>-Zh{t{SG?,ZeYc|t|QI,[eYc{u{QI,\f{u{QH-a{u{PI>-O_|t|OJ?,^cZ{t{PJ@*OZO^|z|YJA*OaY{ z{OK@*R_cY|yw|OK?F>*WF}x}OKA-X~PIOC/UFRFONB0XYLOC0WN@F@0GUNGCF>1FOHOFOFOLE3NJD8>G>KE:#EC:JBF@J8L?$L7 L&L7D&D9@*@;]], [[ =:Y:O0Y8O1Z6P1[4Q1Yk[0QkO1Yl[.QlO1Ym[$[$QmO1Yn[!`#QnO1ZnZe_!YQmP1[OYiZO\RlP1[jc[c[RkP2Yj~\PYFP3Yi}q} YTF3fYd|r|YTF/ZhY{s{PYQH-YfYd|s|SH>+Zi{t{SH>+ZfYc|t|QI,[eYc{u{QI,^cZ{u{QI,a{u{PJ>,O_|t|OJ@+^cZ{t{PJ@ *[O^|z|YJA)PaY{z{OK@*R_cO|yw|OK?F>*WF}x}OKA-X~OJOC.VFRFONB/XOYLOC/FWN@F@0GTNGDF>1FOHOFOFOLE>2NJD8>G> KE:#EC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KE5 NHD:>F>JE>:#!EA:!KAF?K9K?$K8M$M8C&C:!?*?;!]] } local function body(v) local s = BODY[v] if not s then s = unz(BODYZ[v]); BODY[v] = s end return s end local function spans(r) local t = {} local n = floor(r) for j = -n, n do t[j] = floor(sqrt(r * r - j * j)) end return t, n end local SCL, SCLN = spans(7.2) local IRS, IRSN = spans(4.1) local IRI, IRIN = spans(3.1) local PUP, PUPN = spans(2.3) local NT = 44 local TCO, TSI, TF, TL, TTH = {}, {}, {}, {}, {} do local n = 0 for k = 1, NT do local th = (k - 0.5) * TAU / NT + (umod(hash32(k * 0x9E3779B1), 100) - 50) / 900 local s = sin(th) if s < 0.78 then n = n + 1 TCO[n], TSI[n], TF[n], TTH[n] = cos(th), s, wob(th), th local l = -0.5 * cos(th) - 0.62 * s TL[n] = l > 0.45 and 4 or (l > 0.0 and 3 or (l > -0.45 and 2 or 1)) end end NT = n end local function apply(c) local base = { c.r, c.g, c.b } local function mul(a) return { floor(base[1] * a + 0.5), floor(base[2] * a + 0.5), floor(base[3] * a + 0.5) } end local function mixw(a) return { floor(base[1] + (255 - base[1]) * a + 0.5), floor(base[2] + (255 - base[2]) * a + 0.5), floor(base[3] + (255 - base[3]) * a + 0.5) } end C = { mul(0.52), mul(0.74), base, mixw(0.38), mixw(0.66) } C[9] = mul(0.34) local all = { C[1], C[2], C[3], C[4], C[5], { 255, 156, 198 }, { 250, 250, 255 }, { 202, 210, 236 }, C[9] } PAL = { 0, 0, 0 } for _, col in ipairs(all) do PAL[#PAL + 1], PAL[#PAL + 2], PAL[#PAL + 3] = col[1], col[2], col[3] end end apply({ r = 127, g = 203, b = 245 }) local HOP = { [0] = 0, 160, 95 } local hop_per = 160 function on_settings() apply(cfg.fur or { r = 127, g = 203, b = 245 }) hop_per = HOP[cfg.hops or 1] or 160 end local BG = nil local function build_bg() rect(0, 0, W, H, WALL[1], WALL[2], WALL[3]) for y = 3, 46, 8 do for x = ((y // 8) % 2) * 4 + 2, W - 1, 8 do rect(x, y, 2, 2, DOTC[1], DOTC[2], DOTC[3]) end end rect(0, 51, W, H - 51, FLOOR[1], FLOOR[2], FLOOR[3]) rect(0, 51, W, 1, FLOOR_L[1], FLOOR_L[2], FLOOR_L[3]) BG = gfx.snapshot(0, 0, W, H) end local LOOK = { { 0, 0 }, { -2, 0 }, { 2, 0 }, { -2, 1 }, { 2, 1 }, { 0, -1 }, { -1, -1 }, { 1, 1 } } local function look(t) local seg = t // 52 local h = hash32(seg * 0x9E3779B1) & 7 return LOOK[h + 1] end local function disc(tab, n, cx, cy, c) for j = -n, n do local hw = tab[j] rect(cx - hw, cy + j, 2 * hw + 1, 1, c[1], c[2], c[3]) end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS local br = sin(t * TAU / (3.0 * STEP_HZ)) local v = br > 0.5 and 3 or (br > -0.5 and 2 or 1) local jump, air = 0, false if hop_per > 0 then local tau = (t - 124) % hop_per if tau < 6 then v = 4 elseif tau < 26 then local s = (tau - 6 + 0.5) / 20 jump = floor(40 * s * (1 - s) + 0.5) air = true v = (tau < 12 or tau >= 22) and 5 or 1 elseif tau < 32 then v = 4 end end local sw = 17 - jump * 0.6 rect(floor(CX - sw + 0.5), 56, floor(2 * sw), 1, SHADOW[1], SHADOW[2], SHADOW[3]) rect(floor(CX - sw * 0.75 + 0.5), 57, floor(1.5 * sw), 1, SHADOW[1], SHADOW[2], SHADOW[3]) rect(floor(CX - sw * 0.45 + 0.5), 58, floor(0.9 * sw), 1, SHADOW[1], SHADOW[2], SHADOW[3]) blit(body(v), PAL, GX, GY - jump, GW, GH, GW, GH, true) local rx, ry, cy = VAR[v][1], VAR[v][2], CY[v] - jump local ph = t * 0.16 for k = 1, NT do local th = TTH[k] local L = floor(1.4 + 1.1 * sin(5 * th - ph) + 0.6 * sin(3 * th + t * 0.09)) if L > 3 then L = 3 end local c = C[TL[k]] local co, si, f = TCO[k], TSI[k], TF[k] for j = 1, L do px(floor(CX + (rx * f + j - 0.6) * co), floor(cy + (ry * f + j - 0.6) * si), c[1], c[2], c[3]) end end local ex, ey = 32, EYEY[v] - jump local lk = look(t) local ox, oy = lk[1], lk[2] disc(IRS, IRSN, ex + ox, ey + oy, IRIS_D) disc(IRI, IRIN, ex + ox, ey + oy, IRIS) disc(PUP, PUPN, ex + ox, ey + oy, PUPIL) rect(ex + ox - 2, ey + oy - 2, 2, 2, 255, 255, 255) local bt = (t - 139) % 101 if bt < 6 then local cl = ({ 4, 9, 15, 15, 9, 4 })[bt + 1] local top = ey - SCLN for j = 0, cl - 1 do local hw = SCL[j - SCLN] if hw then rect(ex - hw, top + j, 2 * hw + 1, 1, C[3][1], C[3][2], C[3][3]) end end local yl = top + cl - (cl == 15 and 8 or 1) local hw = SCL[yl - ey] or 0 rect(ex - hw, yl, 2 * hw + 1, 1, C[9][1], C[9][2], C[9][3]) end local my = floor(cy + 7.5) local m = C[9] if air then rect(31, my, 3, 2, m[1], m[2], m[3]) else px(30, my, m[1], m[2], m[3]); px(34, my, m[1], m[2], m[3]) rect(31, my + 1, 3, 1, m[1], m[2], m[3]) px(33, my + 2, 255, 255, 255) end end