var topCloud = getName("cloud_0");
var botCloud = getName("cloud_1");
var ship = getName("ship");
var text = getText("text");

function rerunCloud(cloud)
{
  var delayTime = Math.random() * .2;
  var time = 2.75 - delayTime;
  delay(delayTime, function()
  {
    cloud.x = 256;
    tween(cloud, -130, cloud.y, time, null);
  });
  return delayTime + time;
}

function cloudTop()
{
  if (this.hidden) return;
  delay(rerunCloud(topCloud), cloudTop);
}
function cloudBot()
{
  if (this.hidden) return;
  delay(rerunCloud(botCloud), cloudBot);
}
delay(1.5, cloudTop);
cloudBot();

function showText(key)
{
  var t = Locale.get(key, "auto");
  text.showText(t);
  delay(t.length * 0.06 + 1.5, function() { this.next(); });
}

if (hasMemo("second_outro"))
{
  delMemo("second_outro");
  ship.x = 11;
  showText("#outro_3");
}
else
{
  setMemo("second_outro");
  
  delay(5, function()
  {
    // Ship move
    tween(ship, 11, ship.y, 2, null);
    delay(2.2, function()
    {
      showText("#outro_0");
    });
    
  });
}
