info = { type = "image", title = "Tower dive", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A diver leaps off a tower, the crowd cheers", api = 33, } local tr = ({ sk = { ["Swimsuit"] = "Plavky" }, cs = { ["Swimsuit"] = "Plavky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "suit", label = T("Swimsuit"), type = "color", default = "#DE3036" }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, exp = math.floor, math.exp local hash32, umod = math.hash32, math.umod local CYC = 400 local WATER_Y = 46 local WALL = { 84, 110, 150 } local COL = { S = { 240, 178, 134 }, D = { 60, 38, 30 }, R = { 222, 48, 52 } } local SRC = { stand = { ".D.", ".S.", "SRS", "SRS", ".R.", ".R.", "S.S", "S.S" }, walk1 = { ".D.", ".S.", "SR.", ".RS", ".R.", ".R.", "S.S", "SS." }, walk2 = { ".D.", ".S.", ".RS", "SR.", ".R.", ".R.", "S.S", ".SS" }, climb1 = { ".D.", "SS.", "SR.", ".RS", ".R.", ".R.", "SS.", "S.S" }, climb2 = { ".D.", ".SS", ".RS", "SR.", ".R.", ".R.", ".SS", "S.S" }, crouch = { ".D.", ".S.", "SRS", ".R.", "S.S" }, stretch = { "S.S", "SDS", ".S.", ".R.", ".R.", ".R.", ".S.", ".S." }, arrow = { "SS", "SS", "RR", "RR", "RR", "SS", "DS", "SS" }, tuck1 = { "DSRR", "SSRR", "RRSS", "RRSS" }, tuck2 = { "RRDS", "RRSS", "SSRR", "SSRR" }, tuck3 = { "SSRR", "SSRR", "RRSD", "RRSS" }, tuck4 = { "RRSS", "RRSS", "DSRR", "SSRR" }, } local TUCK = { "tuck1", "tuck2", "tuck3", "tuck4" } local SPR = {} for name, rows in pairs(SRC) do local runs = {} for r = 1, #rows do local s, i = rows[r], 1 while i <= #s do local ch = s:sub(i, i) if ch ~= "." then local j = i while s:sub(j + 1, j + 1) == ch do j = j + 1 end runs[#runs + 1] = { r - 1, i - 1, j - i + 1, ch } i = j end i = i + 1 end end SPR[name] = { w = #rows[1], h = #rows, runs = runs } end local function span(x, y, w, c, a) local ix = floor(x) local f = x - ix if not a and f < 0.04 then rect(ix, y, w, 1, c[1], c[2], c[3]) return end a = a or 1 blend_rect(ix, y, 1, 1, c[1], c[2], c[3], a * (1 - f)) if w > 1 then if a == 1 then rect(ix + 1, y, w - 1, 1, c[1], c[2], c[3]) else blend_rect(ix + 1, y, w - 1, 1, c[1], c[2], c[3], a) end end blend_rect(ix + w, y, 1, 1, c[1], c[2], c[3], a * f) end local function put(name, cx, top, a, snap) local s = SPR[name] local x, y = cx - s.w / 2, floor(top + 0.5) if snap then x = floor(x + 0.5) end for i = 1, #s.runs do local r = s.runs[i] span(x + r[2], y + r[1], r[3], COL[r[4]], a) end return s.h end local SKY_T, SKY_B = { 100, 190, 245 }, { 176, 226, 250 } local CONC, STEEL, STEEL_L = { 214, 208, 196 }, { 84, 92, 110 }, { 190, 198, 210 } local TILE, GROUT = { 104, 184, 204 }, { 84, 150, 172 } local WAT_T, WAT_B = { 60, 190, 240 }, { 10, 96, 190 } local SHIRTS = { { 220, 60, 60 }, { 245, 205, 60 }, { 240, 240, 240 }, { 60, 170, 90 }, { 240, 140, 50 }, { 210, 70, 170 }, { 60, 110, 220 } } local HEADS = { COL.S, { 70, 44, 30 }, { 220, 190, 90 }, { 150, 80, 50 } } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function c3(c) return c[1], c[2], c[3] end local PEOPLE = {} for k = 0, 3 do local n = (k % 2 == 0) and 6 or 5 for i = 0, n - 1 do local h = hash32((k * 8 + i) * 0x9E3779B1) PEOPLE[#PEOPLE + 1] = { x = 40 + 2 * (k % 2) + 4 * i, y = 24 + 5 * k, h = umod(h, 1000), shirt = SHIRTS[umod(h >> 4, #SHIRTS) + 1], head = HEADS[umod(h >> 9, #HEADS) + 1], } end end local BG local function build_bg() for y = 0, WATER_Y - 1 do rect(0, y, 64, 1, mix(SKY_T, SKY_B, y / (WATER_Y - 1))) end rect(54 - 3, 8 - 4, 7, 9, 255, 236, 120) rect(54 - 4, 8 - 3, 9, 7, 255, 236, 120) for _, p in ipairs({ { 54, 1 }, { 54, 15 }, { 46, 8 }, { 62, 8 }, { 48, 2 }, { 60, 14 } }) do px(p[1], p[2], 255, 246, 190) end rect(12, 43, 28, 3, 40, 128, 70) rect(14, 41, 5, 2, 56, 150, 84); rect(22, 40, 7, 3, 56, 150, 84); rect(31, 41, 5, 2, 56, 150, 84) rect(15, 41, 2, 1, 96, 186, 108); rect(24, 40, 3, 1, 96, 186, 108) rect(0, WATER_Y, 12, 18, c3(TILE)); rect(40, WATER_Y, 24, 18, c3(TILE)) for y = WATER_Y + 3, 62, 4 do rect(0, y, 12, 1, c3(GROUT)); rect(40, y, 24, 1, c3(GROUT)) end for x = 3, 11, 4 do rect(x, WATER_Y, 1, 18, c3(GROUT)) end for x = 43, 63, 4 do rect(x, WATER_Y, 1, 18, c3(GROUT)) end rect(11, WATER_Y, 1, 18, 70, 140, 170); rect(40, WATER_Y, 1, 18, 70, 140, 170) for y = WATER_Y, 63 do rect(12, y, 28, 1, mix(WAT_T, WAT_B, (y - WATER_Y) / 17)) end rect(12, WATER_Y, 28, 1, 150, 225, 250) rect(0, 44, 12, 2, c3(CONC)); rect(0, 44, 12, 1, 232, 226, 214) rect(38, 44, 26, 2, c3(CONC)); rect(38, 44, 26, 1, 232, 226, 214) rect(1, 22, 2, 22, c3(STEEL)); rect(8, 22, 2, 22, c3(STEEL)) rect(1, 22, 1, 22, 130, 140, 160) rect(1, 28, 9, 1, c3(STEEL)); rect(1, 36, 9, 1, c3(STEEL)) rect(3, 22, 1, 22, c3(STEEL_L)); rect(7, 22, 1, 22, c3(STEEL_L)) for y = 24, 43, 3 do rect(4, y, 3, 1, 150, 158, 172) end rect(0, 20, 17, 1, 206, 212, 222); rect(0, 21, 17, 2, 96, 104, 122) rect(14, 20, 3, 1, 250, 210, 80) rect(0, 15, 1, 5, c3(STEEL_L)); rect(0, 15, 3, 1, c3(STEEL_L)) rect(38, 20, 26, 24, c3(WALL)) rect(38, 20, 2, 24, 120, 128, 142); rect(62, 20, 2, 24, 120, 128, 142) for i = 0, 8 do rect(38 + i * 3, 17, 3, 2, i % 2 == 0 and 220 or 244, i % 2 == 0 and 60 or 244, i % 2 == 0 and 60 or 244) end rect(38, 19, 26, 1, 70, 78, 96) for k = 0, 3 do rect(40, 24 + 5 * k + 4, 24, 1, 200, 200, 208) end rect(40, 43, 24, 1, 200, 200, 208) for _, p in ipairs(PEOPLE) do px(p.x + 1, p.y + 1, c3(p.head)) rect(p.x, p.y + 2, 3, 2, c3(p.shirt)) end BG = gfx.snapshot(0, 0, 64, 64) end local function cloud(x, y, v, off) local cx = (off + frame * v) % 90 - 20 local c = { 255, 255, 255 } span(cx + 2, y, 8, c, 0.8); span(cx, y + 1, 13, c, 0.8); span(cx + 3, y + 2, 9, c, 0.6) end local DROPS = {} for i = 1, 12 do DROPS[i] = { (i - 6.5) * 0.17, 1.5 + ((i * 7) % 5) * 0.25 } end local WHITE = { 236, 248, 255 } local function splash(xe, s) gfx.clip(12, 0, 28, WATER_Y + 18) if s < 8 then local h = floor(8 * (1 - s / 8) + 0.5) blend_rect(floor(xe) - 1, WATER_Y - h, 3, h, 236, 248, 255, 0.9) blend_rect(floor(xe) - 3, WATER_Y - h // 2, 7, h // 2, 236, 248, 255, 0.6) end if s < 24 then for i = 1, 12 do local d = DROPS[i] local y = WATER_Y - d[2] * s + 0.085 * s * s if y < WATER_Y then px(floor(xe + d[1] * s + 0.5), floor(y + 0.5), c3(WHITE)) end end end if s < 40 then span(xe - 5 - s * 0.1, WATER_Y, 10 + floor(s * 0.2), WHITE, 0.8 * (1 - s / 40)) end for i = 0, 2 do local a = s - 4 - 7 * i if a >= 0 and a < 45 then local r, al = 2 + a * 0.35, 0.8 * (1 - a / 45) span(xe - r - 3, WATER_Y, 4, WHITE, al); span(xe + r - 1, WATER_Y, 4, WHITE, al) span(xe - r - 1, WATER_Y + 1, 3, WHITE, al * 0.5); span(xe + r - 1, WATER_Y + 1, 3, WHITE, al * 0.5) end end for i = 1, 6 do local y = 52 + (i % 3) * 3 - s * 0.25 - i if s > 6 + i * 3 and y > WATER_Y + 1 then blend_rect(floor(xe + (i - 3.5) * 1.6), floor(y), 1, 1, 220, 245, 255, 0.7) end end gfx.clip() end local function crowd(t) for i, p in ipairs(PEOPLE) do local ts = 197 + (p.x - 40) local up = t >= ts and t < ts + 95 and not ((t // 10 + i) % 4 == 0 and i % 2 == 0) if not up then up = (frame + 37 * i) % 211 < 14 and i % 4 == 0 end if up then rect(p.x, p.y + 3, 1, 1, c3(WALL)); rect(p.x + 2, p.y + 3, 1, 1, c3(WALL)) rect(p.x, p.y, 1, 3, c3(p.shirt)); rect(p.x + 2, p.y, 1, 3, c3(p.shirt)) px(p.x, p.y - 1, c3(COL.S)); px(p.x + 2, p.y - 1, c3(COL.S)) end end end local function water_glints() gfx.clip(12, WATER_Y, 28, 18) for r = 0, 3 do local y = 49 + r * 4 for k = 0, 2 do local x = (k * 11 + r * 5 + frame * (r % 2 == 0 and 0.12 or -0.09)) % 32 - 4 span(12 + x, y, 4, { 150, 220, 250 }, 0.55) end end gfx.clip() end function on_settings() local c = cfg.suit or { r = 222, g = 48, b = 52 } COL.R = { c.r, c.g, c.b } end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, 64, 64) cloud(0, 5, 0.05, 20); cloud(0, 12, 0.03, 70) water_glints() local t = frame % CYC local xe = 14.5 + 0.43 * 32 if t < 30 then put((t // 6) % 2 == 0 and "walk1" or "walk2", -3 + t * 0.267, 36) elseif t < 110 then local k = (t - 30) // 10 put(k % 2 == 0 and "climb1" or "climb2", 5.5, 36 - 3 * k) elseif t < 150 then put((t // 6) % 2 == 0 and "walk1" or "walk2", 5 + (t - 110) * 0.2375, 12) elseif t < 175 then put("stand", 14.5, 12) elseif t < 185 then put("crouch", 14.5, 15) elseif t < 233 then local tau = t - 185 if tau < 32 then local yc = 15.5 - 0.9 * tau + 0.054 * tau * tau local name = tau < 9 and "stretch" or (tau < 21 and TUCK[floor((tau - 9) / 3.5) % 4 + 1] or "arrow") put(name, 14.5 + 0.43 * tau, yc - SPR[name].h / 2, nil, true) else local s = tau - 32 local yc = 42 + 14 * s / (s + 4) if s < 6 then gfx.clip(0, 0, 64, WATER_Y); put("arrow", xe, yc - 4, nil, true); gfx.clip() end if s < 16 then gfx.clip(12, WATER_Y, 28, 18) put("arrow", xe, yc - 4, 0.8 * (1 - s / 16), true) gfx.clip() end end end if t >= 217 and t < 217 + 70 then splash(xe, t - 217) end crowd(t) end