info = { type = "image", title = "Cat rescue", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A kid catches a cat that jumps from a branch", api = 33, } local tr = ({ sk = { ["Shirt"] = "Tričko", ["Cat"] = "Mačka", ["Ginger"] = "Ryšavá", ["Grey"] = "Sivá", ["Black"] = "Čierna", ["Speed"] = "Rýchlosť" }, cs = { ["Shirt"] = "Tričko", ["Cat"] = "Kočka", ["Ginger"] = "Zrzavá", ["Grey"] = "Šedá", ["Black"] = "Černá", ["Speed"] = "Rychlost" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "shirt", label = T("Shirt"), type = "color", default = "#E632AA" }, { key = "fur", label = T("Cat"), type = "int", default = "ginger", opts = { keys = { "ginger", "grey", "black" }, T("Ginger"), T("Grey"), T("Black") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, blend_rect, px = gfx.rect, gfx.blend_rect, gfx.px local floor, sin, cos = math.floor, math.sin, math.cos local W, H, FPS = gfx.W, gfx.H, gfx.FPS local CYC = 17.0 local SKIN, HAIR, INK = { 250, 200, 150 }, { 250, 210, 70 }, { 24, 24, 34 } local PANTS, SHOE = { 52, 78, 206 }, { 30, 34, 90 } local FURS = { ginger = { { 234, 140, 52 }, { 178, 84, 26 }, { 252, 238, 214 } }, grey = { { 156, 160, 176 }, { 104, 108, 128 }, { 244, 244, 250 } }, black = { { 52, 48, 62 }, { 76, 70, 92 }, { 236, 232, 226 } }, } local EYE, PINK = { 190, 238, 80 }, { 242, 140, 150 } local FUR, SHIRT, SHIRT_D = FURS.ginger, { 230, 50, 170 }, { 190, 30, 136 } function on_settings() FUR = FURS[cfg.fur] or FURS.ginger local s = cfg.shirt or { r = 230, g = 50, b = 170 } SHIRT = { s.r, s.g, s.b } SHIRT_D = { floor(s.r * 0.8), floor(s.g * 0.8), floor(s.b * 0.8) } end local BG = nil local function disc(cx, cy, r, r_, g_, b_) for dy = -r, r do local w = floor(math.sqrt(r * r - dy * dy) + 0.5) rect(cx - w, cy + dy, 2 * w + 1, 1, r_, g_, b_) end end local function build() for y = 0, 50 do local t = y / 50 rect(0, y, W, 1, floor(96 + 96 * t), floor(196 + 40 * t), floor(252 + 0 * t)) end for x = 0, W - 1 do local top = 45 + floor(2 * sin(x * 0.12) + 1.5 * sin(x * 0.31 + 1) + 0.5) rect(x, top, 1, 54 - top, 140, 214, 162) end rect(0, 54, W, 10, 92, 192, 86) rect(0, 54, W, 1, 150, 220, 110); rect(0, 60, W, 4, 66, 168, 70) for x = 1, W - 1, 4 do rect(x, 56 + (x * 3) % 4, 1, 1, 128, 214, 112); rect(x + 2, 61 + (x * 5) % 3, 1, 1, 44, 140, 60) end for i = 0, 5 do local fx = (i * 11 + 4) % 50; px(fx, 57 + i % 3, 255, i % 2 == 0 and 244 or 190, i % 2 == 0 and 250 or 210) end rect(52, 14, 10, 42, 124, 80, 46); rect(52, 14, 2, 42, 164, 110, 66); rect(59, 14, 3, 42, 92, 58, 34) rect(49, 52, 16, 4, 124, 80, 46); rect(49, 52, 3, 4, 164, 110, 66); rect(60, 52, 5, 4, 92, 58, 34) for y = 20, 50, 6 do rect(55, y, 1, 2, 86, 54, 32); rect(57, y + 3, 1, 2, 92, 58, 34) end rect(29, 30, 24, 3, 124, 80, 46); rect(29, 30, 24, 1, 168, 114, 70); rect(29, 33, 22, 1, 92, 58, 34) rect(26, 29, 4, 2, 124, 80, 46) disc(27, 26, 4, 46, 150, 66); disc(25, 25, 2, 92, 198, 90); disc(30, 27, 2, 30, 118, 56) local lumps = { { 46, 6, 11 }, { 57, 8, 10 }, { 40, 11, 7 }, { 62, 3, 9 }, { 52, 15, 5 } } for i = 1, #lumps do local l = lumps[i]; disc(l[1] + 1, l[2] + 1, l[3], 30, 118, 56) end for i = 1, #lumps do local l = lumps[i]; disc(l[1], l[2], l[3] - 1, 46, 150, 66) end for i = 1, #lumps do local l = lumps[i]; disc(l[1] - 2, l[2] - 2, l[3] - 4, 92, 198, 90) end BG = gfx.snapshot(0, 0, W, H) end local ax, ay, ad, aw = 0, 0, 1, 10 local function frect(x, y, w, h, r, g, b) local ix = floor(x) local f = x - ix if f < 0.06 then rect(ix, y, w, h, r, g, b) return end if w > 1 then rect(ix + 1, y, w - 1, h, r, g, b) end blend_rect(ix, y, 1, h, r, g, b, 1 - f) blend_rect(ix + w, y, 1, h, r, g, b, f) end local function part(ox, oy, w, h, c) local x = ad > 0 and ax + ox or ax + aw - ox - w frect(x, floor(ay) + oy, w, h, c[1], c[2], c[3]) end local function kid(x, y, d, pose) ax, ay, ad, aw = x, y, d, 10 part(1, 0, 6, 3, HAIR); part(1, 3, 2, 3, HAIR) part(3, 3, 4, 4, SKIN); part(6, 4, 1, 1, INK); part(4, 7, 2, 1, SKIN) part(2, 8, 5, 5, SHIRT) if pose == "reach" then part(5, 7, 3, 2, SHIRT); part(8, 5, 2, 3, SKIN) elseif pose == "hold" then part(5, 9, 4, 2, SHIRT); part(8, 9, 1, 2, SKIN) elseif pose == "stand" then part(3, 8, 2, 4, SHIRT_D); part(3, 12, 2, 1, SKIN) else part(5, 9, 3, 2, SHIRT); part(8, 9, 1, 1, SKIN) end part(2, 13, 5, 1, PANTS) if pose == "stride" then part(1, 14, 2, 2, PANTS); part(0, 16, 3, 1, SHOE) part(6, 14, 2, 2, PANTS); part(6, 15, 3, 1, SHOE) elseif pose == "together" then part(3, 14, 3, 2, PANTS); part(3, 16, 4, 1, SHOE) else part(2, 14, 2, 2, PANTS); part(5, 14, 2, 2, PANTS); part(2, 16, 3, 1, SHOE); part(5, 16, 3, 1, SHOE) end end local function cat(x, y, face, pose, tail) ax, ay, ad = x, y, -face local f, s, b = FUR[1], FUR[2], FUR[3] if pose == "sit" or pose == "lean" then aw = 10 local d = pose == "lean" and 1 or 0 part(0, d, 2, 3, f); part(3, d, 2, 3, f); part(0, 2 + d, 5, 4, f) part(1, 3 + d, 1, 1, EYE); part(3, 3 + d, 1, 1, EYE); part(0, 4 + d, 1, 1, PINK) part(3, 5, 6, 4, f); part(5, 4, 4, 5, f); part(2, 6, 2, 3, b) part(6, 4, 1, 2, s); part(8, 6, 1, 2, s) if pose == "lean" then part(0, 7, 2, 2, b) end if tail then part(9, 1, 1, 8, f) else part(9, 4, 1, 5, f) end elseif pose == "walk" then aw = 11 part(0, 0, 1, 2, f); part(2, 0, 1, 2, f); part(0, 1, 4, 4, f) part(1, 2, 1, 1, EYE); part(3, 2, 1, 1, EYE); part(0, 3, 1, 1, PINK) part(3, 2, 7, 3, f); part(5, 2, 1, 2, s); part(8, 2, 1, 2, s); part(10, 0, 1, 3, f) local ph = tail and 0 or 1 part(1 + ph, 5, 1, 2, f); part(4, 5, 1, 2, f); part(7 - ph, 5, 1, 2, f); part(9, 5, 1, 2, f) elseif pose == "air" then aw = 11 part(0, 1, 1, 1, f); part(2, 1, 1, 1, f); part(0, 2, 4, 3, f) part(1, 3, 1, 1, EYE); part(3, 3, 1, 1, EYE) part(3, 1, 6, 3, f); part(5, 1, 1, 2, s); part(0, 5, 3, 1, b); part(8, 4, 3, 1, f); part(8, 0, 3, 1, f) else aw = 8 part(0, 0, 2, 2, f); part(3, 0, 2, 2, f); part(0, 1, 5, 4, f) part(1, 2, 1, 1, EYE); part(3, 2, 1, 1, EYE); part(0, 3, 1, 1, PINK) part(1, 5, 7, 2, f); part(2, 5, 3, 2, b); part(7, 3, 1, 3, f) end end local function frow(x, y, w, a) local ix = floor(x) local f = x - ix blend_rect(ix + 1, y, w - 1, 1, 255, 255, 255, a) blend_rect(ix, y, 1, 1, 255, 255, 255, a * (1 - f)) blend_rect(ix + w, y, 1, 1, 255, 255, 255, a * f) end local KX, SX, SY = 22, 38, 21 function render() if not BG then build() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame / FPS * (0.4 + 0.2 * (cfg.speed or 3)) gfx.clip(0, 0, 34, H) for i = 1, 2 do local x = (i * 29 + t * (i == 1 and 1.6 or 1.1)) % (W + 40) - 20 local y = i == 1 and 6 or 16 frow(x + 3, y, 9, 0.9); frow(x, y + 1, 15, 0.9); frow(x + 2, y + 2, 11, 0.8) end gfx.clip() t = t % CYC if t < 8.6 then gfx.clip(0, 0, 52, H) if t < 3.2 then cat(56 - 18 * t / 3.2, 23, -1, "walk", floor(t * 5) % 2 == 0) else local lean = (t > 7.2 and t < 7.8) or t > 8.2 cat(SX, SY, -1, lean and "lean" or "sit", t > 6.6 and floor(t * 4) % 2 == 0) end gfx.clip() elseif t < 9.4 then local u = (t - 8.6) / 0.8 cat(SX + (KX + 5 - SX) * u, SY + (43 - SY) * u - 8 * 4 * u * (1 - u), -1, "air") end local ky = 37 if t >= 3.4 and t < 10.4 then local x, pose = KX, "stand" if t < 5.1 then x = -12 + (KX + 12) * (t - 3.4) / 1.7 pose = floor(t * 8) % 2 == 0 and "stride" or "together" elseif t >= 6.0 and t < 9.4 then pose = "reach" elseif t >= 9.4 then pose = "hold" end kid(x, ky, 1, pose) if t >= 9.4 then cat(x + 5, ky + 6, 1, "held") end elseif t >= 10.4 and t < 14.8 then local u = (t - 10.4) / 4.4 local x = KX - 36 * u local step = floor(t * 4) % 2 kid(x, ky + (step == 0 and 0 or -1), -1, step == 0 and "stride" or "together") cat(x - 3, ky + 6 + (step == 0 and 0 or -1), -1, "held") end end