Skip to content

Sky Laser

A satellite in your corner: the ORBITAL UPLINK gear card locks on to the toughest enemy nearby and slices it with a beam from orbit. Hit NOS to call a strike at once. Three upgrade cards, a radio call, and fifty vaporized enemies earn the ION BLUE paint. A code mod: a weapon of its own with charge-up, beams and lights drawn with the drawing kit.

Mod id Kind Files
sky_laser Lua code 7

It comes with the game: turn it on under MODS on the home menu and start the game again. Browse it on GitHub.

mod.json

{
  "id": "sky_laser",
  "title": "Sky Laser",
  "version": "1.0",
  "api": 1,
  "author": "Taxation Evasion",
  "description": "A satellite in your corner: the ORBITAL UPLINK gear card locks on to the toughest enemy nearby and slices it with a beam from orbit. Hit NOS to call a strike at once. Three upgrade cards, a radio call, and fifty vaporized enemies earn the ION BLUE paint. A code mod: a weapon of its own with charge-up, beams and lights drawn with the drawing kit.",
  "scripts": ["main.lua"]
}

main.lua

-- Sky Laser: a weapon with a pattern of its own (game.weapon). Every
-- `interval` it locks on to the toughest enemies in `range`, charges for a
-- moment while a reticle closes in, then a beam from orbit blasts `radius`
-- around each for `damage`. Starting NOS calls a strike at once.
-- Everything here goes through the `game` API (docs/modding/API.md).

local CHARGE = 0.8   -- seconds from lock-on to impact
local GLOW = 0.45    -- seconds the beam and scorch stay on screen

