info = { type = "image", title = "Slalom skier", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Skier carves through gates and jumps a bump", api = 33, } local tr = ({ sk = { ["Suit"] = "Kombinéza", ["Snowfall"] = "Sneženie", ["Orange"] = "Oranžová", ["Magenta"] = "Purpurová", ["Green"] = "Zelená", ["Yellow"] = "Žltá" }, cs = { ["Suit"] = "Kombinéza", ["Snowfall"] = "Sněžení", ["Orange"] = "Oranžová", ["Magenta"] = "Purpurová", ["Green"] = "Zelená", ["Yellow"] = "Žlutá" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "suit", label = T("Suit"), type = "int", default = "orange", opts = { keys = { "orange", "magenta", "green", "yellow" }, T("Orange"), T("Magenta"), T("Green"), T("Yellow") } }, { key = "snow", label = T("Snowfall"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, abs = math.floor, math.sin, math.abs local hash32, umod = math.hash32, math.umod local char, concat = string.char, table.concat local SUITS = { orange = { { 255, 130, 20 }, { 255, 186, 100 }, { 190, 80, 10 } }, magenta = { { 220, 40, 150 }, { 250, 120, 200 }, { 150, 20, 100 } }, green = { { 36, 184, 96 }, { 120, 232, 160 }, { 20, 120, 60 } }, yellow = { { 250, 206, 30 }, { 255, 238, 130 }, { 190, 146, 10 } }, } local SNOW = { 238, 243, 250 } local SHADE = { 176, 194, 226 } local SY, SX = 27, 32 local GAP, JUMP = 72, 360 local JIT = { 1, -2, 2, 0, -1, 2, -2, 1 } local function c3(c) return c[1], c[2], c[3] end local S = SUITS.orange local FLAKES = true local function gate_x(k) return ((k % 2 == 0) and 10 or -10) + JIT[k % 8 + 1] end local function course(d) local k = floor((d - 36) / GAP) local t = (d - 36) / GAP - k t = t * t * (3 - 2 * t) local a = gate_x(k) return a + (gate_x(k + 1) - a) * t end local function spruce(tiers, trunk) local rows, w = {}, 2 * (tiers[#tiers][#tiers[#tiers]]) + 1 local c = (w + 1) // 2 for _, tier in ipairs(tiers) do for i, hw in ipairs(tier) do local row = {} for x = 1, w do local dx = x - c local v = 0 if abs(dx) <= hw then v = dx < 0 and 3 or dx == 0 and 2 or 1 end if i == 1 and abs(dx) < hw + 1 and v ~= 0 and hw > 0 then v = 4 end if i == 1 and hw == 0 then v = 4 end row[x] = char(v) end rows[#rows + 1] = concat(row) end end for _ = 1, trunk do local row = {} for x = 1, w do row[x] = char(abs(x - c) <= 0 and 5 or 0) end rows[#rows + 1] = concat(row) end return concat(rows), w, #rows end local TREE_PAL = { 0, 0, 0, 28, 86, 62, 38, 120, 82, 60, 156, 100, 246, 250, 255, 96, 64, 40 } local BIG, BW, BH = spruce({ { 0, 1, 2 }, { 1, 2, 3 }, { 2, 3, 4 } }, 2) local SMALL, SW, SH = spruce({ { 0, 1, 2 }, { 1, 2, 3 } }, 2) local function tree(x, y, big) local w, h = big and BW or SW, big and BH or SH blend_rect(x + w // 2 + 1, y - 2, w // 2 + 3, 2, SHADE[1], SHADE[2], SHADE[3], 0.55) gfx.blit_indexed(big and BIG or SMALL, TREE_PAL, x - w // 2, y - h, w, h, w, h, true) end function on_settings() S = SUITS[cfg.suit] or SUITS.orange FLAKES = cfg.snow ~= false end local function skier(sx, y, p, air) local tx = p == 0 and 0 or (p > 0 and 1 or -1) * (abs(p) == 2 and 2 or 1) * (air and 0 or 1) local slope = air and 0 or p * 0.34 for r = 0, 6 do local o = floor(slope * r + 0.5) rect(sx - 3 + o, y + r, 1, 1, 36, 38, 54) rect(sx + 2 + o, y + r, 1, 1, 36, 38, 54) end rect(sx - 3 + floor(slope * 6 + 0.5), y + 6, 1, 1, c3(S[1])) rect(sx + 2 + floor(slope * 6 + 0.5), y + 6, 1, 1, c3(S[1])) rect(sx - 3 + tx // 2, y - 3, 2, 4, 36, 44, 84); rect(sx + 1 + tx // 2, y - 3, 2, 4, 28, 34, 70) local ty = air and 1 or 0 rect(sx - 3 + tx, y - 9 + ty, 6, 6, c3(S[1])) rect(sx - 3 + tx, y - 9 + ty, 2, 2, c3(S[2])) rect(sx + 1 + tx, y - 8 + ty, 2, 5, c3(S[3])) rect(sx - 3 + tx, y - 5 + ty, 6, 1, 40, 40, 60) rect(sx - 2 + tx, y - 13 + ty, 4, 4, 236, 238, 246) rect(sx - 2 + tx, y - 11 + ty, 4, 1, 30, 34, 60); px(sx - 2 + tx, y - 11 + ty, 120, 200, 255) rect(sx - 2 + tx, y - 13 + ty, 4, 1, c3(S[2])) if air then px(sx - 4 + tx, y - 9, c3(S[1])); px(sx - 5 + tx, y - 10, 210, 210, 220) px(sx + 3 + tx, y - 9, c3(S[3])); px(sx + 4 + tx, y - 10, 210, 210, 220) else px(sx - 4 + tx, y - 8, c3(S[1])); px(sx - 4 + tx, y - 7, c3(S[1])) px(sx + 3 + tx, y - 8, c3(S[3])); px(sx + 3 + tx, y - 7, c3(S[3])) local po = p == 0 and 0 or (p > 0 and 1 or -1) for r = 0, 5 do px(sx - 5 + tx - floor(r * 0.3) + po, y - 6 + r, 205, 208, 220) px(sx + 4 + tx + floor(r * 0.3) + po, y - 6 + r, 205, 208, 220) end end end local function pose(d) local vx = (course(d + 3) - course(d - 3)) / 6 if vx < -0.3 then return -2 elseif vx < -0.1 then return -1 elseif vx > 0.3 then return 2 elseif vx > 0.1 then return 1 end return 0 end local function gate(cx, dy, k) local blue = k % 2 == 0 local r, g, b = 220, 40, 50 if blue then r, g, b = 36, 90, 220 end local y = SY + dy for _, off in ipairs({ -8, 8 }) do local x = cx + off blend_rect(x + 1, y - 1, 3, 1, SHADE[1], SHADE[2], SHADE[3], 0.6) rect(x, y - 8, 1, 8, 90, 96, 120) rect(x + (off < 0 and 1 or -2), y - 8, 2, 2, r, g, b) px(x, y - 8, r, g, b) end end function render() local D = frame local camx = floor(course(D - 16) + 0.5) local cx0 = SX - camx rect(0, 0, 64, 64, SNOW[1], SNOW[2], SNOW[3]) for dj = floor((D - 34) / 10), floor((D + 40) / 10) do for ci = floor((camx - 34) / 12), floor((camx + 34) / 12) do local h = hash32(dj * 7919 + ci * 104729) if h & 3 < 2 then local x = cx0 + ci * 12 + umod(h >> 2, 10) local y = SY + dj * 10 + umod(h >> 6, 8) - D if (h >> 9) & 1 == 0 then blend_rect(x, y, 3, 1, SHADE[1], SHADE[2], SHADE[3], 0.45) else blend_rect(x, y + 1, 3, 1, SHADE[1], SHADE[2], SHADE[3], 0.4) rect(x, y, 3, 1, 253, 254, 255) end end end end local jm = floor((D - 72 + 14) / JUMP) local Dj = jm * JUMP + 72 for m = jm, jm + 1 do local dj = m * JUMP + 72 local y = SY + dj - D if y > -3 and y < 66 then local x0 = cx0 + floor(course(dj)) - 14 blend_rect(x0 + 2, y - 1, 24, 1, 255, 255, 255, 0.9) rect(x0 + 2, y - 1, 24, 1, 252, 254, 255) blend_rect(x0, y, 28, 3, SHADE[1], SHADE[2], SHADE[3], 0.6) blend_rect(x0 + 3, y + 3, 22, 1, SHADE[1], SHADE[2], SHADE[3], 0.3) end end for y = 0, SY + 2 do local dd = D + y - SY local x = cx0 + floor(course(dd) + 0.5) blend_rect(x - 3, y, 1, 1, SHADE[1], SHADE[2], SHADE[3], 0.9) blend_rect(x + 2, y, 1, 1, SHADE[1], SHADE[2], SHADE[3], 0.9) end for tj = floor((D - 36) / 13), floor((D + 44) / 13) do for side = -1, 1, 2 do local h = hash32(tj * 0x9E3779B1 + side * 0x85EBCA6B) if h & 3 ~= 0 then local x = cx0 + side * (20 + umod(h >> 3, 20)) local y = SY + tj * 13 + umod(h >> 9, 10) - D tree(x, y, (h >> 14) & 1 == 0) end end end for k = floor((D - 36 - 30) / GAP), floor((D - 36 + 44) / GAP) do gate(cx0 + gate_x(k), 36 + k * GAP - D, k) end for i = 0, 7 do local age = i * 3 local db = D - age local p = pose(db) if abs(p) == 2 and (db - Dj) ~= 0 then local xw = course(db) - (p > 0 and 4 or -4) - (p > 0 and 1 or -1) * age * 0.12 local a = 0.75 * (1 - age / 24) blend_rect(floor(cx0 + xw), floor(SY + 6 - age * 0.35 + db - D), 2 + (i < 3 and 1 or 0), 2, 214, 226, 246, a) end end local tj = (D - (Dj - 8)) / 30 local air = tj >= 0 and tj <= 1 local lift = air and floor(4 * tj * (1 - tj) * 7 + 0.5) or 0 local sx = SX + floor(course(D) - course(D - 16) + 0.5) if air then blend_rect(sx - 3, SY + 1, 7, 2, SHADE[1], SHADE[2], SHADE[3], 0.7 - lift * 0.05) else blend_rect(sx - 3, SY + 6, 8, 2, SHADE[1], SHADE[2], SHADE[3], 0.5) end skier(sx, SY - lift, air and 0 or pose(D), air) if FLAKES then for i = 1, 14 do local h = hash32(i * 0xC2B2AE35) local v = 0.4 + umod(h >> 4, 40) / 100 local x = (umod(h, 80) + frame * (0.1 + umod(h >> 10, 20) / 100)) % 70 - 3 local y = (umod(h >> 14, 70) - frame * v) % 70 - 3 local iy = floor(y) local f = y - iy local ix = floor(x) blend_rect(ix, iy, 1, 1, 150, 176, 220, 0.85 * (1 - f)) blend_rect(ix, iy + 1, 1, 1, 150, 176, 220, 0.85 * f) end end end