info = { type = "image", title = "Jet strike", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Arcade fighter over scrolling sea and clouds", api = 33, } local tr = ({ sk = { ["Terrain"] = "Terén", ["Sea"] = "More", ["Desert"] = "Púšť", ["Arctic"] = "Arktída", ["Explosions"] = "Výbuchy", ["Enemies"] = "Nepriatelia" }, cs = { ["Terrain"] = "Terén", ["Sea"] = "Moře", ["Desert"] = "Poušť", ["Arctic"] = "Arktida", ["Explosions"] = "Výbuchy", ["Enemies"] = "Nepřátelé" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "terrain", label = T("Terrain"), type = "int", default = "sea", opts = { keys = { "sea", "desert", "arctic" }, T("Sea"), T("Desert"), T("Arctic") } }, { key = "blast", label = T("Explosions"), type = "bool", default = true }, { key = "foes", label = T("Enemies"), type = "int", min = 1, max = 3, default = 2 }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local blit_rgb, blit_indexed, snapshot = gfx.blit_rgb, gfx.blit_indexed, gfx.snapshot local floor, sin, sqrt, min, max, abs = math.floor, math.sin, math.sqrt, math.min, math.max, math.abs local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local LOOP = 9600 local PY = 47 local TERR = { sea = { bg = { 14, 66, 150 }, w1 = { 46, 116, 200 }, w2 = { 10, 52, 126 }, ring = { 34, 148, 190 }, edge = { 226, 204, 140 }, top = { 64, 150, 72 }, tree = { 34, 104, 58 }, shade = { 6, 30, 80 } }, desert = { bg = { 206, 168, 98 }, w1 = { 228, 196, 126 }, w2 = { 184, 142, 82 }, ring = { 168, 124, 72 }, edge = { 218, 184, 128 }, top = { 98, 152, 78 }, tree = { 52, 108, 62 }, shade = { 120, 84, 40 } }, arctic = { bg = { 20, 52, 110 }, w1 = { 46, 96, 164 }, w2 = { 14, 38, 88 }, ring = { 120, 176, 224 }, edge = { 226, 240, 255 }, top = { 246, 250, 255 }, tree = { 178, 206, 236 }, shade = { 6, 20, 56 } }, } local TP = TERR.sea local PG, BUILT = {}, 0 local function sprite(rows, map) local out = {} for i = 1, #rows do out[i] = rows[i]:gsub(".", function(c) return string.char(map[c] or 0) end) end return table.concat(out) end local SMAP = { o = 1, G = 2, g = 3, r = 4, R = 5, B = 6, b = 7, y = 8 } local PLANE = sprite({ "......o......", ".....ogo.....", ".....ogo.....", "....ogGgo....", "....orBro....", "....orbro....", ".o..orbro..o.", "oGo.orrro.oGo", "oGGoorrrooGGo", "oGGGrrrrrGGGo", ".oGRrrrrrRGo.", "..oRrRRRrRo..", "...orRyRro...", "....oRRRo....", ".....ooo.....", }, SMAP) local PLANE_P = { 0, 0, 0, 20, 24, 36, 96, 104, 122, 170, 178, 192, 224, 44, 52, 150, 26, 40, 196, 240, 255, 70, 170, 240, 255, 220, 90 } local FOE = sprite({ ".o.....o.", "oGo.o.oGo", "oGGoGoGGo", ".oGGGGGo.", "..oGrGo..", "..oGGGo..", "...ogo...", "....o....", }, SMAP) local FOE_P = { { 0, 0, 0, 16, 40, 24, 70, 170, 90, 150, 230, 150, 255, 90, 70 }, { 0, 0, 0, 30, 20, 40, 130, 100, 170, 190, 170, 220, 255, 200, 70 }, } local ISLAND = { { 14, 22, 10, 7 }, { 48, 40, 8, 6 }, { 26, 70, 13, 9 }, { 54, 92, 7, 5 }, { 10, 108, 6, 4 } } local OY = 0 local function R(x, y, w, h, c) rect(x, y - OY, w, h, c[1], c[2], c[3]) end local function ellipse(cx, cy, rx, ry, c) for dy = -ry, ry do local y = cy + dy if y >= OY and y < OY + H then local half = floor(rx * sqrt(1 - (dy / ry) ^ 2) + 0.5) R(cx - half, y, 2 * half + 1, 1, c) end end end local function draw_page(k) OY = k * H rect(0, 0, W, H, TP.bg[1], TP.bg[2], TP.bg[3]) for i = 1, 44 do local h = hash32(i * 0x9E3779B1 + 5) local y = 1 + umod(h >> 8, 125) if y >= OY and y < OY + H then R(umod(h, 58), y, 3 + umod(h >> 16, 4), 1, (i % 2 == 0) and TP.w1 or TP.w2) end end for i = 1, #ISLAND do local a = ISLAND[i] ellipse(a[1], a[2], a[3] + 3, a[4] + 3, TP.ring) ellipse(a[1], a[2], a[3] + 1, a[4] + 1, TP.edge) ellipse(a[1], a[2], a[3] - 1, a[4] - 1, TP.top) for n = 1, a[3] do local h = hash32(i * 977 + n * 0x85EBCA6B) local dx, dy = umod(h, 2 * a[3] - 6) - a[3] + 3, umod(h >> 8, 2 * a[4] - 4) - a[4] + 2 if (dx * dx) / (a[3] * a[3]) + (dy * dy) / (a[4] * a[4]) < 0.55 and a[2] + dy >= OY and a[2] + dy < OY + H then R(a[1] + dx, a[2] + dy, 2, 2, TP.tree) end end end end local function ease(u) if u <= 0 then return 0 elseif u >= 1 then return 1 end return u * u * (3 - 2 * u) end local function pkey(k) return 10 + umod(hash32((k % 240) * 0x9E3779B1 + 77), 44) end local function plane_x(t) local k = floor(t / 40) return pkey(k) + (pkey(k + 1) - pkey(k)) * ease((t - 40 * k - 14) / 24) end local FIRE = 5 local function draw_bullets(t) for j = max(0, (t - 12) // FIRE), t // FIRE do local tf = j * FIRE local y = PY + 2 - FIRE * (t - tf) local stop = (tf - 40 * (tf // 40) < 10) and 20 or -4 if y > stop then local x = floor(plane_x(tf) + 0.5) rect(x - 4, y, 1, 3, 255, 244, 160); rect(x + 4, y, 1, 3, 255, 244, 160) end end end local function draw_boom(x, y, e) if e >= 16 then return end local r = 1 + floor(e * 0.3) local c1 = e < 3 and { 255, 255, 230 } or e < 7 and { 255, 226, 96 } or e < 11 and { 255, 130, 40 } or { 176, 50, 30 } rect(x - r + 1, y - r, 2 * r - 1, 2 * r + 1, c1[1], c1[2], c1[3]) rect(x - r, y - r + 1, 2 * r + 1, 2 * r - 1, c1[1], c1[2], c1[3]) if e >= 3 and r > 2 then local c2 = e < 7 and { 255, 255, 230 } or e < 11 and { 255, 226, 96 } or { 255, 130, 40 } local s = r - 2 rect(x - s + 1, y - s, 2 * s - 1, 2 * s + 1, c2[1], c2[2], c2[3]) rect(x - s, y - s + 1, 2 * s + 1, 2 * s - 1, c2[1], c2[2], c2[3]) end if e >= 2 then local d = e * 0.45 + 2 rect(x - floor(d), y - floor(d * 0.5) - 1, 1, 1, 255, 220, 120); rect(x + floor(d), y + floor(d * 0.5), 1, 1, 255, 220, 120) rect(x - floor(d * 0.5), y + floor(d), 1, 1, 255, 160, 60); rect(x + floor(d * 0.5), y - floor(d), 1, 1, 255, 160, 60) end end local OFF = { 4, 16, 28 } local FOES, BLAST = 2, true local function draw_foes(t) local kk = (t + 14) // 40 local td = 40 * kk + 10 local ax = pkey(kk) if t < td then local s = (td - t) / 24 blit_indexed(FOE, FOE_P[kk % 2 + 1], floor(ax + 10 * s * sin(s * 9) + 0.5) - 4, floor(18 - 26 * s + 0.5) - 3, 9, 8, 9, 8, true) elseif BLAST then draw_boom(ax, 18, t - td) end for k = max(0, (t - 86) // 40), t // 40 do for j = 1, FOES do local ts = 40 * k + OFF[j] local age = t - ts if age >= 0 and age < 58 then local mid = plane_x(ts + 46) local ex = min(58, max(6, mid + (mid < 32 and 1 or -1) * (17 + 5 * (j - 1)))) local y = -8 + 1.4 * age blit_indexed(FOE, FOE_P[(k + j) % 2 + 1], floor(ex + 3 * sin(age * 0.15 + j) + 0.5) - 4, floor(y) - 3, 9, 8, 9, 8, true) local tf = ts + 14 local y0 = -8 + 1.4 * 14 local xb = floor(ex + 3 * sin(14 * 0.15 + j) + 0.5) if age >= 14 and abs(plane_x(tf + (PY + 4 - y0) / 2.2) - xb) >= 10 then local by = floor(y0 + 2.2 * (age - 14)) if by < H then rect(xb, by, 2, 3, 255, 150, 50); rect(xb, by, 1, 1, 255, 236, 140) end end end end end end local CLOUD = { { 6, 20, 24 }, { 30, 70, 18 }, { 44, 110, 26 }, { 14, 40, 20 }, { 52, 130, 22 } } for i = 1, #CLOUD do local c = CLOUD[i] local rows = {} for r = 0, 5 do local u = (r - 2.5) / 3 local len = floor(c[3] * sqrt(1 - u * u) + 0.5) rows[r + 1] = { (c[3] - len) // 2 + (hash32(r * 31 + i) & 3) - 1, len, 0.9 - 0.3 * abs(u) } end c.rows = rows end local function draw_clouds(t) for i = 1, #CLOUD do local c = CLOUD[i] local y = (c[2] + 2 * t) % 150 - 30 if y > -8 and y < H then for r = 1, 6 do local q = c.rows[r] blend_rect(c[1] + q[1], y + r - 1, q[2], 1, 255, 255, 255, q[3]) end blend_rect(c[1] + 8, y + 14, c[3] - 8, 3, TP.shade[1], TP.shade[2], TP.shade[3], 0.22) end end end function on_settings() TP = TERR[cfg.terrain] or TERR.sea BLAST = cfg.blast ~= false FOES = cfg.foes or 2 BUILT = 0 end function render() if BUILT < 2 then draw_page(BUILT) BUILT = BUILT + 1 PG[BUILT] = snapshot(0, 0, W, H) end local t = frame % LOOP local s = t % 128 for k = 0, 1 do for _, y in ipairs({ s + 64 * k, s + 64 * k - 128 }) do if y > -H and y < H and PG[k + 1] then blit_rgb(PG[k + 1], 0, y, W, H) end end end draw_clouds(t) draw_foes(t) draw_bullets(t) local px = floor(plane_x(t) + 0.5) - 6 local sh = TP.shade blend_rect(px + 8, PY + 8, 3, 9, sh[1], sh[2], sh[3], 0.4) blend_rect(px + 5, PY + 14, 13, 3, sh[1], sh[2], sh[3], 0.4) blit_indexed(PLANE, PLANE_P, px, PY, 13, 15, 13, 15, true) rect(px + 6, PY + 15, 1, 2 + t % 2, 255, 190, 60) rect(px + 6, PY + 15, 1, 1, 255, 250, 200) end