info = { type = "image", title = "Noclip fall", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "Stickman falls through the floor to Backrooms", api = 33, } local STEP_HZ = 30 local FR = 0 local tr = ({ sk = { ["Walk time (s)"] = "Čas chôdze (s)", ["Glitch strength"] = "Sila poruchy" }, cs = { ["Walk time (s)"] = "Doba chůze (s)", ["Glitch strength"] = "Síla poruchy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "walk", label = T("Walk time (s)"), type = "int", min = 2, max = 8, default = 4 }, { key = "glitch", label = T("Glitch strength"), type = "int", min = 1, max = 3, default = 2 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt, abs, max, min = math.floor, math.sin, math.cos, math.sqrt, math.abs, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local T1, T2, T3, T4, T5, T6, T7, T8, CYC = 120, 156, 198, 208, 230, 260, 274, 374, 390 local GS = 2 function on_settings() local walk = (cfg.walk or 4) * 30 GS = cfg.glitch or 2 T1 = walk T2 = T1 + 36 T3 = T2 + 42 T4 = T3 + 10 T5 = T4 + 22 T6 = T5 + 30 T7 = T6 + 14 T8 = T7 + 100 CYC = T8 + 16 end local function line(x0, y0, x1, y1, r, g, b) x0, y0, x1, y1 = floor(x0 + 0.5), floor(y0 + 0.5), floor(x1 + 0.5), floor(y1 + 0.5) local dx, dy = abs(x1 - x0), -abs(y1 - y0) local sx, sy = x0 < x1 and 1 or -1, y0 < y1 and 1 or -1 local err = dx + dy for _ = 1, 80 do px(x0, y0, r, g, b) if x0 == x1 and y0 == y1 then break end local e2 = 2 * err if e2 >= dy then err = err + dy; x0 = x0 + sx end if e2 <= dx then err = err + dx; y0 = y0 + sy end end end local RX, RY = {}, {} for dy = -5, 5 do for dx = -5, 5 do local d = sqrt(dx * dx + dy * dy) if d >= 3.3 and d <= 4.4 then RX[#RX + 1] = dx; RY[#RY + 1] = dy end end end local INK = { 0, 0, 0 } local function figure(J, ed) local r, g, b = INK[1], INK[2], INK[3] local hx, hy = floor(J[1] + 0.5), floor(J[2] + 0.5) for i = 1, #RX do px(hx + RX[i], hy + RY[i], r, g, b) end line(J[1], J[2] + 4, J[5], J[6], r, g, b) line(J[3], J[4], J[7], J[8], r, g, b) line(J[3], J[4], J[9], J[10], r, g, b) line(J[5], J[6], J[11], J[12], r, g, b) line(J[5], J[6], J[13], J[14], r, g, b) px(hx + ed * 2 - 1, hy - 1, r, g, b) px(hx + ed * 2 + 1, hy - 1, r, g, b) end local function lerp(out, a, b, e) for i = 1, 14 do out[i] = a[i] + (b[i] - a[i]) * e end return out end local function smooth(e) return e * e * (3 - 2 * e) end local JW, JA, JB, JC, JD = {}, {}, {}, {}, {} local function pose_walk(fx, fy, ph) local sw, c = sin(ph) * 5, cos(ph) JW[1], JW[2] = fx, fy - 24 JW[3], JW[4] = fx, fy - 19 JW[5], JW[6] = fx, fy - 11 JW[7], JW[8] = fx - sw * 0.7, fy - 12 JW[9], JW[10] = fx + sw * 0.7, fy - 12 JW[11], JW[12] = fx + sw, fy - 2 * max(0, c) JW[13], JW[14] = fx - sw, fy - 2 * max(0, -c) return JW end local function pose_stand(J, fx, fy) J[1], J[2], J[3], J[4], J[5], J[6] = fx, fy - 24, fx, fy - 19, fx, fy - 11 J[7], J[8], J[9], J[10] = fx - 3, fy - 12, fx + 3, fy - 12 J[11], J[12], J[13], J[14] = fx - 3, fy, fx + 3, fy end local function pose_sit(J, fx, fy) J[1], J[2], J[3], J[4], J[5], J[6] = fx - 1, fy - 15, fx - 1, fy - 10, fx + 2, fy - 3 J[7], J[8], J[9], J[10] = fx + 4, fy - 7, fx + 5, fy - 5 J[11], J[12], J[13], J[14] = fx + 11, fy - 1, fx + 10, fy - 4 end local function pose_lie(J, fx, fy) J[1], J[2], J[3], J[4], J[5], J[6] = fx - 9, fy - 4, fx - 5, fy - 2, fx + 4, fy - 2 J[7], J[8], J[9], J[10] = fx - 3, fy - 9, fx - 9, fy - 10 J[11], J[12], J[13], J[14] = fx + 10, fy - 8, fx + 12, fy - 1 end pose_stand(JA, 0, 0); pose_sit(JB, 0, 0); pose_lie(JC, 0, 0) local function glitch(seed, s) local n = floor(s * GS * 0.7 + 0.5) local amp = 2 + floor(s * GS * 1.2) for i = 1, n do local h = hash32(seed * 977 + i * 7919) local y = umod(h, 58) local hh = 2 + umod(h >> 8, 7) if y + hh > H then hh = H - y end local dx = umod(h >> 12, 2 * amp + 1) - amp if dx == 0 then dx = amp end local snap = gfx.snapshot(0, y, W, hh) gfx.blit_rgb(snap, dx, y, W, hh) gfx.blit_rgb(snap, dx > 0 and dx - W or dx + W, y, W, hh) if i % 3 == 0 then blend_rect(0, y, W, 1, 255, 40, 255, 0.4) elseif i % 3 == 1 then blend_rect(0, y + hh - 1, W, 1, 40, 255, 255, 0.4) end end for i = 1, floor(s * 2) do local h = hash32(seed * 131 + i * 104729) px(umod(h, W), umod(h >> 8, H), 255, 255, 255) end end local function frect(xf, y, w, h, c) local xl = floor(xf) local xe = floor(xf + w) local cl, ce = 1 - (xf - xl), xf + w - xe if xe == xl then blend_rect(xl, y, 1, h, c[1], c[2], c[3], w); return end if cl > 0.96 then rect(xl, y, 1, h, c[1], c[2], c[3]) elseif cl > 0.04 then blend_rect(xl, y, 1, h, c[1], c[2], c[3], cl) end if xe - xl - 1 > 0 then rect(xl + 1, y, xe - xl - 1, h, c[1], c[2], c[3]) end if ce > 0.04 then blend_rect(xe, y, 1, h, c[1], c[2], c[3], ce) end end local SKY, CLOUD, SUN = { 70, 190, 255 }, { 255, 255, 255 }, { 255, 230, 60 } local HILL, HILL2 = { 44, 150, 84 }, { 32, 124, 70 } local GRASS, TUFT = { 70, 200, 60 }, { 30, 150, 40 } local ROAD, ROADE = { 214, 160, 100 }, { 160, 104, 56 } local STONE = { 150, 150, 160 } local TRUNK, LEAF = { 140, 84, 40 }, { 40, 170, 60 } local FY, FX = 56, 28 local function scene1(sc) rect(0, 0, W, 44, SKY[1], SKY[2], SKY[3]) rect(50, 5, 8, 8, SUN[1], SUN[2], SUN[3]); rect(49, 7, 10, 4, SUN[1], SUN[2], SUN[3]) rect(51, 4, 6, 10, SUN[1], SUN[2], SUN[3]) for i = 0, 1 do local x = (i * 34 - FR * 0.06 * (1 + i * 0.5)) % 90 - 20 local y = 8 + i * 12 frect(x + 3, y, 10, 3, CLOUD) frect(x, y + 2, 16, 3, CLOUD) end rect(0, 36, 22, 8, HILL2[1], HILL2[2], HILL2[3]); rect(4, 33, 12, 3, HILL2[1], HILL2[2], HILL2[3]) rect(18, 38, 30, 6, HILL[1], HILL[2], HILL[3]); rect(26, 35, 14, 3, HILL[1], HILL[2], HILL[3]) rect(44, 34, 20, 10, HILL2[1], HILL2[2], HILL2[3]); rect(50, 31, 10, 3, HILL2[1], HILL2[2], HILL2[3]) rect(0, 44, W, 8, GRASS[1], GRASS[2], GRASS[3]) rect(0, 52, W, 12, ROAD[1], ROAD[2], ROAD[3]) rect(0, 52, W, 1, ROADE[1], ROADE[2], ROADE[3]) for i = 0, 2 do local x = (i * 30 - sc * 0.7) % 96 - 16 frect(x + 3, 38, 2, 10, TRUNK) frect(x, 30, 8, 3, LEAF); frect(x - 1, 33, 10, 5, LEAF) end for i = 0, 4 do local x = floor((i * 19 - sc) % 100) - 16 rect(x, 46 + (i % 3) * 2, 1, 2, TUFT[1], TUFT[2], TUFT[3]); rect(x + 2, 45 + (i % 3) * 2, 1, 3, TUFT[1], TUFT[2], TUFT[3]) local s = floor((i * 23 + 7 - sc * 1.2) % 100) - 16 rect(s, 58 + (i % 3) * 2, 4, 2, STONE[1], STONE[2], STONE[3]) end end local WALLS = { { 232, 200, 52 }, { 214, 184, 44 } } local END_W, CEIL, FLOOR_A, FLOOR_B, FLOOR_C = { 238, 210, 70 }, { 248, 238, 192 }, { 212, 176, 108 }, { 198, 160, 90 }, { 184, 144, 74 } local R_BG = nil local LAMP_ON, LAMP_DEAD = { 255, 253, 228 }, { 196, 190, 156 } local R_A, R_B1, R_B2, R_CX, R_CY = 34, 20, 30, 32, 27 local function build_room() local c for x = 0, W - 1 do local dx = x < R_CX and (R_CX - 0.5 - x) or (x + 0.5 - R_CX) local k = dx / R_A local yt = floor(R_CY - R_B1 * k + 0.5) local yb = floor(R_CY + R_B2 * k + 0.5) if dx < 20 then yt, yb = 15, 45 end c = CEIL; rect(x, 0, 1, max(yt, 0), c[1], c[2], c[3]) local w = dx < 20 and END_W or (x < R_CX and WALLS[1] or WALLS[2]) rect(x, yt, 1, yb - yt, w[1], w[2], w[3]) if yb < 51 then c = FLOOR_A; rect(x, yb, 1, 51 - yb, c[1], c[2], c[3]) end if yb < 57 then c = FLOOR_B; rect(x, max(yb, 51), 1, 57 - max(yb, 51), c[1], c[2], c[3]) end c = FLOOR_C; rect(x, max(yb, 57), 1, H - max(yb, 57), c[1], c[2], c[3]) if dx >= 20 and yb - yt > 4 then rect(x, yb - 2, 1, 2, 132, 92, 28) end end rect(12, 43, 40, 2, 132, 92, 28) rect(36, 24, 9, 21, 124, 84, 26) rect(37, 25, 7, 20, 198, 142, 54) px(38, 36, 255, 238, 150) rect(15, 26, 9, 19, 124, 84, 26) rect(16, 27, 7, 18, 96, 70, 20) rect(18, 29, 3, 16, 120, 90, 28) rect(0, 51, W, 1, 150, 112, 44); rect(0, 57, W, 1, 142, 104, 40) R_BG = gfx.snapshot(0, 0, W, H) end local function room(lamp) if not R_BG then build_room() else gfx.blit_rgb(R_BG, 0, 0, W, H) end local lc = lamp and LAMP_ON or LAMP_DEAD for y = 3, 8 do local dx = 0.612 * (R_CY - y - 0.5) rect(floor(R_CX - dx + 0.5), y, floor(2 * dx + 0.5), 1, lc[1], lc[2], lc[3]) end for y = 11, 12 do local dx = 0.612 * (R_CY - y - 0.5) rect(floor(R_CX - dx + 0.5), y, floor(2 * dx + 0.5), 1, lc[1], lc[2], lc[3]) end end local function strength(t) if t < 8 then return 3 - t * 0.37 end if t >= T1 and t < T2 then return 1 + 2 * (t - T1) / (T2 - T1) end if t >= T2 and t < T3 then return 4 + 2 * (t - T2) / (T3 - T2) end if t >= T3 and t < T4 then return 6 - 6 * (t - T3) / (T4 - T3) end if t >= T8 then return 1 + 5 * (t - T8) / (CYC - T8) end return 0 end function render() FR = frame * STEP_HZ // gfx.FPS local t = FR % CYC local cyc = FR // CYC if t < T3 then local u = t < T2 and t or T2 local sc = u * 1.2 scene1(sc) local ph = u * 0.5 local J if t < T2 then J = pose_walk(FX, FY, ph) figure(J, 1) else local f = t - T2 local sink = 0.017 * f * f local rx = min(12, 3 + f * 0.4) rect(FX - rx, FY - 1, 2 * rx, 4, 60, 40, 8) rect(FX - rx + 1, FY, 2 * rx - 2, 2, 255, 222, 60) rect(FX - rx + 3, FY + 1, 2 * rx - 6, 1, 60, 40, 8) JW[1], JW[2] = FX, FY - 24 + sink JW[3], JW[4] = FX, FY - 19 + sink JW[5], JW[6] = FX, FY - 11 + sink local fl = sin(f * 0.9) * 3 JW[7], JW[8] = FX - 5 - fl, FY - 25 + sink JW[9], JW[10] = FX + 5 + fl, FY - 25 + sink JW[11], JW[12] = FX - 3, FY + sink JW[13], JW[14] = FX + 3, FY + sink gfx.clip(0, 0, W, FY + 1) figure(JW, 1) gfx.clip() end else room(not ((t * 7 + cyc) % 53 < 2)) local f if t >= T4 and t < T5 then f = (t - T4) / (T5 - T4) local y = -30 + (57 + 30) * f * f local fl = sin(t * 1.1) * 3 JW[1], JW[2] = 32, y - 24 JW[3], JW[4] = 32, y - 19 JW[5], JW[6] = 32, y - 11 JW[7], JW[8] = 26 - fl, y - 26 JW[9], JW[10] = 38 + fl, y - 26 JW[11], JW[12] = 27 + fl, y JW[13], JW[14] = 37 - fl, y figure(JW, 0) elseif t >= T5 and t < T8 then if t < T6 then pose_lie(JW, 32, 57) if (t // 6) % 2 == 0 then JW[8] = JW[8] - 1; JW[10] = JW[10] + 1 end figure(JW, 1) elseif t < T7 then local e = (t - T6) / (T7 - T6) pose_lie(JC, 32, 57); pose_sit(JB, 32, 57); pose_stand(JA, 32, 57) if e < 0.5 then lerp(JW, JC, JB, smooth(e * 2)) else lerp(JW, JB, JA, smooth(e * 2 - 1)) end figure(JW, 0) else local q = t - T7 pose_stand(JW, 32, 57) local ed = 0 if q < 24 then ed = -1 elseif q < 34 then ed = 0 elseif q < 64 then ed = 1 elseif q < 72 then ed = 0 else ed = -1 end JW[1] = JW[1] + ed if q % 40 > 30 then JW[8] = JW[8] - 1 end figure(JW, ed) end end end local s = strength(t) if s > 0 then glitch(FR, s) end end