info = { type = "image", title = "Glitch runner", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "An RGB block runner sprints and glitches", api = 33, } local STEP_HZ = 30 local FR = 0 local tr = ({ sk = { ["Palette"] = "Paleta", ["Fire"] = "Oheň", ["Ice"] = "Ľad", ["Neon"] = "Neón", ["Speed"] = "Rýchlosť", ["Glitch"] = "Porucha" }, cs = { ["Palette"] = "Paleta", ["Fire"] = "Oheň", ["Ice"] = "Led", ["Speed"] = "Rychlost", ["Glitch"] = "Porucha" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "pal", label = T("Palette"), type = "int", default = 0, opts = { T("RGB"), T("Fire"), T("Ice"), T("Neon") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "glitch", label = T("Glitch"), type = "int", min = 0, max = 10, default = 4 }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sin, cos, abs, max = math.floor, math.sin, math.cos, math.abs, math.max local hash32 = math.hash32 local byte, char = string.byte, string.char local W, H = gfx.W, gfx.H local TAU = 6.2831853 local PALS = { [0] = { { 64, 120, 255 }, { 255, 48, 64 }, { 255, 200, 40 }, { 255, 255, 255 } }, [1] = { { 200, 30, 90 }, { 255, 80, 24 }, { 255, 176, 20 }, { 255, 244, 150 } }, [2] = { { 120, 110, 255 }, { 60, 210, 255 }, { 40, 255, 200 }, { 232, 250, 255 } }, [3] = { { 150, 70, 255 }, { 255, 40, 200 }, { 0, 240, 220 }, { 255, 240, 40 } }, } local COL, TRL, GND1, GND2 = {}, {}, {}, {} local function set_pal(k) COL = PALS[k] or PALS[0] for i = 1, 4 do local c = COL[i] TRL[i] = { c[1] // 2, c[2] // 2, c[3] // 2 } end local a, b = COL[2], COL[1] GND1 = { a[1] * 9 // 16, a[2] * 9 // 16, a[3] * 9 // 16 } GND2 = { b[1] * 7 // 16, b[2] * 7 // 16, b[3] * 7 // 16 } end set_pal(0) local A, GL = 12, 4 function on_settings() set_pal(cfg.pal or 0) A = 6 + 2 * (cfg.speed or 3) GL = cfg.glitch or 4 end local NP = 32 local POSE = {} local HX, HY = 34, 32 local BR1, BR2, BRT = { 0, 0 }, { 0, 0, 1, 0 }, { -1, 0, 0, 0, 1, 0 } local HEADB = {} for cy = -2, 2 do for cx = -2, 2 do if cx * cx + cy * cy <= 5 then HEADB[#HEADB + 1] = cx; HEADB[#HEADB + 1] = cy end end end local function build_pose(i) local X, Y, P, seen = {}, {}, {}, {} local function mark(gx, gy, part) local k = (gy + 40) * 80 + gx + 40 local j = seen[k] if j then P[j] = part else j = #X + 1; X[j], Y[j], P[j] = gx, gy, part; seen[k] = j end end local function seg(ax, ay, bx, by, part, br) local n = floor(max(abs(bx - ax), abs(by - ay)) / 1.5) + 1 for s = 0, n do local t = s / n local gx, gy = floor((ax + (bx - ax) * t) / 2), floor((ay + (by - ay) * t) / 2) for b = 1, #br, 2 do mark(gx + br[b], gy + br[b + 1], part) end end end local p = i / NP local bob = -2 * abs(sin(p * TAU)) local nx, ny = 4, bob - 16 local function leg(ph, part) local th = 0.5 * sin(ph * TAU) local c = cos((ph - 0.95) * TAU) local kn = 0.15 + 1.3 * (c > 0 and c or 0) local kx, ky = 11 * sin(th), bob + 11 * cos(th) local sa = th - kn local fx, fy = kx + 11 * sin(sa), ky + 11 * cos(sa) seg(0, bob, kx, ky, part, BR2) seg(kx, ky, fx, fy, part, BR2) seg(fx, fy, fx + 4 * cos(sa), fy - 4 * sin(sa), part, BR1) end local function arm(ph, part) local ua = -0.8 * sin(ph * TAU) local sx, sy = nx - 1, ny + 2 local ex, ey = sx + 8 * sin(ua), sy + 8 * cos(ua) seg(sx, sy, ex, ey, part, BR2) seg(ex, ey, ex + 7 * sin(ua + 1.5), ey + 7 * cos(ua + 1.5), part, BR1) end leg(p + 0.5, 1); arm(p + 0.5, 1) seg(0, bob, nx, ny, 2, BRT) local hx, hy = floor((nx + 3) / 2), floor((ny - 5) / 2) for b = 1, #HEADB, 2 do mark(hx + HEADB[b], hy + HEADB[b + 1], 2) end mark(hx + 1, hy - 1, 4) leg(p, 3); arm(p, 3) local buf = {} for j = 1, #X do buf[j] = char(X[j] + 64, Y[j] + 64, P[j]) end local ps = table.concat(buf) POSE[i] = ps return ps end local function pose(i) return POSE[i] or build_pose(i) end local GS = {} local function draw(ps, ox, cols, keep, k, shift) local b4, b3 = FR // 4, FR // 3 for j = 1, #ps, 3 do local cx, cy, part = byte(ps, j, j + 2) cx, cy = cx - 64, cy - 64 if not keep or (cx * 5 + cy * 3 + k * 7 + b3 * 11) % 10 < keep then local m = (cx * 7 + cy * 13 + b4 * 5) % 11 local c = cols[part] if m == 0 then c = cols[4] elseif m == 5 then c = cols[part % 3 + 1] end local x = ox + cx * 2 if shift then x = x + (GS[cy // 3] or 0) end rect(x, HY + cy * 2, 2, 2, c[1], c[2], c[3]) end end end local function c3g(c) return c[1], c[2], c[3] end function render() FR = frame * STEP_HZ // gfx.FPS gfx.clear(0, 0, 0) local idx = (FR * A // 8) % NP local v = A * 0.16 local s = (FR % 1200) * v local o1, o2 = floor(s) % 8, floor(s * 1.5) % 12 for x = -o1, W - 1, 8 do rect(x, 56, 5, 1, c3g(GND1)) end for x = -o2, W - 1, 12 do rect(x, 60, 7, 1, c3g(GND2)) end for j = 1, 5 do local h = hash32(j * 0x9E3779B1) & 0x7FFF local x = floor((h % 96 - s * 2) % 96) - 16 rect(x, 8 + j * 8 + h % 5, 6 + h % 7, 1, c3g(j % 2 == 0 and GND2 or GND1)) end for k = 3, 1, -1 do draw(pose((idx - 3 * k) % NP), HX - 9 * k, TRL, 7 - 2 * k, k, false) end local b5 = FR // 5 local gh = hash32(b5 * 0x9E3779B1) & 0x7FFF local active = gh % 100 < GL * 3 local ps = pose(idx) if active then for band = -6, 5 do local h = hash32((band + 50) * 0x85EBCA6B + b5 * 0x27D4EB2F) & 0x7FFF GS[band] = (h % 4 == 0) and ((h >> 2) % 7 - 3) * 2 or 0 end for j = 1, #ps, 6 do local cx, cy = byte(ps, j, j + 1) local x, y = HX + (cx - 64) * 2, HY + (cy - 64) * 2 blend_rect(x - 3, y, 2, 2, 255, 0, 60, 0.55) blend_rect(x + 3, y, 2, 2, 0, 220, 255, 0.55) end for n = 1, 5 do local h = hash32(b5 * 0x632BE5AB + n * 0x9E3779B1) & 0x7FFF local c = COL[(h >> 12) % 4 + 1] rect(8 + h % 52, 6 + (h >> 6) % 50, 2 + ((h >> 11) & 1) * 2, 2, c[1], c[2], c[3]) end end draw(ps, HX, COL, nil, 0, active) end