info = { type = "image", title = "Platform train", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Tiny commuters board a train that brakes in", api = 33, } local tr = ({ sk = { ["Stripe colour"] = "Farba pruhu", ["Commuters"] = "Cestujúci", ["Clock"] = "Hodiny" }, cs = { ["Stripe colour"] = "Barva pruhu", ["Commuters"] = "Cestující", ["Clock"] = "Hodiny" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "stripe", label = T("Stripe colour"), type = "color", default = "#2F6FD0" }, { key = "people", label = T("Commuters"), type = "int", min = 1, max = 4, default = 4 }, { key = "clock", label = T("Clock"), type = "bool", default = true }, } 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, TX0, LEN, DW = 720, -20, 134, 10 local FLOOR = 51 local BG = nil local function build_bg() rect(0, 0, W, 6, 30, 36, 68) rect(4, 3, 10, 1, 255, 250, 214); rect(36, 3, 12, 1, 255, 250, 214) rect(0, 6, W, 39, 234, 226, 192) for y = 11, 41, 6 do rect(0, y, W, 1, 222, 213, 178) end for x = 7, 63, 8 do rect(x, 6, 1, 39, 224, 216, 182) end rect(0, 28, W, 2, 46, 100, 176) rect(2, 7, 16, 6, 222, 196, 92); rect(4, 9, 5, 2, 60, 52, 40); rect(11, 9, 2, 2, 60, 52, 40); rect(14, 8, 2, 4, 200, 60, 50) rect(38, 7, 14, 6, 222, 196, 92); rect(40, 9, 4, 2, 60, 52, 40); rect(46, 9, 4, 2, 60, 52, 40) rect(30, 16, 5, 8, 214, 84, 70); rect(54, 16, 6, 8, 70, 130, 190) rect(0, 41, W, 4, 62, 66, 82) rect(0, 45, W, 6, 58, 56, 64) rect(0, 46, W, 1, 150, 152, 164); rect(0, 49, W, 1, 150, 152, 164) for x = 1, 63, 6 do rect(x, 47, 2, 2, 96, 72, 54) end rect(0, FLOOR, W, 13, 150, 152, 164) rect(0, FLOOR, W, 2, 238, 198, 44) rect(0, 58, W, 6, 138, 140, 154) for x = 5, 63, 11 do rect(x, FLOOR + 2, 1, 11, 128, 130, 144) end rect(51, 53, 13, 4, 118, 76, 48) rect(51, 57, 13, 2, 156, 102, 62) rect(52, 59, 1, 2, 70, 46, 32); rect(62, 59, 1, 2, 70, 46, 32) BG = gfx.snapshot(0, 0, W, H) end local function door(x, g) rect(x, 23, DW, 27, 172, 180, 194) if g == 0 then rect(x + 2, 24, 6, 6, 40, 80, 92) else rect(x + (DW - g) // 2, 23, g, 27, 224, 198, 138) end end local function train(tx, g, sr, sg, sb) local L = floor(tx) rect(L, 13, LEN, 3, 112, 124, 146) rect(L, 16, LEN, 34, 190, 198, 210) rect(L, 16, LEN, 2, 216, 222, 232) rect(L, 23, LEN, 8, 40, 76, 88) rect(L, 41, LEN, 2, sr, sg, sb) rect(L, 46, LEN, 4, 112, 120, 134) for k = 0, 5 do local x = L + 4 + 22 * k if x > -DW and x < W then rect(x + 15, 23, 2, 8, 190, 198, 210) door(x, g) end end rect(L + 42, 16, 1, 34, 70, 76, 88); rect(L + 86, 16, 1, 34, 70, 76, 88) end local function frect(x, y, w, h, c, a) local x0 = floor(x) local f = x - x0 if f < 0.05 and a >= 1 then rect(x0, y, w, h, c[1], c[2], c[3]) elseif f < 0.05 then blend_rect(x0, y, w, h, c[1], c[2], c[3], a) else blend_rect(x0, y, 1, h, c[1], c[2], c[3], (1 - f) * a) if w > 1 then blend_rect(x0 + 1, y, w - 1, h, c[1], c[2], c[3], a) end blend_rect(x0 + w, y, 1, h, c[1], c[2], c[3], f * a) end end local PB1 = { { 54, 34, 24 }, { 240, 192, 152 }, { 214, 72, 62 }, { 176, 52, 46 }, { 40, 50, 92 } } local PA1 = { { 36, 30, 30 }, { 150, 104, 76 }, { 244, 204, 56 }, { 206, 164, 36 }, { 60, 60, 74 } } local PB2 = { { 206, 176, 96 }, { 240, 196, 160 }, { 66, 170, 124 }, { 44, 130, 94 }, { 70, 70, 112 } } local PA2 = { { 90, 50, 40 }, { 224, 172, 136 }, { 156, 94, 204 }, { 120, 68, 164 }, { 44, 44, 56 } } local PS = { { 176, 178, 190 }, { 236, 190, 150 }, { 70, 124, 206 }, { 50, 94, 168 }, { 52, 52, 70 } } local WATCH = { 255, 255, 255 } local function person(x, fy, P, mode, ph, a) frect(x + 1, fy - 10, 3, 1, P[1], a) frect(x + 1, fy - 9, 3, 2, P[2], a) frect(x + 1, fy - 7, 3, 4, P[3], a) frect(x, fy - 7, 1, 3, P[4], a) frect(x + 4, fy - 7, 1, 3, P[4], a) local lh, rh = 3, 3 if mode == "walk" then if ph % 2 == 0 then lh = 2 else rh = 2 end elseif mode == "tap" then if ph % 2 == 0 then rh = 2 end elseif mode == "watch" then frect(x + 4, fy - 9, 1, 2, P[2], a) frect(x + 4, fy - 8, 1, 1, WATCH, a) end if mode == "sit" then frect(x + 1, fy - 3, 4, 1, P[5], a) frect(x + 4, fy - 2, 1, 2, P[5], a) else frect(x + 1, fy - lh, 1, lh, P[5], a) frect(x + 3, fy - rh, 1, rh, P[5], a) end end local function seg(c, a, b) if c <= a then return 0 elseif c >= b then return 1 end return (c - a) / (b - a) end local function lerp(a, b, u) return a + (b - a) * u end local function round(v) return floor(v + 0.5) end local function boarder(P, sx, a0, a1, a2, n0, n1, c, off, watch) if c < a0 then person(sx, 58, P, (watch and c > 28 and c < 78) and "watch" or "tap", c // 12 + off, 1) elseif c < a1 then person(sx, round(lerp(58, FLOOR, seg(c, a0, a1))), P, "walk", c // 6, 1) elseif c < a2 then local u = seg(c, a1, a2) person(sx, round(lerp(FLOOR, FLOOR - 2, u)), P, "stand", 0, 1 - u) elseif c >= n0 then if c < n1 then local x = lerp(64, sx, seg(c, n0, n1)) local d = x - sx person(x, d >= 8 and 62 or round(58 + d / 2), P, "walk", c // 6, 1) else person(sx, 58, P, (watch and c > 28 and c < 78) and "watch" or "tap", c // 12 + off, 1) end end end local function alighter(P, dx, a0, a1, a2, x1, c) if c < a0 or c >= a2 then return end if c < a0 + 18 then person(dx, 50, P, "stand", 0, seg(c, a0, a0 + 18)) elseif c < a1 then person(dx, round(lerp(50, 62, seg(c, a0 + 18, a1))), P, "walk", c // 6, 1) else person(lerp(dx, x1, seg(c, a1, a2)), 62, P, "walk", c // 6, 1) end end local function clock_face(cx, cy, s) rect(cx - 4, cy - 5, 9, 1, 30, 34, 52); rect(cx - 4, cy + 5, 9, 1, 30, 34, 52) rect(cx - 5, cy - 4, 1, 9, 30, 34, 52); rect(cx + 5, cy - 4, 1, 9, 30, 34, 52) rect(cx - 4, cy - 4, 9, 9, 246, 244, 232) px(cx, cy - 4, 30, 34, 52); px(cx, cy + 4, 30, 34, 52); px(cx - 4, cy, 30, 34, 52); px(cx + 4, cy, 30, 34, 52) local am, ah = (s % 60) * 0.10472, (300 + s * 0.1) * 0.017453 for k = 1, 3 do px(round(cx + k * sin(am)), round(cy - k * cos(am)), 30, 34, 52) end for k = 1, 2 do px(round(cx + k * sin(ah)), round(cy - k * cos(ah)), 200, 40, 40) end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local c = (frame + 240) % CYC local sc = cfg.stripe or { r = 47, g = 111, b = 208 } local n = cfg.people or 4 local tx if c >= 60 and c < 260 then tx = TX0 + 84 * (1 - seg(c, 60, 260)) ^ 2 elseif c >= 260 and c < 490 then tx = TX0 elseif c >= 490 and c < 620 then tx = TX0 - 130 * seg(c, 490, 620) ^ 2 end if tx then local g = 0 if c < 420 then g = floor(6 * seg(c, 270, 300) + 0.5) else g = floor(6 * (1 - seg(c, 420, 450)) + 0.5) end train(tx, g, sc.r, sc.g, sc.b) end rect(20, 0, 5, 56, 40, 88, 162); rect(20, 0, 2, 56, 64, 116, 188); rect(23, 0, 2, 56, 26, 66, 130) rect(19, 55, 7, 3, 26, 58, 112) if cfg.clock ~= false then clock_face(22, 8, frame // FPS) end person(54, 60, PS, "sit", 0, 1) if n >= 1 then boarder(PB1, 9, 330, 355, 373, 540, 685, c, 0, false) end if n >= 2 then alighter(PA1, 31, 298, 341, 445, -8, c) end if n >= 3 then boarder(PB2, 31, 360, 385, 403, 560, 665, c, 1, true) end if n >= 4 then alighter(PA2, 53, 304, 347, 410, 72, c) end end