info = { type = "image", title = "Goose cottage", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A goose family waddles out of a cottage", api = 33, } local tr = ({ sk = { ["Goslings"] = "Húsatá", ["Roof colour"] = "Farba strechy" }, cs = { ["Goslings"] = "Housata", ["Roof colour"] = "Barva střechy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "kids", label = T("Goslings"), type = "int", min = 0, max = 4, default = 3 }, { key = "roof", label = T("Roof colour"), type = "color", default = "#C4502E" }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local W, H = gfx.W, gfx.H local SKY = { 150, 202, 240 } local CLOUD = { 246, 248, 255 } local HILL = { 72, 142, 98 } local GRASS = { 106, 180, 64 } local TUFT = { 74, 146, 46 } local PATH = { 218, 190, 130 } local WALL = { 172, 108, 54 } local SEAM = { 128, 76, 36 } local GABLE = { 200, 140, 76 } local BEAM = { 104, 62, 32 } local DOOR = { 62, 120, 156 } local DOOR_D = { 42, 90, 124 } local KNOB = { 250, 212, 90 } local ROOM = { 100, 64, 42 } local FLOORC = { 142, 100, 62 } local PANE = { 252, 216, 120 } local STONE = { 160, 152, 142 } local STONE_D = { 120, 112, 104 } local FENCE = { 200, 156, 104 } local LEAF = { 50, 124, 60 } local LEAF_L = { 96, 170, 74 } local TRUNK = { 116, 76, 42 } local APPLE = { 226, 44, 40 } local BLOOM = { 240, 72, 86 } local DAISY = { 250, 250, 236 } local SMOKE = { 224, 226, 232 } local function c3(c) return c[1], c[2], c[3] end local RR, RG, RB, DR, DG, DB = 196, 80, 46, 141, 58, 33 local NK = 3 local BG = nil local CX = 19 local function window(x, y) rect(x, y, 7, 7, c3(BEAM)) rect(x + 1, y + 1, 5, 5, c3(PANE)) rect(x + 3, y + 1, 1, 5, c3(BEAM)) rect(x + 1, y + 3, 5, 1, c3(BEAM)) rect(x - 1, y + 7, 9, 3, c3(TRUNK)) for k = 0, 3 do px(x + k * 2, y + 7, c3(BLOOM)) end for k = 0, 2 do px(x + 1 + k * 2, y + 7, c3(LEAF_L)) end end local TUFTS = { 2,58, 9,52, 27,61, 36,58, 41,62, 58,56, 31,49, 62,50, 6,47, 45,47 } local FLOWERS = { 25,59, 39,60, 60,59, 4,50, 33,47 } local function build_bg() rect(0, 0, W, H, c3(SKY)) for x = 0, W - 1 do local top = floor(33 + 3 * sin(x * 0.09 + 1) + 2 * sin(x * 0.23) + 0.5) rect(x, top, 1, 44 - top, c3(HILL)) end rect(0, 44, W, H - 44, c3(GRASS)) rect(12, 51, W - 12, 5, c3(PATH)) rect(11, 52, 1, 3, c3(PATH)) for i = 1, #TUFTS, 2 do local x, y = TUFTS[i], TUFTS[i + 1] rect(x, y, 1, 2, c3(TUFT)); px(x + 1, y + 1, c3(TUFT)); px(x - 1, y, c3(TUFT)) end for i = 1, #FLOWERS, 2 do px(FLOWERS[i], FLOWERS[i + 1], c3(i % 4 == 1 and DAISY or BLOOM)) end rect(52, 26, 3, 18, c3(TRUNK)) for y = 7, 27 do local d = y - 17 local hw = floor(sqrt(100 - d * d) + 0.5) rect(53 - hw, y, 2 * hw + 1, 1, c3(LEAF)) end for y = 9, 17 do local d = y - 13 local hw = floor(sqrt(20 - d * d) + 0.3) rect(50 - hw, y, 2 * hw + 1, 1, c3(LEAF_L)) end px(47, 20, c3(APPLE)); px(57, 12, c3(APPLE)); px(55, 23, c3(APPLE)) px(60, 18, c3(APPLE)); px(50, 24, c3(APPLE)); px(56, 17, c3(APPLE)) for x = 38, W - 1, 4 do rect(x, 39, 2, 10, c3(FENCE)) end rect(37, 41, W - 37, 1, c3(FENCE)); rect(37, 45, W - 37, 1, c3(FENCE)) rect(27, 9, 4, 14, c3(STONE)) rect(26, 8, 6, 2, c3(STONE_D)) px(28, 12, c3(STONE_D)); px(29, 15, c3(STONE_D)) for y = 12, 30 do local hw = 2 + (y - 12) rect(CX - hw, y, 2 * hw + 1, 1, RR, RG, RB) if hw > 4 then rect(CX - hw + 4, y, 2 * hw - 7, 1, c3(GABLE)) end px(CX - hw, y, DR, DG, DB); px(CX + hw, y, DR, DG, DB) if y % 3 == 0 then rect(CX - hw + 1, y, 3, 1, DR, DG, DB) rect(CX + hw - 3, y, 3, 1, DR, DG, DB) end end rect(CX - 2, 19, 5, 5, c3(BEAM)) rect(CX - 1, 20, 3, 3, c3(PANE)) rect(CX, 20, 1, 3, c3(BEAM)) rect(3, 31, 33, 18, c3(WALL)) for y = 34, 46, 4 do rect(4, y, 31, 1, c3(SEAM)) end rect(3, 31, 1, 18, c3(BEAM)); rect(35, 31, 1, 18, c3(BEAM)) rect(3, 30, 33, 1, c3(BEAM)) window(6, 35); window(26, 35) rect(14, 34, 11, 15, c3(BEAM)) rect(15, 35, 9, 14, c3(ROOM)) rect(15, 46, 9, 3, c3(FLOORC)) rect(13, 49, 13, 2, c3(STONE)) rect(13, 50, 13, 1, c3(STONE_D)) BG = gfx.snapshot(0, 0, W, H) end local PR, PG, PB = {}, {}, {} local function pal(i, r, g, b) PR[i], PG[i], PB[i] = r, g, b end pal(1, 246, 246, 240) pal(2, 194, 204, 218) pal(3, 244, 146, 36) pal(4, 30, 30, 40) pal(5, 252, 218, 72) pal(6, 224, 172, 40) local G_BODY = { 6,0,1,1, 6,5,8,1, 7,0,9,1, 8,0,9,1, 9,1,9,1, 10,2,8,1, 8,2,6,2, 9,3,6,2 } local G_HEAD = { 0,7,9,1, 1,6,9,1, 2,6,9,1, 3,6,8,1, 4,6,7,1, 5,6,7,1, 1,8,8,4, 1,10,11,3, 2,10,10,3 } local G_HONK = { 0,7,9,1, 1,6,9,1, 2,6,9,1, 3,6,8,1, 4,6,7,1, 5,6,7,1, 1,8,8,4, 0,10,11,3, 2,10,11,3 } local G_PECK = { 5,8,9,1, 6,9,10,1, 7,10,11,1, 8,10,12,1, 9,11,12,1, 8,11,11,4, 9,13,13,3, 10,12,13,3 } local G_LEGS = { { 11,4,4,3, 11,6,6,3, 12,3,4,3, 12,6,7,3 }, { 11,3,3,3, 11,7,7,3, 12,2,3,3, 12,7,8,3 }, } local K_BODY = { 2,0,0,5, 2,2,5,5, 3,0,5,5, 4,1,4,5, 0,3,5,5, 1,3,5,5, 3,1,3,6, 0,4,4,4, 1,6,6,3 } local K_LEGS = { { 5,2,2,3, 5,4,4,3 }, { 5,1,1,3, 5,3,3,3 } } local function segs(S, ix, f, top, dir, sw) local rx = ix + (f >= 0.5 and 1 or 0) for i = 1, #S, 4 do local y, a, b, c = top + S[i], S[i + 1], S[i + 2], S[i + 3] if dir < 0 then a, b = sw - b, sw - a end local r, g, bl = PR[c], PG[c], PB[c] if c == 1 or c == 5 then if f > 0 then if b > a then rect(ix + a + 1, y, b - a, 1, r, g, bl) end blend(ix + a, y, r, g, bl, 1 - f) blend(ix + b + 1, y, r, g, bl, f) else rect(ix + a, y, b - a + 1, 1, r, g, bl) end else rect(rx + a, y, b - a + 1, 1, r, g, bl) end end end local function goose(x, feet, dir, head, legs) local ix = floor(x) local f, top = x - ix, feet - 12 segs(G_BODY, ix, f, top, dir, 13) segs(head, ix, f, top, dir, 13) segs(G_LEGS[legs + 1], ix, f, top, dir, 13) end local function gosling(x, feet, dir, legs) local ix = floor(x) local f, top = x - ix, feet - 5 segs(K_BODY, ix, f, top, dir, 6) segs(K_LEGS[legs + 1], ix, f, top, dir, 6) end local STEP_HZ = 30 local PER, PH, V = 420, 410, 0.4 local function walk_start(k) return 68 + 28 * k end local function walker(k, u) local ws = walk_start(k) if u < 4 then return nil end local x0 = k == 0 and 14 or 16 if u < ws - 12 then local dir = 1 if k == 0 and u >= 16 and u < 52 then dir = ((u - 16) // 12) % 2 == 0 and -1 or 1 end return x0, 48, dir, 0, true elseif u < ws then local s = (u - ws + 12) // 3 + 1 return x0, 48 + s, 1, s % 2, false end local d = u - ws local x = x0 + d * V if x > W then return nil end return x, 52, 1, (d // 6) % 2, false end local function leaf_w(u, uc) if u < 4 then return 9 elseif u < 8 then return 6 elseif u < 12 then return 3 end if u < uc then return 2 end local c = u - uc if c < 4 then return 3 elseif c < 8 then return 6 end return 9 end local function draw_walker(k, u) local x, feet, dir, legs = walker(k, u) if not x then return end if k == 0 then goose(x, feet, dir, G_HEAD, legs) else gosling(x, feet, dir, legs) end end local function draw_door(w) rect(15, 35, w, 14, c3(DOOR)) if w == 9 then rect(17, 35, 1, 14, c3(DOOR_D)); rect(20, 35, 1, 14, c3(DOOR_D)) px(22, 42, c3(KNOB)) else rect(15 + w - 1, 35, 1, 14, c3(DOOR_D)) end end local CL_BIG, CL_SMALL = { 0,3,8, 1,1,11, 2,0,13 }, { 0,2,5, 1,0,8 } local CLOUDS = { { CL_BIG, 1, 6, 0.10 }, { CL_SMALL, 4, 40, 0.07 } } local function srow(x, y, a, b, r, g, bl) local ix = floor(x) local f = x - ix if b > a then rect(ix + a + 1, y, b - a, 1, r, g, bl) end blend(ix + a, y, r, g, bl, 1 - f) if f > 0 then blend(ix + b + 1, y, r, g, bl, f) end end local function draw_clouds(t) gfx.clip(0, 0, W, 7) for i = 1, #CLOUDS do local c = CLOUDS[i] local S = c[1] local x = (c[3] + t * c[4]) % (W + 16) - 16 for j = 1, #S, 3 do srow(x, c[2] + S[j], S[j + 1], S[j + 2], c3(CLOUD)) end end gfx.clip() end local function draw_smoke(t) for j = 0, 2 do local a = (t + j * 40) % 120 local x, y = 28 + a * 0.05, 7 - a * 0.1 local s = 1 + a // 40 local al = a < 100 and 0.7 or 0.7 * (120 - a) / 20 local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy local r, g, b = c3(SMOKE) blend_rect(ix, iy, s, s, r, g, b, al * (1 - fx) * (1 - fy)) blend_rect(ix + 1, iy, s, s, r, g, b, al * fx * (1 - fy)) blend_rect(ix, iy + 1, s, s, r, g, b, al * (1 - fx) * fy) blend_rect(ix + 1, iy + 1, s, s, r, g, b, al * fx * fy) end end function on_settings() local c = cfg.roof or { r = 196, g = 80, b = 46 } RR, RG, RB = c.r, c.g, c.b DR, DG, DB = floor(c.r * 0.72), floor(c.g * 0.72), floor(c.b * 0.72) NK = cfg.kids or 3 BG = nil end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // gfx.FPS draw_clouds(t) draw_smoke(t) local u = (t + PH) % PER for k = NK, 0, -1 do local x, _, _, _, inside = walker(k, u) if x and inside then draw_walker(k, u) end end draw_door(leaf_w(u, walk_start(NK) + 6)) for k = NK, 0, -1 do local x, _, _, _, inside = walker(k, u) if x and not inside then draw_walker(k, u) end end local p = t % 96 goose(0, 62, 1, ((p >= 40 and p < 50) or (p >= 58 and p < 68)) and G_PECK or G_HEAD, 0) local q = (t + 30) % 150 goose(49, 63, -1, (q < 6 or (q >= 10 and q < 16)) and G_HONK or G_HEAD, 0) end