info = { type = "image", title = "Goal kick", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "Striker scores, keeper dives, the net bulges", api = 33, } local tr = ({ sk = { ["Kit colour"] = "Farba dresu", ["Camera flashes"] = "Blesky foto" }, cs = { ["Kit colour"] = "Barva dresu", ["Camera flashes"] = "Blesky foto" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "kit", label = T("Kit colour"), type = "color", default = "#D62832" }, { key = "flashes", label = T("Camera flashes"), type = "bool", default = true }, } local rect, px, blend_rect, blit = gfx.rect, gfx.px, gfx.blend_rect, gfx.blit_indexed local floor, sin, cos, sqrt, exp = math.floor, math.sin, math.cos, math.sqrt, math.exp local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local CYCLE = 156 local function make(w, h, f) local g = {} for i = 1, w * h do g[i] = 0 end local function R(x, y, rw, rh, c) for yy = y, y + rh - 1 do for xx = x, x + rw - 1 do if xx >= 0 and xx < w and yy >= 0 and yy < h then g[yy * w + xx + 1] = c end end end end local function L(x0, y0, x1, y1, c, th) local n = math.max(math.abs(x1 - x0), math.abs(y1 - y0)) for i = 0, n do local t = n == 0 and 0 or i / n R(floor(x0 + (x1 - x0) * t + 0.5), floor(y0 + (y1 - y0) * t + 0.5), th, th, c) end end f(R, L) local rows = {} for y = 0, h - 1 do rows[y + 1] = string.char(table.unpack(g, y * w + 1, y * w + w)) end return table.concat(rows) end local function flip(s, w) local rows = {} for i = 1, #s, w do rows[#rows + 1] = s:sub(i, i + w - 1):reverse() end return table.concat(rows) end local FW, FH = 11, 13 local function head(R, y) R(3, y, 4, 4, 2); R(3, y, 4, 2, 1); R(3, y + 2, 1, 1, 1) end local function torso(R, y, n) R(2, y, 5, n, 3); R(6, y, 1, n, 4) end local DW, DH, LW_, LH_ = 14, 7, 14, 4 local STAND, RUN_A, RUN_B, KICK, CHEER, CROUCH, DIVE, LIE, S, NET local function init_poses() STAND = make(FW, FH, function(R, L) R(2, 10, 2, 2, 6); R(5, 10, 2, 2, 6); R(2, 12, 3, 1, 7); R(5, 12, 3, 1, 7); R(2, 8, 5, 2, 5) torso(R, 4, 4) R(1, 4, 1, 2, 3); R(1, 6, 1, 1, 2); R(1, 7, 1, 1, 8); R(7, 4, 1, 2, 3); R(7, 6, 1, 1, 2); R(7, 7, 1, 1, 8) head(R, 0) end) RUN_A = make(FW, FH, function(R, L) L(5, 10, 7, 11, 6, 2); R(7, 12, 3, 1, 7); L(3, 10, 1, 11, 6, 2); R(0, 11, 2, 1, 7); R(2, 8, 5, 2, 5) torso(R, 4, 4) L(7, 5, 9, 6, 3, 1); R(9, 6, 1, 1, 8); L(1, 5, 0, 7, 3, 1); R(0, 8, 1, 1, 8) head(R, 0) end) RUN_B = make(FW, FH, function(R, L) R(3, 10, 2, 2, 6); R(2, 12, 3, 1, 7); L(5, 9, 8, 10, 6, 2); R(8, 10, 2, 1, 7); R(2, 8, 5, 2, 5) torso(R, 4, 4) L(7, 5, 8, 7, 3, 1); R(8, 8, 1, 1, 8); L(1, 5, 0, 5, 3, 1); R(0, 4, 1, 1, 8) head(R, 0) end) end local function init_more() KICK = make(FW, FH, function(R, L) R(2, 10, 2, 2, 6); R(1, 12, 3, 1, 7); L(5, 9, 8, 10, 6, 2); R(9, 10, 2, 2, 7); R(2, 8, 5, 2, 5) torso(R, 4, 4) L(7, 5, 9, 4, 3, 1); R(9, 3, 1, 1, 8); L(1, 5, 0, 6, 3, 1); R(0, 7, 1, 1, 8) head(R, 0) end) CHEER = make(FW, FH, function(R, L) R(2, 10, 2, 2, 6); R(5, 10, 2, 2, 6); R(2, 12, 3, 1, 7); R(5, 12, 3, 1, 7); R(2, 8, 5, 2, 5) torso(R, 4, 4) R(1, 1, 1, 4, 3); R(1, 0, 1, 1, 8); R(7, 1, 1, 4, 3); R(7, 0, 1, 1, 8) head(R, 0) end) CROUCH = make(FW, FH, function(R, L) R(1, 12, 3, 1, 7); R(5, 12, 3, 1, 7); R(2, 11, 2, 1, 6); R(5, 11, 2, 1, 6); R(2, 9, 5, 2, 5) torso(R, 6, 3) L(7, 7, 9, 8, 3, 1); R(9, 8, 2, 1, 8); R(1, 7, 1, 2, 3); R(0, 9, 1, 1, 8) head(R, 2) end) DIVE = make(DW, DH, function(R, L) R(0, 3, 2, 2, 6); R(0, 2, 1, 3, 7); R(2, 2, 2, 4, 5) R(4, 2, 6, 4, 3); R(4, 5, 6, 1, 4) L(9, 2, 12, 0, 3, 1); R(12, 0, 2, 1, 8); R(9, 5, 4, 1, 3); R(13, 5, 1, 1, 8) R(10, 2, 4, 4, 2); R(10, 2, 3, 2, 1) end) LIE = make(LW_, LH_, function(R, L) R(0, 0, 2, 3, 6); R(0, 0, 1, 3, 7); R(2, 0, 2, 3, 5); R(4, 0, 6, 3, 3); R(4, 2, 6, 1, 4) R(10, 0, 4, 3, 2); R(10, 0, 2, 1, 1); R(8, 3, 4, 1, 2) end) S = { stand = flip(STAND, FW), crouch = flip(CROUCH, FW), dive = flip(DIVE, DW), lie = flip(LIE, LW_), walk_a = RUN_A, walk_b = RUN_B, run_a = flip(RUN_A, FW), run_b = flip(RUN_B, FW), } end local NPH = 6 local BALL = {} local function init_ball(k0, k1) for k = k0, k1 do local a = k * (6.28318 / 5) / NPH local cells = {} for y = 0, 7 do for x = 0, 7 do local dx, dy = x + 0.5 - 4, y + 0.5 - 4 local d = sqrt(dx * dx + dy * dy) local v = 0 if d <= 4.1 then v = d > 3.2 and 2 or 1 local cx, cy = 1.1 * cos(a), 1.1 * sin(a) if (dx - cx) ^ 2 + (dy - cy) ^ 2 < 1.7 then v = 2 end for j = 0, 4 do local px_, py_ = 3.0 * cos(a + j * 1.2566 + 0.6), 3.0 * sin(a + j * 1.2566 + 0.6) if (dx - px_) ^ 2 + (dy - py_) ^ 2 < 1.2 then v = 2 end end end cells[#cells + 1] = v end end BALL[k] = string.char(table.unpack(cells)) end end local BALL_PAL = { 0, 0, 0, 250, 250, 250, 28, 28, 34 } local function init_net() local n = {} for y = 0, 21 do for x = 0, 11 do n[#n + 1] = (y % 4 == 1 or x % 4 == 1) and 1 or 0 end end NET = string.char(table.unpack(n)) end local INITS = { init_poses, init_more, function() init_ball(0, 2) end, function() init_ball(3, 5) end, init_net } local NI = 0 local NET_PAL = { 0, 0, 0, 190, 204, 216 } local KICK_PAL, KEEP_PAL = {}, { 0, 0, 0, 34, 26, 24, 210, 160, 120, 250, 140, 30, 190, 100, 20, 34, 34, 44, 34, 34, 44, 20, 20, 26, 250, 250, 250 } local FLASH = true function on_settings() local c = cfg.kit or { r = 214, g = 40, b = 50 } KICK_PAL = { 0, 0, 0, 60, 40, 30, 240, 190, 150, c.r, c.g, c.b, c.r * 7 // 10, c.g * 7 // 10, c.b * 7 // 10, 245, 245, 250, c.r, c.g, c.b, 30, 30, 36, 240, 190, 150 } FLASH = cfg.flashes ~= false end local function lerp(a, b, t) return floor(a + (b - a) * t + 0.5) end local function scene() for y = 0, 21 do rect(0, y, W, 1, lerp(60, 150, y / 21), lerp(150, 208, y / 21), lerp(230, 250, y / 21)) end blend_rect(6, 7, 16, 2, 255, 255, 255, 0.55); blend_rect(8, 5, 10, 2, 255, 255, 255, 0.55) blend_rect(38, 12, 14, 2, 255, 255, 255, 0.45); blend_rect(41, 10, 8, 2, 255, 255, 255, 0.45) rect(0, 22, W, 2, 30, 34, 52); rect(0, 24, W, 18, 60, 66, 104) local CROWD = { { 230, 80, 80 }, { 240, 220, 90 }, { 90, 150, 240 }, { 250, 250, 250 }, { 36, 40, 66 }, { 150, 90, 60 } } for i = 1, 150 do local h = hash32(i * 0x9E3779B1) local c = CROWD[umod(h >> 16, 6) + 1] px(umod(h, W), 24 + umod(h >> 8, 18), c[1], c[2], c[3]) end local ADS = { { 220, 60, 60 }, { 250, 250, 250 }, { 40, 90, 200 }, { 250, 200, 40 } } for i = 0, 7 do local c = ADS[i % 4 + 1] rect(i * 8, 42, 8, 4, c[1], c[2], c[3]); rect(i * 8, 42, 8, 1, 255, 255, 255) end rect(0, 46, W, 6, 46, 138, 58); rect(0, 52, W, 6, 58, 154, 70); rect(0, 58, W, 6, 46, 138, 58) rect(0, 46, W, 1, 220, 238, 222) rect(48, 36, 12, 22, 22, 50, 46); rect(46, 34, 2, 24, 240, 244, 248); rect(46, 34, 16, 2, 240, 244, 248); rect(60, 34, 2, 24, 240, 244, 248) end local BG = nil local SPOT_X, SPOT_Y = 25, 54 local HIT = 61 local function ball_at(t) if t < 36 then return SPOT_X, SPOT_Y, 0 end if t < HIT then local s = (t - 36) / 30 return SPOT_X + 40 * s, SPOT_Y - 50.9 * s + 46.3 * s * s, (t - 36) * 1 end if t < 76 then local u = (t - HIT) / 15 return 58.3 - 6.3 * u, 44.1 + 9.9 * u * u, (t - 36) * 1 end if t < 101 then local u = (t - 76) / 25 local hgt, a, b = 4, 76, 88 if t >= 96 then hgt, a, b = 0.7, 96, 101 elseif t >= 88 then hgt, a, b = 1.8, 88, 96 end local v = (t - a) / (b - a) return 52 - 27 * u, SPOT_Y - hgt * 4 * v * (1 - v), 100 - (t - 76) * 1 end return SPOT_X, SPOT_Y, 0 end local function draw_sprite(s, pal, x, y, w, h) blit(s, pal, x, y, w, h, w, h, true) end function render() if not BG then scene() BG = gfx.snapshot(0, 0, W, H) else gfx.blit_rgb(BG, 0, 0, W, H) end if NI < #INITS then NI = NI + 1 INITS[NI]() return end local t = frame % CYCLE if FLASH then for i = 1, (t >= HIT and t < 105) and 5 or 2 do local h = hash32((frame // 2) * 0x2545F491 + i * 0x9E3779B1) px(umod(h, W), 24 + umod(h >> 8, 18), 255, 255, 255) end end local kx, pose, ky = 12, STAND, 45 local pal = KICK_PAL if t < 36 then kx = 12 - (36 - t) pose = t < 33 and ((t // 3) % 2 == 0 and RUN_A or RUN_B) or KICK elseif t < 42 then pose = KICK elseif t < 66 then pose = STAND elseif t < 120 then pose = CHEER local u = ((t - 66) % 22) / 22 ky = 45 - floor(16 * u * (1 - u) + 0.5) else kx = 12 - (t - 120) pose = (t // 3) % 2 == 0 and S.run_a or S.run_b end blend_rect(kx + 1, 58, 9, 1, 0, 0, 0, 0.3) draw_sprite(pose, pal, kx, ky, FW, FH) local kp if t < 38 or t >= 128 then kp = { S.stand, 50, 45, FW, FH } elseif t < 44 then kp = { S.crouch, 50, 45, FW, FH } elseif t < 66 then local u = (t - 44) / 22 kp = { S.dive, floor(47 - 3 * u + 0.5), floor(51 - 20 * u * (1 - u) + 0.5), DW, DH } elseif t < 96 then kp = { S.lie, 44, 53, LW_, LH_ } elseif t < 104 then kp = { S.crouch, 46, 45, FW, FH } else kp = { (t // 3) % 2 == 0 and S.walk_a or S.walk_b, 46 + (t - 104) // 6, 45, FW, FH } end blend_rect(kp[2] + 1, 58, 9, 1, 0, 0, 0, 0.3) draw_sprite(kp[1], KEEP_PAL, kp[2], kp[3], kp[4], kp[5]) local bx, by, spin = ball_at(t) blend_rect(floor(bx) - 2, 58, 5, 1, 0, 0, 0, 0.3) draw_sprite(BALL[floor(spin) % NPH], BALL_PAL, floor(bx - 4 + 0.5), floor(by - 4 + 0.5), 8, 8) local tau = t - HIT local amp = tau >= 0 and 2.5 * exp(-tau / 10) * cos(tau * 0.45) or 0 if amp > 0.35 or amp < -0.35 then for r = 0, 20, 2 do local shape = 1 - math.abs(r + 1 - 8) / 10 local off = shape > 0 and floor(amp * shape + 0.5) or 0 blit(NET:sub(r * 12 + 1, (r + 2) * 12), NET_PAL, 48 + off, 36 + r, 12, 2, 12, 2, true) end else blit(NET, NET_PAL, 48, 36, 12, 22, 12, 22, true) end end