info = { type = "image", title = "Pancake chef", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A bear chef flips pancakes onto a stack", api = 33, } local tr = ({ sk = { ["Fur colour"] = "Farba srsti", ["Flip speed"] = "Rýchlosť preklápania", ["slow"] = "pomaly", ["normal"] = "normálne", ["fast"] = "rýchlo" }, cs = { ["Fur colour"] = "Barva srsti", ["Flip speed"] = "Rychlost překlápění", ["slow"] = "pomalu", ["normal"] = "normálně", ["fast"] = "rychle" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "fur", label = T("Fur colour"), type = "color", default = "#A8683A" }, { key = "speed", label = T("Flip speed"), type = "int", default = 1, opts = { T("slow"), T("normal"), T("fast") } }, } local rect, px, blend = gfx.rect, gfx.px, gfx.blend local floor, sin, cos, abs, PI = math.floor, math.sin, math.cos, math.abs, math.pi local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local WALL, TILE = { 52, 116, 128 }, { 40, 96, 108 } local SHELF, JAR1, JAR2, LID = { 120, 80, 50 }, { 206, 120, 60 }, { 96, 176, 96 }, { 156, 156, 168 } local TOP1, TOP2 = { 214, 220, 230 }, { 168, 174, 186 } local WOOD, WOOD_D, KNOB = { 134, 80, 50 }, { 102, 58, 34 }, { 230, 200, 120 } local HAT, HAT_D, HAT_DD = { 250, 250, 252 }, { 206, 210, 224 }, { 168, 172, 190 } local JACKET, JACKET_D, BUTTON = { 240, 240, 236 }, { 200, 204, 214 }, { 140, 140, 156 } local SCARF, SCARF_D = { 222, 52, 52 }, { 160, 30, 36 } local MUZ, NOSE, EAR_IN, BLUSH = { 240, 212, 168 }, { 50, 30, 26 }, { 236, 150, 150 }, { 240, 128, 128 } local EYE, SHINE, MOUTH = { 24, 16, 20 }, { 255, 255, 255 }, { 200, 56, 70 } local PAN, PAN_L, PAN_D, HANDLE = { 64, 64, 72 }, { 112, 112, 124 }, { 40, 40, 46 }, { 70, 44, 30 } local CAKE, CAKE_D, CAKE_B, BATTER = { 242, 180, 80 }, { 198, 122, 48 }, { 156, 88, 34 }, { 250, 226, 160 } local PLATE, PLATE_L = { 196, 204, 218 }, { 236, 240, 248 } local BUTTER, SYRUP = { 255, 236, 140 }, { 170, 80, 22 } local FL_B, FL_O = { 70, 120, 255 }, { 255, 150, 40 } local STEAM = { 226, 236, 244 } local function c3(c) return c[1], c[2], c[3] end local CYCLES = { 120, 90, 66 } local CY = 90 local FUR, FUR_D = { 168, 104, 58 }, { 120, 74, 40 } local BG = nil function on_settings() local c = cfg.fur or { r = 168, g = 104, b = 58 } FUR = { c.r, c.g, c.b } FUR_D = { floor(c.r * 0.7), floor(c.g * 0.7), floor(c.b * 0.7) } CY = CYCLES[(cfg.speed or 1) + 1] or 90 BG = nil end local BX = 20 local HEAD = { 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 6, 4 } local function ear(x) rect(x - 1, 14, 3, 1, c3(FUR)) rect(x - 2, 15, 5, 3, c3(FUR)) rect(x - 1, 18, 3, 1, c3(FUR)) rect(x - 1, 15, 3, 2, c3(EAR_IN)) end local function build_bg() rect(0, 0, W, H, c3(WALL)) for x = 7, W - 1, 8 do rect(x, 0, 1, 45, c3(TILE)) end for y = 7, 44, 8 do rect(0, y, W, 1, c3(TILE)) end rect(0, 12, 10, 1, c3(SHELF)) rect(1, 8, 3, 4, c3(JAR1)); rect(1, 7, 3, 1, c3(LID)) rect(5, 9, 3, 3, c3(JAR2)); rect(5, 8, 3, 1, c3(LID)) rect(0, 45, W, 1, c3(TOP1)) rect(0, 46, W, 1, c3(TOP2)) rect(0, 47, W, 17, c3(WOOD)) rect(0, 54, W, 1, c3(WOOD_D)) rect(21, 47, 1, 17, c3(WOOD_D)); rect(50, 47, 1, 17, c3(WOOD_D)) px(10, 50, c3(KNOB)); px(56, 50, c3(KNOB)); px(10, 58, c3(KNOB)); px(56, 58, c3(KNOB)) rect(38, 49, 2, 2, c3(PAN_D)); rect(46, 49, 2, 2, c3(PAN_D)) rect(53, 43, 11, 1, c3(PLATE_L)) rect(52, 44, 12, 1, c3(PLATE)) rect(13, 31, 15, 1, c3(JACKET)) rect(12, 32, 17, 1, c3(JACKET)) rect(11, 33, 19, 12, c3(JACKET)) rect(27, 33, 2, 12, c3(JACKET_D)) px(18, 34, c3(BUTTON)); px(22, 34, c3(BUTTON)); px(18, 38, c3(BUTTON)) px(22, 38, c3(BUTTON)); px(18, 42, c3(BUTTON)); px(22, 42, c3(BUTTON)) rect(8, 33, 3, 7, c3(JACKET)); rect(8, 40, 3, 3, c3(FUR)) rect(29, 33, 3, 6, c3(JACKET)); rect(29, 38, 3, 1, c3(JACKET_D)) ear(BX - 8); ear(BX + 8) for i = 1, #HEAD do local w = HEAD[i] rect(BX - w, 14 + i, 2 * w + 1, 1, c3(FUR)) end for i = 2, #HEAD - 1 do rect(BX + HEAD[i], 14 + i, 1, 1, c3(FUR_D)) end rect(15, 29, 11, 2, c3(SCARF)); px(20, 31, c3(SCARF_D)); px(19, 30, c3(SCARF_D)) rect(BX - 2, 22, 5, 1, c3(MUZ)) rect(BX - 3, 23, 7, 3, c3(MUZ)) rect(BX - 2, 26, 5, 1, c3(MUZ)) rect(BX - 1, 22, 3, 2, c3(NOSE)); px(BX - 1, 22, 110, 90, 86) px(BX, 24, c3(NOSE)); px(BX - 1, 25, c3(NOSE)); px(BX + 1, 25, c3(NOSE)) rect(13, 23, 2, 1, c3(BLUSH)); rect(26, 23, 2, 1, c3(BLUSH)) rect(BX - 1, 5, 3, 1, c3(HAT)) rect(BX - 5, 6, 11, 1, c3(HAT)) rect(BX - 6, 7, 13, 5, c3(HAT)) rect(BX - 5, 12, 11, 1, c3(HAT)) rect(BX + 4, 8, 2, 4, c3(HAT_D)) px(BX - 3, 6, c3(HAT_D)); px(BX + 3, 6, c3(HAT_D)) rect(BX - 5, 13, 11, 3, c3(HAT_D)) px(BX - 3, 14, c3(HAT_DD)); px(BX, 14, c3(HAT_DD)); px(BX + 3, 14, c3(HAT_DD)) rect(BX - 5, 13, 11, 1, c3(HAT)) BG = gfx.snapshot(0, 0, W, H) end local function draw_eyes(mode, ex, ey) if mode == "happy" then local er, eg, eb = EYE[1], EYE[2], EYE[3] px(15, 20, er, eg, eb); rect(16, 19, 2, 1, er, eg, eb); px(18, 20, er, eg, eb) px(22, 20, er, eg, eb); rect(23, 19, 2, 1, er, eg, eb); px(25, 20, er, eg, eb) rect(BX - 1, 25, 3, 1, c3(MOUTH)) elseif mode == "blink" then rect(16 + ex, 20, 2, 1, c3(EYE)); rect(23 + ex, 20, 2, 1, c3(EYE)) else rect(16 + ex, 19 + ey, 2, 2, c3(EYE)); rect(23 + ex, 19 + ey, 2, 2, c3(EYE)) px(16 + ex, 19 + ey, c3(SHINE)); px(23 + ex, 19 + ey, c3(SHINE)) end end local function draw_pan(off) rect(30, 39 + off, 4, 4, c3(FUR)) rect(34, 41 + off, 3, 1, c3(HANDLE)) rect(37, 40 + off, 13, 1, c3(PAN_L)) rect(36, 41 + off, 15, 1, c3(PAN)) rect(37, 42 + off, 13, 1, c3(PAN_D)) end local function draw_flames(t) for i = 0, 4 do local x = 39 + 2 * i local h = hash32((t // 3) * 0x9E3779B1 + i * 0x2545F491) px(x, 44, c3(FL_B)) if (h & 3) ~= 0 then px(x, 43, c3(FL_O)) end end end local function draw_stack(n, squash) for i = 1, n do local yb = 42 - 2 * (i - 1) if i == n and squash then rect(51, yb, 13, 1, c3(CAKE)) else rect(52, yb, 11, 1, c3(CAKE_D)) rect(53, yb - 1, 9, 1, c3(CAKE)) end end if n > 0 and not squash then local ty = 42 - 2 * (n - 1) - 1 rect(56, ty - 1, 2, 1, c3(BUTTER)) px(61, ty, c3(SYRUP)); px(62, ty + 1, c3(SYRUP)); px(62, ty + 2, c3(SYRUP)) end end local function fly_cake(x, y, a) local c = cos(a) local hgt = abs(c) local face = c >= 0 and CAKE or CAKE_B local xi, yi = floor(x + 0.5), floor(y + 0.5) if hgt < 0.35 then rect(xi - 5, yi, 11, 1, c3(CAKE_D)) elseif hgt < 0.75 then rect(xi - 4, yi - 1, 9, 1, c3(face)); rect(xi - 5, yi, 11, 1, c3(CAKE_D)) else rect(xi - 4, yi - 1, 9, 1, c3(face)); rect(xi - 5, yi, 11, 1, c3(face)) rect(xi - 4, yi + 1, 9, 1, c3(CAKE_D)) if c < 0 then px(xi - 2, yi, c3(CAKE_D)); px(xi + 2, yi - 1, c3(CAKE_D)) end end end local function wisp(x0, yb, len, t, ph) local sr, sg, sb = STEAM[1], STEAM[2], STEAM[3] for j = 0, 2 do local p = ((t + ph + j * 13) % 40) / 40 local y = yb - p * len local yi = floor(y) local f = y - yi local x = floor(x0 + 1.2 * sin(p * 6 + ph) + 0.5) local a = 0.6 * (1 - p) blend(x, yi, sr, sg, sb, a * (1 - f)) blend(x, yi + 1, sr, sg, sb, a * f) 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 cyc = t // CY local p = (t % CY) / CY local m = cyc % 6 draw_flames(t) local off = 0 if p >= 0.55 and p < 0.59 then off = -2 elseif p >= 0.59 and p < 0.62 then off = -1 end draw_pan(off) if p < 0.56 then rect(39, 39 + off, 9, 1, c3(CAKE)) local h = hash32((t // 6) * 0x9E3779B1 + cyc) px(40 + umod(h, 7), 39 + off, c3(CAKE_D)) px(40 + umod(h >> 8, 7), 39 + off, c3(CAKE_D)) elseif p >= 0.86 then local w = 3 + floor((p - 0.86) / 0.14 * 6 + 0.5) w = w - (w + 1) % 2 rect(43 - w // 2, 39, w, 1, c3(BATTER)) end local landed = p >= 0.84 draw_stack(landed and m + 1 or m, p >= 0.84 and p < 0.87) if p < 0.56 or p >= 0.9 then wisp(40, 37, 12, t, 0); wisp(44, 37, 14, t, 2.1); wisp(47, 37, 11, t, 4.2) end local n = landed and m + 1 or m if n > 0 then local ty = 42 - 2 * (n - 1) - 3 wisp(55, ty, 9, t, 1.3); wisp(59, ty, 8, t, 3.4) end local mode, ex, ey = "open", 1, 0 if p >= 0.56 and p < 0.84 then local k = (p - 0.56) / 0.28 local x = 43 + (57 - 43) * k local y = 39 + (42 - 2 * m - 39) * k - 120 * k * (1 - k) fly_cake(x, y, k * 2 * PI) ey = y < 22 and -1 or 0 ex = x < 46 and 0 or 1 elseif landed and p < 0.97 then mode = "happy" elseif (t % 100) < 3 then mode = "blink" end draw_eyes(mode, ex, ey) end