-- assets/scripts/fountain.lua
-- A fountain of quads: spawn at the top, sway as they fall, vanish below.
-- Edit this file WHILE THE ENGINE RUNS; it reloads on save (hot reload).
-- Try: change 180 to 60 (slow fall), 0.25 to 0.05 (firehose), 16 to 40.

local W, H  = 800, 600      -- match AppConfig's window size
local timer = 0

function on_update(view, dt)
  -- spawn a few quads per second along the top edge
  timer = timer + dt
  if timer > 0.25 then
    timer = 0
    local x = 40 + math.random() * (W - 80)
    mawida.spawn(x, 20, 16, 16)               -- x, y, w, h
  end

  -- steer every entity the engine showed us
  for _, e in ipairs(view.entities) do
    if e.y > H + 20 then
      mawida.despawn(e.id)                    -- fell off the bottom: gone
    else
      local wiggle = math.sin(e.y * 0.05) * 60
      mawida.set_velocity(e.id, wiggle, 180)  -- drift down, sway sideways
    end
  end
end
