info = { type = "image", title = "Partygoer", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A smiling creature peeks out of a yellow door", api = 33, } local STEP_HZ = 30 local FR = 0 local tr = ({ sk = { ["Balloon"] = "Balón", ["Pause between visits (s)"] = "Pauza medzi návštevami (s)" }, cs = { ["Balloon"] = "Balón", ["Pause between visits (s)"] = "Pauza mezi návštěvami (s)" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "balloon", label = T("Balloon"), type = "color", default = "#F02828" }, { key = "idle", label = T("Pause between visits (s)"), type = "int", min = 1, max = 10, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, abs, max, min = math.floor, math.sin, math.abs, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local CX, CY = 32, 30 local A, B1, B2 = 34, 20, 30 local DX0, DX1, DY0, DY1 = 24, 40, 22, 46 local function sc(c, f) return { floor(c[1] * f + 0.5), floor(c[2] * f + 0.5), floor(c[3] * f + 0.5) } end local function mkpal(f) return { wl = sc({ 232, 204, 80 }, f), wr = sc({ 212, 184, 64 }, f), endw = sc({ 238, 214, 100 }, f), ce = { sc({ 248, 238, 192 }, f), sc({ 242, 230, 174 }, f) }, fl = { sc({ 204, 166, 96 }, f), sc({ 188, 150, 80 }, f), sc({ 172, 134, 64 }, f) }, base = sc({ 140, 100, 36 }, f), stripe = sc({ 196, 166, 56 }, f), frame = sc({ 138, 96, 34 }, f), inner = sc({ 92, 66, 20 }, f), inner2 = sc({ 72, 50, 14 }, f), lamp = sc({ 255, 253, 228 }, f), } end local PALS = { mkpal(1), mkpal(0.78), mkpal(0.7), mkpal(0.96) } local BG = {} local LAMPS = { { 2, 6 }, { 10, 12 }, { 15, 16 } } local function build_bg(p) local c for x = 0, W - 1 do local dx = x < CX and (CX - 0.5 - x) or (x + 0.5 - CX) local k = dx / A local yt = floor(CY - B1 * k + 0.5) local yb = floor(CY + B2 * k + 0.5) local isend = dx < 19 if isend then yt, yb = 19, 47 end c = p.ce[1]; rect(x, 0, 1, min(yt, 10), c[1], c[2], c[3]) if yt > 10 then c = p.ce[2]; rect(x, 10, 1, yt - 10, c[1], c[2], c[3]) end c = isend and p.endw or (x < CX and p.wl or p.wr) rect(x, yt, 1, yb - yt, c[1], c[2], c[3]) if yb < 52 then c = p.fl[1]; rect(x, yb, 1, 52 - yb, c[1], c[2], c[3]) end if yb < 58 then c = p.fl[2]; rect(x, max(yb, 52), 1, 58 - max(yb, 52), c[1], c[2], c[3]) end c = p.fl[3]; rect(x, max(yb, 58), 1, H - max(yb, 58), c[1], c[2], c[3]) if yb - yt > 4 then c = p.base; rect(x, yb - (isend and 2 or 3), 1, isend and 2 or 3, c[1], c[2], c[3]) end end c = p.stripe for _, x in ipairs({ 5, 9, 54, 58 }) do local dx = x < CX and (CX - 0.5 - x) or (x + 0.5 - CX) local k = dx / A rect(x, floor(CY - B1 * k + 0.5) + 1, 1, floor((B1 + B2) * k) - 4, c[1], c[2], c[3]) end c = p.frame; rect(DX0 - 1, DY0 - 2, DX1 - DX0 + 3, DY1 - DY0 + 3, c[1], c[2], c[3]) c = p.inner; rect(DX0, DY0, DX1 - DX0 + 1, DY1 - DY0 + 1, c[1], c[2], c[3]) c = p.inner2; rect(DX0, DY1 - 3, DX1 - DX0 + 1, 4, c[1], c[2], c[3]) BG[p] = gfx.snapshot(0, 0, W, H) end local HAT = { 0, 1, 1, 2, 2, 3, 4 } local HEAD = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 5 } local BODY = { 5, 5, 6, 6, 6 } local YL, YH, YB = { 255, 226, 40 }, { 222, 176, 10 }, { 70, 100, 240 } local BLUE2, RED = { 240, 244, 255 }, { 240, 50, 50 } local EYE_LIT = { 255, 238, 130 } local B = { r = 240, g = 40, b = 40 } local IDLE, CYC = 90, 270 local VIS = 185 function on_settings() local c = cfg.balloon or { r = 240, g = 40, b = 40 } B = c IDLE = (cfg.idle or 3) * 30 CYC = IDLE + VIS end local function creature(cx, tilt, blink, grin) local y = 23 rect(cx - 1 + floor(tilt + 0.5), y, 2, 2, RED[1], RED[2], RED[3]) y = 25 for i = 1, #HAT do local yy = y + i - 1 local off = floor(tilt * (42 - yy) / 18 + 0.5) local hw = HAT[i] local c = (i == 4 or i == 5) and BLUE2 or YB if i == 4 or i == 5 then rect(cx + off - hw, yy, 2 * hw + 1, 1, YB[1], YB[2], YB[3]) rect(cx + off - hw + 1, yy, 2 * hw - 1, 1, c[1], c[2], c[3]) else rect(cx + off - hw, yy, 2 * hw + 1, 1, c[1], c[2], c[3]) end end for i = 1, #HEAD do local yy = 32 + i - 1 local off = floor(tilt * (42 - yy) / 18 + 0.5) local hw = HEAD[i] rect(cx + off - hw, yy, 2 * hw + 1, 1, YL[1], YL[2], YL[3]) rect(cx + off + hw, yy, 1, 1, YH[1], YH[2], YH[3]) end for i = 1, #BODY do local hw = BODY[i] rect(cx - hw, 42 + i - 1, 2 * hw + 1, 1, YL[1], YL[2], YL[3]) rect(cx + hw, 42 + i - 1, 1, 1, YH[1], YH[2], YH[3]) end rect(cx - 9, 40, 3, 2, YL[1], YL[2], YL[3]) local o = floor(tilt * 7 / 18 + 0.5) local ex = cx + o if blink then rect(ex - 4, 36, 2, 1, 0, 0, 0); rect(ex + 2, 36, 2, 1, 0, 0, 0) else rect(ex - 4, 35, 2, 2, 0, 0, 0); rect(ex + 2, 35, 2, 2, 0, 0, 0) end local ox = cx + floor(tilt * 3 / 18 + 0.5) px(ox - 5, 38, 0, 0, 0); px(ox + 4, 38, 0, 0, 0) rect(ox - 4, 39, 8, 1, 0, 0, 0) if grin then rect(ox - 3, 40, 6, 1, 252, 246, 222) end return cx - 8, 40 end local function eyes(cx) rect(cx - 4, 35, 2, 2, EYE_LIT[1], EYE_LIT[2], EYE_LIT[3]) rect(cx + 2, 35, 2, 2, EYE_LIT[1], EYE_LIT[2], EYE_LIT[3]) end local function balloon(bx, by, hx, hy, t) local kx, ky = bx, by + 6 local n = 10 for i = 0, n do local u = i / n local x = hx + (kx - hx) * u + sin(u * 5 + t * 0.15) * 1.2 * u local y = hy + (ky - hy) * u px(floor(x + 0.5), floor(y + 0.5), 236, 236, 226) end local rows = { 1, 2, 3, 3, 3, 3, 3, 2, 1 } for i = 1, #rows do rect(bx - rows[i], by - 5 + i, 2 * rows[i] + 1, 1, B.r, B.g, B.b) end px(bx - 2, by - 3, 255, 200, 200); px(bx - 2, by - 2, 255, 200, 200) px(bx, by + 5, B.r, B.g, B.b) end function render() FR = frame * STEP_HZ // gfx.FPS if not B then return end local t = FR % CYC local vt = t - IDLE local pi = 1 local fl = (t + 17) % 97 if fl == 0 or fl == 2 or fl == 3 then pi = 4 end local show = 0 local pgr = 0 if vt >= 0 then if vt < 30 then show = 1 elseif vt < 145 then show = 2; pgr = min(1, (vt - 30) / 16) else local vf = vt - 145 if (vf >= 4 and vf < 6) or (vf >= 10 and vf < 12) or (vf >= 15 and vf < 17) or (vf >= 20 and vf < 22) then pi = 3 end if vf < 10 then show = 2; pgr = 1 elseif vf < 16 then show = 1 end if vf >= 16 and vf < 20 then show = 0 end if vf >= 24 then pi = 1 elseif pi == 1 then pi = 2 end end if vt < 30 and (vt % 29 < 2) then pi = 2 end end local p = PALS[pi] if not BG[p] then build_bg(p) else gfx.blit_rgb(BG[p], 0, 0, W, H) end for _, r in ipairs(LAMPS) do local lc = p.lamp for y = r[1], r[2] do local dx = 0.612 * (CY - y - 0.5) rect(floor(CX - dx + 0.5), y, floor(2 * dx + 0.5), 1, lc[1], lc[2], lc[3]) end end if show == 0 then return end gfx.clip(DX0, DY0, DX1 - DX0 + 1, DY1 - DY0 + 1) if show == 1 then if (vt < 30 and vt >= 8 and (vt % 20 < 17)) or vt >= 145 then if not (vt % 11 == 0) then eyes(32 + (vt >= 145 and 0 or 0)) end end gfx.clip() return end local ease = pgr * pgr * (3 - 2 * pgr) local sway = (vt >= 46) and 2 * sin(vt * 0.07) or 0 local cx = 32 + floor((1 - ease) * 14 + 0.5) local blink = vt % 53 < 3 local grin = (vt % 90) < 60 local hx, hy = creature(cx, sway, blink, grin) gfx.clip() local bob = sin(vt * 0.09) local bx = cx - 14 + floor(bob * 1.6 + 0.5) local by = 21 + floor(sin(vt * 0.07 + 1) * 2 + 0.5) + floor((1 - ease) * 6) gfx.clip(0, 0, DX1 + 2, H) balloon(bx, by, hx, hy, vt) gfx.clip() end