-- sprite screen

-- tables for easy parameter altering
lettersprite = {}
letter = {}
pos = {}

stars = {}
starpos = {}

function textsprite(text)
  -- make a bunch of sprites
  local strlen = string.len(text)
  local startx = 80
  local starx = 320
  local mult = 1
  local dir = 1

  -- stuff them into tables so we can get them later
  for i = 1, strlen do
    myglyph = dink.create_sprite(startx, 200, 0, 831, 1)
    myglyph.nodraw = true
    table.insert(lettersprite, myglyph)
    startx = startx + 20
    table.insert(letter, string.sub(text, i, i))
    table.insert(pos, i * 0.2)
    -- let's make some flying hearts too
    local star = dink.create_sprite(600, 200, brain.REPEAT, 53, 1)
    star.nodraw = true
    star.frame = 1
    star.touch_damage = -1
    star.script = "gheart"
    table.insert(stars, star)
    table.insert(starpos, i * 0.3)
  end

  dink.wait(5000)
  while true do
    -- go through the table and alter all the values
    for k, v in ipairs(lettersprite) do
      v:say("`" .. math.random(6) .. letter[k])
      v.y = math.floor(math.deg(math.cos(pos[k])) + 2.5) + 300
      pos[k] = pos[k] + 0.2
      stars[k].x = starx + math.floor(math.deg(math.sin(starpos[k])) * mult + 0.5)
      stars[k].y = 200 + math.floor(math.deg(math.cos(starpos[k])) * mult + 0.5)
      stars[k].nodraw = false
      starpos[k] = starpos[k] + 0.2
      if mult < 3 and dir == 1 then
        mult = mult + 0.001
      else
        mult = mult - 0.001
        dir = 2
      end

      if mult == 0 then
        dir = 1
      end

      if stars[k].x > 650 then
        stars[k].x = 320
        stars[k].y = 200
        dir = 1
      end
    end
    dink.wait(10)
  end
end

function main()
  stuff = { "labyrinth.mod", "bgm.xm", "bgm 2.xm", "datajack.s3m" }
  dink.playmidi(stuff[math.random(4)])
  textsprite("YEOLDEDINK RELEASE 0.86!")
end
