info = { type = "image", title = "Liftoff", category = "space", author = "BRRRO", version = "1.0", license = "MIT", desc = "A rocket climbing through the clouds", api = 33, } local px, rect, blend = gfx.px, gfx.rect, gfx.blend local floor, sin, fmod = math.floor, math.sin, math.fmod local hash32, schar, concat, unpack = math.hash32, string.char, table.concat, table.unpack local W, H = gfx.W, gfx.H local SKY = { { 44, 104, 190 }, { 62, 130, 214 }, { 92, 158, 228 } } local CLOUD, CLOUD_D = { 244, 248, 255 }, { 196, 210, 232 } local SMOKE = { 226, 226, 232 } local FLAME = { { 255, 250, 210 }, { 255, 210, 90 }, { 255, 140, 30 }, { 226, 70, 20 } } local R_W, R_H = 15, 24 local ROCKET = { "......krk......", "......krk......", ".....krrrk.....", ".....krrrk.....", "....krrrrrk....", "....krrrrrk....", "....kwwwwwk....", "....kwvvvwk....", "....kwvvvwk....", "....kwvvvwk....", "....kwwwwwk....", "....krrrrrk....", "....krrrrrk....", "...krwwwwwrk...", "...krwwwwwrk...", "..krrwwwwwrrk..", "..krrwwwwwrrk..", ".krrrwwwwwrrrk.", ".krrrwwwwwrrrk.", "..kkkwwwwwkkk..", "....kdddddk....", "....kdddddk....", ".....kdddk.....", "......kkk......", } local R_IX = { k = 1, w = 2, r = 3, v = 4, d = 5 } local R_PAL = { 0, 0, 0, 40, 44, 60, 238, 242, 250, 220, 60, 50, 120, 200, 255, 120, 126, 142 } local R_SPR do local rows, row = {}, {} for j = 1, R_H do for i = 1, R_W do row[i] = R_IX[ROCKET[j]:sub(i, i)] or 0 end rows[j] = schar(unpack(row, 1, R_W)) end R_SPR = concat(rows) end local R_X, R_Y = (W - R_W) // 2, 9 local N_CLOUD = 5 local function draw_clouds(f) for i = 1, N_CLOUD do local h = hash32(i * 0x9E3779B1) local sp = 0.30 + (h >> 4) % 40 / 100.0 local x = h % (W - 14) local y = fmod(f * sp + h % 137, H + 20) - 10 local w = 9 + (h >> 8) % 8 local iy = floor(y) rect(x, iy, w, 3, CLOUD[1], CLOUD[2], CLOUD[3]) rect(x + 2, iy - 2, w - 5, 2, CLOUD[1], CLOUD[2], CLOUD[3]) rect(x + 1, iy + 3, w - 2, 1, CLOUD_D[1], CLOUD_D[2], CLOUD_D[3]) end end local function draw_flame(f, y0) local n = 11 + floor(4 * sin(fmod(f * 0.7, 6.28318)) + 0.5) for j = 0, n - 1 do local t = j / n local hw = floor((1.6 + 1.8 * sin(t * 3.14159)) * (1.0 - t * 0.7) + 0.5) + (hash32(f * 7 + j) % 2) local c = FLAME[1 + floor(t * 3.99)] if hw > 0 then rect(R_X + R_W // 2 - hw, y0 + j, 2 * hw + 1, 1, c[1], c[2], c[3]) end end end local function smoke_row(x, y, w, a) if y >= 0 and y < H then gfx.blend_rect(x, y, w, 1, SMOKE[1], SMOKE[2], SMOKE[3], a) end end local N_SMOKE = 12 local function draw_smoke(f, y0) for i = 1, N_SMOKE do local h = hash32(i * 0x85EBCA6B) local per = 70 + h % 40 local t = fmod(f * 0.9 + h % per, per) / per local y = y0 + 6 + t * 40 local x = R_X + R_W // 2 + floor((h % 9 - 4) * t * 2.4) local r = 2 + floor(t * 5.0) local a = 0.85 * (1.0 - t * 0.9) for dy = -r, r do local dx = floor(0.9 * (r * r - dy * dy) ^ 0.5 + 0.5) if dx > 0 then smoke_row(x - dx, floor(y) + dy, 2 * dx + 1, a) end end end end local STEP_HZ = 30 function render() local f = frame * STEP_HZ // gfx.FPS for i = 1, 3 do local c = SKY[i] rect(0, (i - 1) * 22, W, 22, c[1], c[2], c[3]) end draw_clouds(f) local bob = floor(1.5 + 1.5 * sin(fmod(f * 0.05, 6.28318))) local ry = R_Y + bob draw_smoke(f, ry + R_H) draw_flame(f, ry + R_H - 2) gfx.blit_indexed(R_SPR, R_PAL, R_X, ry, R_W, R_H, R_W, R_H, true) end