info = { type = "image", title = "Lizard court", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Lizard king, bowing courtiers, juggling jester", api = 33, } local tr = ({ sk = { ["Carpet"] = "Koberec", ["Red"] = "Červený", ["Blue"] = "Modrý", ["Green"] = "Zelený", ["Courtiers"] = "Dvorania", ["Juggling speed"] = "Rýchlosť žonglovania" }, cs = { ["Carpet"] = "Koberec", ["Red"] = "Červený", ["Blue"] = "Modrý", ["Green"] = "Zelený", ["Courtiers"] = "Dvořané", ["Juggling speed"] = "Rychlost žonglování" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "carpet", label = T("Carpet"), type = "int", default = "red", opts = { keys = { "red", "blue", "green" }, T("Red"), T("Blue"), T("Green") } }, { key = "courtiers", label = T("Courtiers"), type = "int", min = 1, max = 3, default = 3 }, { key = "juggle", label = T("Juggling speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, blit_indexed, snapshot = gfx.blit_rgb, gfx.blit_indexed, gfx.snapshot local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local char, concat = string.char, table.concat local W, H = gfx.W, gfx.H local KEYS = ".gGlewyYrRtTmpqb" local MAP = {} for i = 1, #KEYS do MAP[KEYS:sub(i, i)] = char(i - 1) end local COL = { ["."] = { 0, 0, 0 }, g = { 78, 170, 74 }, G = { 44, 112, 58 }, l = { 232, 214, 150 }, e = { 24, 16, 22 }, w = { 246, 242, 232 }, y = { 246, 198, 56 }, Y = { 184, 126, 34 }, r = { 208, 44, 56 }, R = { 130, 26, 44 }, m = { 150, 34, 56 }, b = { 255, 236, 120 }, } local function mkpal(t, T2, p, q) local P = {} COL.t, COL.T, COL.p, COL.q = t, T2, p, q for i = 1, #KEYS do local c = COL[KEYS:sub(i, i)] P[#P + 1], P[#P + 2], P[#P + 3] = c[1], c[2], c[3] end return P end local function sprite(rows) local w = 0 for i = 1, #rows do if #rows[i] > w then w = #rows[i] end end local r = {} for i = 1, #rows do r[i] = rows[i] .. string.rep(".", w - #rows[i]) end return { s = (concat(r):gsub(".", MAP)), w = w, h = #r } end local function flip(rows) local o = {} for i = 1, #rows do o[i] = rows[i]:reverse() end return o end local function draw(sp, pal, x, y) blit_indexed(sp.s, pal, x, y, sp.w, sp.h, sp.w, sp.h, true) end local KING_ROWS = { "..y..yy..y..", "..yyyyyyyy..", "..yryYYyry..", ".gggggggggg.", ".ggeggggegg.", ".gggggggggg.", ".gGGGGGGGGg.", "..gggggggg..", ".rwrwrwrwrr.", "grrrrrrrrrrg", "grrrrrrrrrrg", "grrRrrrrRrrg", ".rrrrrrrrrr.", ".rrrrrrrrrr.", "wwwwwwwwwwww", "..gg....gg..", ".ggg....ggg.", } local function king_pose(over) local r = {} for i = 1, #KING_ROWS do r[i] = over[i] or KING_ROWS[i] end return sprite(r) end local SHUT, MOUTH = ".ggGggggGgg.", ".gmmmmmmmmg." local KING = { [0] = sprite(KING_ROWS), king_pose({ [5] = SHUT, [7] = MOUTH }), king_pose({ [5] = SHUT, [6] = MOUTH, [7] = MOUTH, [8] = MOUTH }), king_pose({ [5] = SHUT }), } local UP = { "....GGGG...", "...gggggg..", "...gggegg..", "...ggggggG.", "....gggg...", "...tttttt..", "..ttttttt..", "..ttTttgt..", "g.ttttttt..", "gg.TTTTT...", "Gg..gg.gg..", "G...GG.GG..", } local B1 = { "...........", ".....GGGG..", "....gggggg.", "....gggeggG", ".....ggggg.", "...tttttt..", "..tttttttt.", "..ttTttttg.", "g.tttttt...", "gg.TTTTT...", "Gg..gg.gg..", "G...GG.GG..", } local B2 = { ".....GGGG..", "...gggggggg", "..ttgggegGG", ".ttttttttt.", "gtttTtttgt.", "gg.TTTTTT..", "Gg..gg.gg..", "G...GG.GG..", } local COURT = { { sprite(UP), sprite(B1), sprite(B2) }, { sprite(flip(UP)), sprite(flip(B1)), sprite(flip(B2)) } } local JESTER = sprite({ "b.......b", "pp.....qq", ".ppp.qqq.", "..ppqqq..", "..yyyyy..", "..ggggg..", "..gegeg..", "..gwwwg..", ".ppppqqq.", ".ppppqqq.", "..ppqqq..", "..pp.qq..", "..gg.gg..", }) local P_KING = mkpal({ 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }) local COURTIERS = { { x = 5, foot = 57, side = 1, off = 0, pal = mkpal({ 58, 92, 206 }, { 34, 56, 142 }, { 0, 0, 0 }, { 0, 0, 0 }) }, { x = 15, foot = 49, side = 1, off = 70, pal = mkpal({ 150, 70, 184 }, { 98, 42, 122 }, { 0, 0, 0 }, { 0, 0, 0 }) }, { x = 40, foot = 51, side = 2, off = 140, pal = mkpal({ 36, 160, 156 }, { 22, 100, 100 }, { 0, 0, 0 }, { 0, 0, 0 }) }, } local P_JESTER = mkpal({ 0, 0, 0 }, { 0, 0, 0 }, { 214, 52, 70 }, { 60, 110, 220 }) local CARPETS = { red = { { 176, 34, 50 }, { 232, 182, 60 } }, blue = { { 44, 76, 176 }, { 232, 182, 60 } }, green = { { 34, 128, 70 }, { 232, 182, 60 } }, } local function R(x, y, w, h, c) rect(x, y, w, h, c[1], c[2], c[3]) end local WALL, JOINT = { 92, 78, 112 }, { 76, 64, 96 } local STONE, STONE_L, STONE_D = { 150, 136, 160 }, { 176, 164, 184 }, { 118, 106, 132 } local FLOOR1, FLOOR2 = { 134, 108, 92 }, { 116, 92, 80 } local WOOD, WOOD_L = { 120, 78, 42 }, { 156, 106, 56 } local GOLD = { 232, 182, 60 } local BG = nil local function column(x) R(x - 1, 0, 8, 2, STONE_L) R(x, 2, 6, 34, STONE) R(x + 4, 2, 2, 34, STONE_D) R(x + 1, 2, 1, 34, STONE_L) R(x - 1, 36, 8, 3, STONE_L) end local function banner(x, c) R(x - 1, 1, 8, 1, GOLD) R(x, 2, 6, 14, c) R(x, 16, 2, 1, c); R(x + 4, 16, 2, 1, c) R(x, 2, 6, 1, GOLD) R(x + 2, 5, 2, 5, GOLD); R(x + 1, 6, 4, 2, GOLD) end local function build_bg() local C = CARPETS[cfg.carpet] or CARPETS.red R(0, 0, W, 40, WALL) for r = 0, 7 do local y = 4 + 5 * r if y < 38 then R(0, y, W, 1, JOINT) end for x = (r % 2) * 6, W - 1, 12 do R(x, y - 4, 1, 4, JOINT) end end R(0, 38, W, 2, { 60, 50, 72 }) local rows = { { 40, 6, 8 }, { 46, 7, 10 }, { 53, 8, 12 }, { 61, 3, 14 } } for i = 1, #rows do local rw = rows[i] for k = 0, W // rw[3] + 1 do R(k * rw[3] - (i % 2) * (rw[3] // 2), rw[1], rw[3], rw[2], (k + i) % 2 == 0 and FLOOR1 or FLOOR2) end end column(2); column(56) banner(10, C[1]); banner(48, C[1]) R(17, 37, 30, 3, STONE_D); R(17, 37, 30, 1, STONE) R(21, 32, 22, 5, STONE_L); R(21, 35, 22, 2, STONE) R(24, 6, 16, 26, WOOD); R(24, 6, 1, 26, WOOD_L) R(27, 3, 10, 3, WOOD); R(30, 1, 4, 2, WOOD_L) R(26, 9, 12, 23, { 110, 26, 48 }) R(23, 24, 3, 8, WOOD_L); R(38, 24, 3, 8, WOOD_L) for hw = 4, 7 do local ya = 36 + (hw - 4) * 7 R(32 - hw, ya, 2 * hw, 7, C[1]) R(32 - hw, ya, 1, 7, C[2]); R(31 + hw, ya, 1, 7, C[2]) end R(30, 36, 4, 1, C[2]) R(18, 21, 3, 7, { 70, 54, 40 }); R(42, 21, 3, 7, { 70, 54, 40 }) BG = snapshot(0, 0, W, H) end function on_settings() BG = nil end local function torch(tx, ty, ph) local h = umod(hash32((frame // 3) * 7 + ph), 3) rect(tx - 1, ty + 1, 3, 4, 214, 84, 24) rect(tx, ty - h, 1, 3 + h, 250, 170, 40) px(tx, ty + 3, 255, 236, 140) end local BEAT = { 10, 8, 7, 6, 5 } local OFF = { [0] = 0, 2, 1 } local BALL = { { 230, 50, 50 }, { 250, 220, 60 }, { 60, 200, 230 } } local function juggle(jx, jy, t) local tau = BEAT[cfg.juggle or 3] local pk = math.min(24, 0.28 * tau * tau) local T = t / tau + 60 local hy = jy + 6 local xl, xr = jx - 1, jx + 8 for k = 0, 2 do local m = (T - OFF[k]) / 3 local mi = floor(m) local f = m - mi local x = (OFF[k] + 3 * mi) % 2 == 0 and xl + (xr - xl) * f or xr + (xl - xr) * f local c = BALL[k + 1] rect(floor(x + 0.5), floor(hy - 4 * f * (1 - f) * pk + 0.5) - 1, 2, 2, c[1], c[2], c[3]) end end function render() if not BG then build_bg() else blit_rgb(BG, 0, 0, W, H) end local t = frame torch(19, 15, 0); torch(43, 15, 5) local yp = t % 420 local pose = 0 if yp >= 300 and yp < 350 then pose = (yp < 310 or yp >= 340) and 1 or 2 elseif yp % 97 < 3 then pose = 3 end draw(KING[pose], P_KING, 26, 15) rect(25, 13, 1, 19, 184, 126, 34) rect(24, 10, 3, 3, 214, 40, 52); px(24, 10, 255, 190, 190) if t % 150 < 4 then px(29, 15, 255, 255, 255) end for i = 1, cfg.courtiers or 3 do local c = COURTIERS[i] local ph = (t - c.off) % 360 local k = 1 if ph < 52 then k = ph < 4 and 1 or (ph < 9 and 2 or (ph < 42 and 3 or (ph < 48 and 2 or 1))) end local sp = COURT[c.side][k] blend_rect(c.x + 1, c.foot, 9, 1, 0, 0, 0, 0.25) draw(sp, c.pal, c.x, c.foot - sp.h) end local jx, jy = 52, 49 local bob = (t / BEAT[cfg.juggle or 3]) % 1 < 0.3 and 1 or 0 blend_rect(jx, 62, 9, 1, 0, 0, 0, 0.25) draw(JESTER, P_JESTER, jx, jy + 1 - bob) rect(jx - 1, jy + 8, 2, 1, 214, 52, 70); px(jx - 1, jy + 7, 214, 52, 70) rect(jx + 8, jy + 8, 2, 1, 60, 110, 220); px(jx + 9, jy + 7, 60, 110, 220) juggle(jx, jy - bob, t) end