EVR.include("animation/effects/Scroller.js");
EVR.include("animation/effects/Fader.js");
EVR.include("animation/introduction/Introduction.js");
EVR.include("animation/ending/Ending.js");

EVR.Animation = function(rate, skip_frames, buffer)
{
   this.rate = rate;
   this.playing = false;
   this.deviation = 0;
   this.skip_frames = skip_frames || false;
   this.buffer = buffer || false;
}

EVR.Animation.prototype.play = function(method_name, delay)
{
   if (method_name == null)
   {
      method_name = DEFAULT_ANIMATION_METHOD_NAME;
   }
   var parameters = this.extract_parameters(arguments);
   var current = this;
   this.reset_last_ms(delay);
   this.interval = window.setTimeout(
      function()
      {
	 current.playing = true;
	 current.loop(method_name, parameters);
      }, delay);
}

EVR.Animation.prototype.reset_last_ms = function(delay)
{
   if (this.skip_frames)
   {
      this.last_ms = +new Date - this.rate;
      if (delay)
      {
	 this.last_ms += delay;
      }
   }
}

EVR.Animation.prototype.loop = function(method_name, parameters)
{
   var frames = 1;
   if (this.skip_frames)
   {
      frames += this.measure_deviation();
   }
   var current = this;
   for (var ii = 0; ii < frames; ii++)
   {
      current[method_name].apply(current, parameters);
   }
   if (this.playing)
   {
      this.interval = window.setTimeout(
	 function()
	 {
	    current.loop(method_name, parameters);
	 }, this.rate - this.buffer);
   }
}

EVR.Animation.prototype.measure_deviation = function()
{
   var count = 0;
   var time = +new Date;
   var difference = time - this.last_ms;
   var overflow = difference - this.rate;
   this.deviation += overflow;
   this.last_ms = time;
   if (this.deviation < -this.rate)
   {
      this.deviation += this.rate;
      count--;
   }
   else
   {
      while (this.deviation > this.rate)
      {
	 this.deviation -= this.rate;
	 count++;
      }
   }
   return count;
}

EVR.Animation.prototype.stop = function()
{
   window.clearInterval(this.interval);
   this.playing = false;
}

EVR.Animation.prototype.extract_parameters = function(list)
{
   if (list.length > 2)
   {
      list = Array.prototype.slice.call(list);
      return list.slice(2);
   }
   return [null];
}

EVR.Animation.prototype.toggle = function()
{
   if (this.playing)
   {
      this.stop();
   }
   else
   {
      this.play();
   }
}

EVR.Animation.prototype.toString = function()
{
   return "[object EVR.Animation]";
}
EVR.include("animation/ending/tombstone/Tombstone.js");
EVR.include("animation/ending/family/Family.js");
EVR.include("animation/ending/rainbow/Rainbow.js");
EVR.include("animation/ending/corpse/Corpse.js");
EVR.include("animation/ending/message/Message.js");
EVR.Animation.Ending = function(evr)
{
   this.evr = evr;
   this.container = evr.field;
   this.set_y_offset();
   this.add_children();
   this.playing = false;
   this.visible = false;
   this.finished = false;
}
EVR.Animation.Ending.prototype.set_y_offset = function()
{
   this.y_offset = -this.container.ground.get_dimensions(true)[1];
}
EVR.Animation.Ending.prototype.add_children = function()
{
   this.tombstone = new EVR.Animation.Ending.Tombstone(this);
   this.family  = new EVR.Animation.Ending.Family(this);
   this.rainbow = new EVR.Animation.Ending.Rainbow(this);
   this.corpse = new EVR.Animation.Ending.Corpse(this);
   this.message = new EVR.Animation.Ending.Message(this);
}
EVR.Animation.Ending.prototype.play = function()
{
   if (!this.playing)
   {
      var field = this.evr.field;
      field.stop_trees();
      field.set_color(ENDING_BACKGROUND);
      this.tombstone.append();
      this.family.append();
      this.rainbow.append();
      this.corpse.append();
      this.visible = true;
   }
   this.family.play();
   this.rainbow.play(null, RAINBOW_DELAY);
   this.playing = true;
}
EVR.Animation.Ending.prototype.display_message = function()
{
   if (this.playing)
   {
      this.message.append();
   }
}
EVR.Animation.Ending.prototype.stop = function()
{
   this.family.stop();
   this.rainbow.stop();
   this.corpse.stop();
   this.corpse.soul.stop();
   this.playing = false;
}
EVR.Animation.Ending.prototype.reset = function()
{
   this.rainbow.reset();
   this.family.reset();
   this.corpse.reset();
   this.message.remove();
}
EVR.Animation.Ending.prototype.clear = function()
{
   this.stop();
   this.reset();
   var field = this.evr.field;
   this.remove_children();
   field.start_trees();
   field.set_color(FIELD_COLORS[0]);
   this.finished = false;
   this.visible = false;
}
EVR.Animation.Ending.prototype.remove_children = function()
{
   this.tombstone.remove();
   this.family.remove();
   this.rainbow.remove();
   this.corpse.remove();
}
EVR.Animation.Ending.prototype.draw = function()
{
   if (this.visible)
   {
      this.tombstone.draw();
      this.family.draw();
      this.rainbow.draw();
      this.corpse.draw();
      this.message.draw();
   }
}
EVR.Animation.Ending.prototype.toString = function()
{
   return "[object EVR.Animation.Ending]";
}
18.216.150.3
18.216.150.3
18.216.150.3
 
June 6, 2016