info = { type = "image", title = "King's hall", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A king strolls through a torchlit castle hall", api = 33, } local tr = ({ sk = { ["Robe"] = "Plášť", ["Burgundy"] = "Bordový", ["Royal blue"] = "Kráľovská modrá", ["Forest"] = "Lesný", ["Purple"] = "Fialový", ["Walk speed"] = "Rýchlosť chôdze", ["Slow"] = "Pomaly", ["Normal"] = "Bežne", ["Brisk"] = "Svižne" }, cs = { ["Robe"] = "Plášť", ["Burgundy"] = "Bordó", ["Royal blue"] = "Královská modř", ["Forest"] = "Lesní", ["Purple"] = "Fialový", ["Walk speed"] = "Rychlost chůze", ["Slow"] = "Pomalu", ["Normal"] = "Běžně", ["Brisk"] = "Svižně" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "robe", label = T("Robe"), type = "int", default = "burgundy", opts = { keys = { "burgundy", "blue", "forest", "purple" }, T("Burgundy"), T("Royal blue"), T("Forest"), T("Purple") } }, { key = "speed", label = T("Walk speed"), type = "int", default = 1, opts = { T("Slow"), T("Normal"), T("Brisk") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot, blit_idx, blend_mask = gfx.blit_rgb, gfx.snapshot, gfx.blit_indexed, gfx.blend_mask local floor, sin, min, max, sqrt = math.floor, math.sin, math.min, math.max, math.sqrt local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STONE, STONE2, MORTAR = { 112, 104, 94 }, { 124, 116, 104 }, { 70, 64, 60 } local CEIL, FRAME, FRAME_L = { 44, 38, 38 }, { 150, 142, 128 }, { 182, 174, 158 } local FL1, FL2, FL3, FJ = { 100, 92, 86 }, { 90, 82, 78 }, { 80, 72, 70 }, { 56, 50, 50 } local SKYB = { { 24, 34, 100 }, { 36, 52, 128 }, { 54, 78, 156 }, { 76, 108, 190 } } local MOON, STAR = { 234, 238, 255 }, { 220, 226, 255 } local RED, RED_D, GOLD, GOLD_D = { 150, 34, 40 }, { 96, 20, 28 }, { 232, 184, 56 }, { 176, 132, 36 } local IRON, WOOD = { 52, 46, 46 }, { 110, 72, 40 } local FL_O, FL_Y = { 255, 150, 40 }, { 255, 226, 120 } local PILLAR, PIL_L, PIL_D = { 54, 48, 46 }, { 96, 88, 82 }, { 34, 30, 30 } local SKIN, HAIR, BEARD, PALE, DARK = { 238, 192, 150 }, { 170, 164, 156 }, { 190, 184, 174 }, { 238, 234, 226 }, { 30, 24, 24 } local BOOT = { 48, 28, 24 } local ROBES = { burgundy = { 132, 42, 38 }, blue = { 52, 72, 152 }, forest = { 52, 112, 70 }, purple = { 112, 58, 142 } } local ROBE, ROBE_D, ROBE_L = ROBES.burgundy, nil, nil local V0 = 11 local function T3(c) return c[1], c[2], c[3] end local function shade(c, k) return { min(255, floor(c[1] * k)), min(255, floor(c[2] * k)), min(255, floor(c[3] * k)) } end ROBE_D, ROBE_L = shade(ROBE, 0.7), shade(ROBE, 1.3) function on_settings() ROBE = ROBES[cfg.robe] or ROBES.burgundy ROBE_D, ROBE_L = shade(ROBE, 0.7), shade(ROBE, 1.3) V0 = ({ 8, 11, 15 })[(cfg.speed or 1) + 1] or 11 end local function hs(x0, x1, y, h, c, a) if x1 <= x0 or x1 < 0 or x0 > W then return end a = a or 1 local r, g, b = c[1], c[2], c[3] local i0, i1 = floor(x0), floor(x1) if i0 == i1 then blend_rect(i0, y, 1, h, r, g, b, (x1 - x0) * a); return end if i1 > i0 + 1 then if a >= 1 then rect(i0 + 1, y, i1 - i0 - 1, h, r, g, b) else blend_rect(i0 + 1, y, i1 - i0 - 1, h, r, g, b, a) end end blend_rect(i0, y, 1, h, r, g, b, (i0 + 1 - x0) * a) if x1 > i1 then blend_rect(i1, y, 1, h, r, g, b, (x1 - i1) * a) end end local function vline(x, y, h, c, a) local ix = floor(x) local f = x - ix blend_rect(ix, y, 1, h, c[1], c[2], c[3], a * (1 - f)) blend_rect(ix + 1, y, 1, h, c[1], c[2], c[3], a * f) end local BG, GLOW local function checker(h, dens) local rows = {} for y = 1, h do local d = dens[y] local cells = {} for x = 1, W do local on if d == 4 then on = true elseif d == 3 then on = not (x % 2 == 0 and y % 2 == 0) elseif d == 2 then on = (x + y) % 2 == 0 else on = x % 2 == 0 and y % 2 == 0 end cells[x] = on and 1 or 0 end rows[y] = string.char(table.unpack(cells, 1, W)) end return table.concat(rows) end local function build() rect(0, 7, W, 41, T3(STONE)) rect(0, 0, W, 7, T3(CEIL)) for c = 0, 3 do if c % 2 == 1 then rect(0, 7 + 10 * c, W, 10, T3(STONE2)) end rect(0, 16 + 10 * c, W, 1, T3(MORTAR)) end rect(0, 47, W, 1, T3(MORTAR)) rect(0, 48, W, 4, T3(FL1)) rect(0, 52, W, 5, T3(FL2)) rect(0, 57, W, 7, T3(FL3)) rect(0, 52, W, 1, T3(FJ)) rect(0, 57, W, 1, T3(FJ)) blit_idx(checker(4, { 4, 3, 2, 1 }), { 0, 0, 0, 30, 26, 26 }, 0, 7, W, 4, W, 4, true) blit_idx(checker(3, { 1, 2, 3 }), { 0, 0, 0, 36, 32, 30 }, 0, 61, W, 3, W, 3, true) BG = snapshot(0, 0, W, H) end local GW, GH = 25, 21 local function glow() local rows, row = {}, {} for y = 0, GH - 1 do for x = 0, GW - 1 do local d = sqrt(((x - 12) / 12) ^ 2 + ((y - 10) / 10) ^ 2) row[x + 1] = d < 1 and floor(255 * (1 - d)) or 0 end rows[y + 1] = string.char(table.unpack(row, 1, GW)) end GLOW = table.concat(rows) end local CYC = 15 local function path(tau) if tau < 0.9 then local x = tau / 0.9 return 0.9 * (x ^ 3 - x ^ 4 / 2) elseif tau < 9 then return 0.45 + tau - 0.9 elseif tau < 9.9 then local x = (tau - 9) / 0.9 return 8.55 + (tau - 9) - 0.9 * (x ^ 3 - x ^ 4 / 2) end return 9 end local MOONW = { 1.5, 2.5, 3, 3, 3, 2.5, 1.5 } local STARS = { 21, 17, 33, 27, 52, 16, 9, 26 } local function window(xc) hs(xc - 3, xc + 3, 11, 1, FRAME) hs(xc - 5, xc + 5, 12, 1, FRAME) hs(xc - 6.2, xc + 6.2, 13, 21, FRAME) hs(xc - 7.2, xc + 7.2, 34, 2, FRAME_L) local gl, gr = xc - 4.2, xc + 4.2 hs(xc - 3, xc + 3, 13, 1, SKYB[1]) for i = 1, 4 do hs(gl, gr, 9 + 5 * i, 5, SKYB[i]) end if gr > 36 and gl < 44 then for k = 1, 7 do local w = MOONW[k] local a, b = max(40 - w, gl), min(40 + w, gr) if b > a then hs(a, b, 17 + k, 1, MOON) end end end for i = 1, 4 do local sx = STARS[i * 2 - 1] if sx > gl and sx < gr then px(sx, STARS[i * 2], T3(STAR)) end end hs(xc - 0.5, xc + 0.5, 14, 19, FRAME) hs(gl, gr, 23, 1, FRAME) for i = 0, 4 do local cx = xc + 3 + i * 3 hs(cx - 4.5 - i * 0.5, cx + 4.5 + i * 0.5, 48 + i * 3, 3, { 150, 180, 240 }, 0.17) end end local function banner(xc) hs(xc - 5, xc + 5, 12, 1, GOLD_D) hs(xc - 4, xc + 4, 13, 15, RED) hs(xc - 4, xc - 3, 13, 15, RED_D) hs(xc - 4, xc - 1, 28, 2, RED) hs(xc + 1, xc + 4, 28, 2, RED) hs(xc - 4, xc + 4, 14, 1, GOLD) hs(xc - 0.5, xc + 0.5, 16, 9, GOLD) hs(xc - 2.5, xc + 2.5, 19, 1, GOLD) end local function torch(xt, ph, t) local fl = floor(t * 10 + ph) % 3 blend_mask(GLOW, 255, 150, 60, floor(xt + 0.5) - 12, 11, GW, GH, GW, GH, 0.34 + 0.08 * fl) hs(xt - 2, xt + 2, 28, 1, IRON) hs(xt - 0.5, xt + 0.5, 24, 4, WOOD) hs(xt - 1.5, xt + 1.5, 23, 1, IRON) hs(xt - 1.5, xt + 1.5, 20, 3, FL_O) hs(xt - 0.5, xt + 0.5, 19 - fl, 1 + fl, FL_O) hs(xt - 0.5, xt + 0.5, 21, 2, FL_Y) end local function pillar(x) hs(x - 1, x + 8, 0, 4, PILLAR) hs(x - 1, x + 8, 60, 4, PILLAR) hs(x, x + 7, 4, 56, PILLAR) hs(x + 1, x + 2.5, 4, 56, PIL_L) hs(x + 5, x + 7, 4, 56, PIL_D) end local KX, KY = 22, 33 local function king(pose, adj) local bob = (pose == 1 or pose == 3) and -1 or 0 local function K(x, y, w, h, c) rect(KX + x, KY + y, w, h, T3(c)) end local s = pose == 0 and 2 or (pose == 2 and -2 or 0) local cd = adj == 1 and 1 or 0 if pose == 0 then K(0, 24, 3, 2, BOOT); K(5, 24, 3, 2, BOOT) elseif pose == 2 then K(1, 24, 3, 2, BOOT); K(6, 24, 3, 2, BOOT) elseif pose == 4 or adj then K(1, 24, 3, 2, BOOT); K(4, 24, 3, 2, BOOT) else K(2, 24, 4, 2, BOOT) end K(0, 12 + bob, 8, 12 - bob, ROBE) K(0, 12 + bob, 2, 12 - bob, ROBE_D) K(0, 16 + bob, 8, 1, GOLD) K(0, 22, 8, 1, GOLD_D) K(0, 10 + bob, 8, 2, PALE); K(2, 11 + bob, 1, 1, DARK); K(5, 11 + bob, 1, 1, DARK) K(1, 3 + bob, 6, 5, SKIN); K(0, 3 + bob, 2, 4, HAIR); K(3, 8 + bob, 4, 2, BEARD) K(5, 5 + bob, 1, 1, DARK); K(7, 5 + bob, 1, 1, SKIN) K(1 + cd, 1 + bob, 6, 2, GOLD) K(1 + cd, bob, 1, 1, GOLD); K(3 + cd, bob, 1, 1, GOLD); K(5 + cd, bob, 1, 1, GOLD) K(4 + cd, 1 + bob, 1, 1, RED) if adj then K(4, 8, 3, 5, ROBE_L); K(6, adj == 1 and 2 or 3, 2, 2, SKIN) else K(4 + s, 13 + bob, 3, 6, ROBE_L); K(5 + s, 19 + bob, 2, 2, SKIN) end end function render() if not BG then build(); glow() end local t = frame / FPS local cyc = floor(t / CYC) local tau = t - cyc * CYC local cam = (cyc * 9 + path(tau)) * V0 blit_rgb(BG, 0, 0, W, H) for c = 0, 3 do local y = 7 + 10 * c local x0 = (c % 2) * 10 for j = floor((cam - x0) / 20), floor((cam - x0 + W) / 20) + 1 do vline(j * 20 + x0 - cam, y, 9, MORTAR, 1) end end for k = floor(cam / 48), floor((cam + W) / 48) + 1 do hs(k * 48 - cam - 2, k * 48 - cam + 2, 0, 7, IRON) end local k0, k1 = floor((cam - 20) / 48), floor((cam + W + 20) / 48) for k = k0, k1 do local b = k * 48 - cam torch(b + 21, k * 2, t) torch(b + 39, k * 2 + 1, t) end for k = k0, k1 do local b = k * 48 - cam window(b + 8) banner(b + 30) end local FB = { { 48, 4, 14, 1 }, { 52, 5, 20, 1.12 }, { 57, 7, 28, 1.25 } } for i = 1, 3 do local b = FB[i] local sp, f = b[3], b[4] local c = cam * f for j = floor(c / sp), floor((c + W) / sp) + 1 do vline(j * sp - c, b[1], b[2], FJ, 0.8) end end local pose, adj = floor(cam / 4) % 4, nil if tau >= 9.9 then pose = 4 if tau >= 10.4 and tau < 12.5 then adj = (floor((tau - 10.4) / 0.5) % 2 == 0) and 1 or 2 end end king(pose, adj) local pc = cam * 1.8 for k = floor((pc - 30) / 90), floor((pc + W) / 90) + 1 do pillar(k * 90 + 40 - pc) end end