-- Toughest first: the beam is wasted on a cop on foot.
local function targets(s, w)
  local list = {}
  for _, e in ipairs(game.enemies(s, s.player.x, s.player.y, w.stats.range)) do
    if e.hp > 0 then list[#list + 1] = e end
  end
  table.sort(list, function(a, b) return a.hp > b.hp end)
  return list
end

local function strike(s, w)
  local picks = targets(s, w)
  if #picks == 0 then return false end
  for i = 1, math.min(w.stats.rounds, #picks) do
    local e = picks[i]
    w.state.strikes[#w.state.strikes + 1] = {e = e, x = e.x, y = e.y, charge = CHARGE, glow = 0}
  end
  game.sound(s, 'laser_ufo', 0.35, 0.7)
  if not s.sky_laser_called then
    s.sky_laser_called = true
    game.say(s, 'sky_laser.online')
  end
  return true
end

game.weapon('sky_laser.beam', {
  -- The simulation: all timing and damage happen here, the same on every machine.
  fire = function(s, w, dt)
    local st = w.state
    st.strikes = st.strikes or {}
    st.wait = (st.wait or 1) - dt
    -- Starting NOS calls a strike now (a rising edge of `boosting`).
    local boost = s.player.boosting and not st.boosting
    st.boosting = s.player.boosting
    if (st.wait <= 0 or boost) and strike(s, w) then st.wait = w.stats.interval
    elseif st.wait <= 0 then st.wait = 0.25 end
    for i = #st.strikes, 1, -1 do
      local k = st.strikes[i]
      if k.charge > 0 then
        -- The beam tracks its target while it charges.
        if k.e.hp > 0 then k.x, k.y = k.e.x, k.e.y end
        k.charge = k.charge - dt
        if k.charge <= 0 then
          local _, burned = game.blast(s, k.x, k.y, w.stats.radius, w.stats.damage)
          if #burned > 0 then game.count(s, 'sky_laser.vaporized', #burned) end
          game.sound(s, 'explosion_rumble', 0.45, 1.3)
          k.glow = GLOW
        end
      else
        k.glow = k.glow - dt
        if k.glow <= 0 then table.remove(st.strikes, i) end
      end
    end
  end,
  -- Drawing only reads the strikes: a closing reticle, then the beam.
  draw = function(s, w, d)
    local cyan, flash = w.stats.color or {120, 220, 255}, not d.reduced_flashes
    for _, k in ipairs(w.state.strikes or {}) do
      if d.visible(k.x, k.y, 260) then
        if k.charge > 0 then
          local t = 1 - k.charge / CHARGE
          local r = w.stats.radius * (1.6 - t)
          d.ring(k.x, k.y, r, cyan, 0.4 + 0.5 * t)
          d.line(k.x - r - 6, k.y, k.x - r + 4, k.y, cyan, 0.9, 1)
          d.line(k.x + r - 4, k.y, k.x + r + 6, k.y, cyan, 0.9, 1)
          d.line(k.x, k.y - r - 6, k.x, k.y - r + 4, cyan, 0.9, 1)
          d.line(k.x, k.y + r - 4, k.x, k.y + r + 6, cyan, 0.9, 1)
          d.light(k.x, k.y, 30 + 40 * t, cyan, 0.4 * t)
        else
          -- The beam slants in from high above, then fades.
          local a = k.glow / GLOW
          local sx, sy = k.x + 150, k.y - 320
          d.line(sx, sy, k.x, k.y, cyan, 0.5 * a, 7)
          d.line(sx, sy, k.x, k.y, 'white', 0.9 * a, 2)
          d.circle(k.x, k.y, w.stats.radius * (flash and 1 or 0.6) * (1.2 - 0.4 * a), cyan, 0.35 * a)
          d.circle(k.x, k.y, 8 * a, 'white', 0.9 * a)
          d.light(k.x, k.y, w.stats.radius * 3, cyan, (flash and 1 or 0.4) * a)
        end
      end
    end
  end,
})

announcer.json

[
  {
    "id": "sky_laser.online",
    "lines": [
      "Satellite uplink is online.",
      "Hit NOS to call a strike."
    ],
    "priority": 2,
    "ttl": 5
  }
]

cards.json

[
  {
    "id": "sky_laser.uplink",
    "name": "ORBITAL UPLINK",
    "tier": "gear",
    "branch": "orbital",
    "max": 1,
    "icon": 12,
    "description": "A satellite locks on to the toughest enemy nearby and burns it from orbit. NOS calls a strike at once."
  },
  {
    "id": "sky_laser.focus",
    "name": "FOCUSING LENS",
    "tier": "specialist",
    "branch": "orbital",
    "max": 1,
    "icon": 10,
    "requires": "sky_laser.uplink",
    "description": "Orbital beams hit twice as hard."
  },
  {
    "id": "sky_laser.overclock",
    "name": "OVERCLOCKED UPLINK",
    "tier": "specialist",
    "branch": "orbital",
    "max": 1,
    "icon": 9,
    "requires": "sky_laser.uplink",
    "description": "Orbital strikes come twice as often."
  },
  {
    "id": "sky_laser.constellation",
    "name": "CONSTELLATION",
    "tier": "specialist",
    "branch": "orbital",
    "max": 2,
    "icon": 12,
    "requires": "sky_laser.uplink",
    "description": "+1 beam per strike, each on a different target."
  }
]

counters.json

[
  {
    "id": "sky_laser.vaporized",
    "label": "VAPORIZED"
  }
]

paints.json

[
  {
    "id": "sky_laser.ion_blue",
    "name": "ION BLUE",
    "rgb": [70, 190, 255],
    "group": "COMBAT",
    "counter": "sky_laser.vaporized",
    "target": 50,
    "requirement": "Vaporize 50 enemies with the Orbital Uplink"
  }
]

weapons.json

[
  {
    "id": "sky_laser.uplink",
    "pattern": "sky_laser.beam",
    "range": 220,
    "interval": 4,
    "damage": 14,
    "radius": 34,
    "rounds": 1,
    "max_rounds": 3,
    "color": [120, 220, 255],
    "upgrades": {
      "sky_laser.focus": {"damage": 1},
      "sky_laser.overclock": {"rate": 1},
      "sky_laser.constellation": {"rounds": 1}
    }
  }
]