EVR.Level.Road.Borders = function(container, level)
{
   this.container = container;
   this.background = level.background;
   this.height = ROAD_BORDER_WIDTH;
   this.build();
}
EVR.Level.Road.Borders.prototype.build = function()
{
   this.borders = [];
   this.borders.push(this.build_border(ALIGN_TOP, -this.height));
   this.borders.push(this.build_border(ALIGN_BOTTOM, this.height));
}
EVR.Level.Road.Borders.prototype.build_border = function(alignment, offset)
{
   var border = new EVR.Graphic(
      this.container, null, null, alignment, this.container.container);
   border.set_color(this.background);
   border.set_proportions(1, this.height);
   border.place(null, offset);
   border.append();
   return border;
}
EVR.Level.Road.Borders.prototype.draw = function()
{
   for (var ii = 0; ii < this.borders.length; ii++)
   {
      this.borders[ii].draw();
   }
}
EVR.Level.Road.Borders.prototype.get_dimensions = function(ratio)
{
   return this.borders[0].get_dimensions(ratio);
}
EVR.Level.Road.Borders.prototype.get_coordinates = function(ratio)
{
   return this.borders[0].get_coordinates(ratio);
}
EVR.Level.Road.Borders.prototype.toString = function()
{
   return "[object EVR.Level.Road.Borders]";
}
EVR.Level.Road.Racer.Ghost = function(container, level)
{
   EVR.Level.Road.Racer.call(this, container, level);
   this.initialize_avatar();
   this.set_step();
   this.update_dimensions();
   this.initialize_trail();
   this.lane = 0;
}
EVR.Level.Road.Racer.Ghost.prototype = new EVR.Level.Road.Racer;
EVR.Level.Road.Racer.Ghost.prototype.initialize_avatar = function()
{
   EVR.Level.Road.Racer.prototype.initialize_avatar.call(this);
   this.avatar.set_opacity(GHOST_OPACITY);
}
EVR.Level.Road.Racer.Ghost.prototype.initialize_trail = function()
{
   var trail = new EVR.Level.Road.Path.Trail(this.level);
   trail.load();
   this.index = 0;
   this.marker = trail[0];
   this.trail = trail;
}
EVR.Level.Road.Racer.Ghost.prototype.update =
   function(player_speed, rate, cluster)
{
   if (this.trail.trail.length > 0)
   {
      this.advance_marker();
      this.update_offset(player_speed, rate);
      if (cluster >= 0)
      {
	 this.update_map_indicator(cluster);
      }
      this.lane = this.marker.lane;
   }
   this.place();
}
EVR.Level.Road.Racer.Ghost.prototype.place = function()
{
   if (this.trail.trail.length > 0)
   {
      EVR.Level.Road.Racer.prototype.place.call(this);
   }
}
// fix offset during redraw
EVR.Level.Road.Racer.Ghost.prototype.advance_marker = function()
{
//    var time = this.level.clock.time.get();
//    var trail = this.trail.trail;
//    var index = this.index;
//    var limit = trail.length - 1;
//    var advanced = false;
//    while (index < limit && trail[index + 1].time < time)
//    {
//       advanced = true;
//       index++;
//    }
//    this.index = index;
//    this.marker = trail[index];
//    return advanced;
   var index = this.index + 1;
   var trail = this.trail.trail;
   if (index >= trail.length)
   {
      index--;
   }
   this.marker = trail[index];
   this.index = index;
}
EVR.Level.Road.Racer.Ghost.prototype.update_offset =
   function(player_speed, rate)
{
   var dimensions = this.container.get_dimensions();
   var ratio = dimensions[1] / dimensions[0];
   var difference = this.marker.speed - parseFloat(player_speed);
   this.offset += difference * ratio * rate;
}
EVR.Level.Road.Racer.Ghost.prototype.update_map_indicator =
   function(cluster_index)
{
   var road = this.container;
   var map = this.level.map;
   var racer_x = road.racer.get_coordinates()[0];
   var distance = racer_x - this.get_coordinates()[0];
   var direction = distance <= 0 ? 1 : -1;
   distance = Math.abs(distance);
   var items = road.path.items;
   var cluster = items[cluster_index];
   if (direction < 0)
   {
      var edge = cluster.get_coordinates()[0];
   }
   else
   {
      var edge = cluster.get_coordinates()[0] + cluster.get_dimensions()[0];
   }
   var difference = Math.abs(racer_x - edge);
   var remove = false;
   for (var ii = cluster_index; ii < items.length - 1 && ii > 0; ii += direction)
   {
      if (difference >= distance)
      {
	 break;
      }
      cluster = items[ii + direction];
      difference += cluster.get_dimensions()[0];
   }
   if (ii > 0 && ii < items.length - 1)
   {
      map.advance_ghost(ii - 1);
   }
}
EVR.Level.Road.Racer.Ghost.prototype.toString = function()
{
   return "[object EVR.Level.Road.Racer.Ghost]";
}
EVR.include("level/road/racer/player/Player.js");
EVR.include("level/road/racer/Ghost.js");
EVR.include("level/road/racer/flame/Flame.js");
EVR.include("level/road/racer/flash/Flash.js");
EVR.Level.Road.Racer = function(container, level)
{
   this.container = container;
   this.level = level;
   this.lane = 0;
}
EVR.Level.Road.Racer.prototype.initialize_avatar = function()
{
   var container = this.container;
   var avatar = new EVR.Emoticon(this.level.container);
   avatar.set_container(container);
   avatar.aligner.alignment = ALIGN_TOP_LEFT;
   avatar.set_proportions(1, container.beam_height);
   avatar.set_color();
   avatar.append();
   this.avatar = avatar;
   this.initialize_offset();
}
EVR.Level.Road.Racer.prototype.initialize_offset = function()
{
   var dimensions = this.avatar.container.get_dimensions();
   this.offset = dimensions[1] / dimensions[0] / PLAYER_OFFSET;
}
EVR.Level.Road.Racer.prototype.place = function()
{
   this.avatar.place(this.offset, this.step * this.lane);
}
EVR.Level.Road.Racer.prototype.set_step = function()
{
   var height = this.container.beam_height;
   var margin = this.container.margin;
   this.step = height + margin;
}
EVR.Level.Road.Racer.prototype.draw = function()
{
   this.place();
   this.avatar.draw();
   this.update_dimensions();
}
EVR.Level.Road.Racer.prototype.move = function(direction)
{
   var lane = this.lane + direction;
   var count = this.level.count_lanes();
   if (lane < 0)
   {
      this.lane = count - 1;
   }
   else if (lane >= count)
   {
      this.lane = 0;
   }
   else
   {
      this.lane = lane;
   }
   this.place();
}
EVR.Level.Road.Racer.prototype.update_dimensions = function()
{
   this.dimensions = this.avatar.get_dimensions();
}
EVR.Level.Road.Racer.prototype.get_dimensions = function(ratio)
{
   if (ratio == true)
   {
      return this.avatar.get_dimensions(true);
   }
   else
   {
      return this.dimensions;
   }
}
EVR.Level.Road.Racer.prototype.get_coordinates = function(ratio)
{
   return this.avatar.get_coordinates(ratio);
}
EVR.Level.Road.Racer.prototype.remove = function()
{
   this.avatar.remove();
}
EVR.Level.Road.Racer.prototype.toString = function()
{
   return "[object EVR.Level.Road.Racer]";
}
3.80.85.76
3.80.85.76
3.80.85.76
 
June 7, 2018


↠ RSS Feed ↞