EVR.include("title/word/Word.js");
EVR.Title = function(field)
{
   EVR.Graphic.call(this, field, null, null, ALIGN_TOP);
   this.field = field;
   this.words = [];
   this.setAttributes();
   this.append();
   this.addWords();
}
EVR.Title.prototype = new EVR.Graphic;
EVR.Title.prototype.setAttributes = function()
{
   this.element.id = "title";
   this.set_proportions(TITLE_WIDTH, TITLE_HEIGHT);
   this.place(0, TITLE_MARGIN);
}
EVR.Title.prototype.addWords = function()
{
   var words = this.words;
   words.push(new EVR.Title.Word(this, "EMOTICON", TITLE_EMOTICON_FONT_SIZE));
   words.push(new EVR.Title.Word(this, "VERSUS", TITLE_VERSUS_FONT_SIZE));
   words.push(new EVR.Title.Word(this, "RAINBOW", TITLE_RAINBOW_FONT_SIZE));
   this.words = words;
}
EVR.Title.prototype.draw = function()
{
   EVR.Graphic.prototype.draw.call(this);
   var words = this.words;
   for (var ii = 0; ii < words.length; ii++)
   {
      words[ii].draw();
   }
}
EVR.Title.prototype.toString = function()
{
   return "[object EVR.Title]";
}
EVR.include("title/word/Glyph.js");
EVR.Title.Word = function(title, word, font_size)
{
   this.title = title;
   this.word = word;
   this.font_size = font_size;
   this.glyphs = [];
   this.setElement();
   this.addGlyphs();
   this.setFontSize();
}
EVR.Title.Word.prototype.setElement = function()
{
   var element = document.createElement("span");
   element.id = this.word;
   element.className = "word";
   this.title.element.appendChild(element);
   this.element = element;
}
EVR.Title.Word.prototype.addGlyphs = function()
{
   var word = this.word;
   var glyphs = this.glyphs;
   for (var ii = 0; ii < word.length; ii++)
   {
      glyphs.push(new EVR.Title.Word.Glyph(this, word.charAt(ii)));
   }
   this.glyphs = glyphs;
}
EVR.Title.Word.prototype.setFontSize = function()
{
   var dimensions = this.title.field.get_dimensions();
   var modifier = dimensions[1] / dimensions[0];
   var basis = dimensions[0] * modifier;
   var style = this.element.style;
   style.fontSize = parseInt(basis * this.font_size) + "px";
   modifier = dimensions[0] / dimensions[1];
   style.letterSpacing = parseInt(modifier * TITLE_LETTER_SPACING) + "px";
}
EVR.Title.Word.prototype.draw = function()
{
   this.setFontSize();
}
EVR.Title.Word.Glyph = function(word, character)
{
   this.word = word;
   this.character = character;
   this.setElement();
   this.addBackground();
   this.addForeground();
}
EVR.Title.Word.Glyph.prototype.setElement = function()
{
   var element = document.createElement("span");
   element.id = this.character;
   this.word.element.appendChild(element);
   this.element = element;
}
EVR.Title.Word.Glyph.prototype.addForeground = function()
{
   var element = document.createElement("span");
   element.innerHTML = this.character;
   element.className = "foreground";
   this.element.appendChild(element);
}
EVR.Title.Word.Glyph.prototype.addBackground = function()
{
   var element = document.createElement("span");
   element.innerHTML = this.character;
   element.className = "background";
   this.element.appendChild(element);
}
EVR.include("level/cluster/Cluster.js");
EVR.include("level/loader/Loader.js");
EVR.include("level/road/Road.js");
EVR.include("level/Clock.js");
EVR.include("level/register/Register.js");
EVR.include("level/meter/Meter.js");
EVR.include("level/map/Map.js");
EVR.include("level/countdown/Countdown.js");
EVR.include("level/Prompt.js");
EVR.include("level/streak/Streak.js");
EVR.include("level/cheers/Cheers.js");
EVR.include("level/Delegate.js");
EVR.include("level/indicators/Indicators.js");
EVR.include("level/summary/Summary.js");
EVR.include("level/records/Records.js");
EVR.Level = function(evr, container, id, practice)
{
   this.evr = evr;
   this.container = container;
   this.id = parseInt(id);
   this.practice = practice;
   this.sound = evr.sound;
   this.initialize_states();
   this.load()
   this.add_children();
}
EVR.Level.prototype.initialize_states = function()
{
   this.states = [];
   this.states[LEVEL_STATE_WAITING] = true;
   this.states[LEVEL_STATE_RACING] = false;
   this.states[LEVEL_STATE_PAUSED] = false;
   this.states[LEVEL_STATE_SUMMARIZING] = false;
   this.states[LEVEL_STATE_FINISHED] = false;
}
EVR.Level.prototype.load = function()
{
   this.loader = new EVR.Level.Loader(this);
   this.loader.load();
   this.container.set_colors(this.sky);
}
EVR.Level.prototype.add_children = function()
{
   this.road = new EVR.Level.Road(this);
   this.clock = new EVR.Level.Clock(this);
   this.register = new EVR.Level.Register(this);
   this.meter = new EVR.Level.Meter(this);
   this.map = new EVR.Level.Map(this);
   this.prompt = new EVR.Level.Prompt(this);
   this.streak = new EVR.Level.Streak(this);
   this.cheers = new EVR.Level.Cheers(this);
   this.add_countdown();
   this.delegate = new EVR.Level.Delegate(this);
   this.add_indicators();
}
EVR.Level.prototype.add_countdown = function()
{
   var current = this;
   var action = function() { current.start() };
   this.countdown = new EVR.Level.Countdown(this, this.container, action);
}
EVR.Level.prototype.add_indicators = function()
{
   var record_count = this.evr.history.count_records();
   if (this.id == 1 && record_count < LEVEL_INDICATOR_DISPLAY_THRESHOLD)
   {
      this.indicators = new EVR.Level.Indicators(this);
   }
}
EVR.Level.prototype.draw = function()
{
   var states = this.states;
   if (states[LEVEL_STATE_RACING] && !states[LEVEL_STATE_PAUSED])
   {
      this.pause();
   }
   this.road.draw();
   this.clock.attached && this.clock.draw();
   this.register.attached && this.register.draw();
   this.meter.attached && this.meter.draw();
   this.map.attached && this.map.draw();
   this.prompt.attached && this.prompt.draw();
   this.streak.draw();
   this.cheers.draw();
   this.countdown.draw();
   !!this.summary && this.summary.draw();
   !!this.records && this.records.attached && this.records.draw();
   !!this.indicators && this.indicators.draw();
}
EVR.Level.prototype.start = function()
{
   var current = this;
   window.setTimeout(
      function()
      {
	 current.road.path.play();
	 current.clock.start();
// 	 !!current.indicators && current.indicators.remove();
	 current.set_state(LEVEL_STATE_RACING, true);
      }, LEVEL_START_DELAY);
}
EVR.Level.prototype.count_lanes = function()
{
   return !!this.beams && this.beams.length;
}
EVR.Level.prototype.finish = function()
{
   this.set_state(LEVEL_STATE_RACING, false);
   if (this.practice)
   {
      this.set_state(LEVEL_STATE_FINISHED, true);
      this.prompt.set_finish_text();
      this.prompt.toggle();
   }
   else
   {
      var road = this.road;
      road.path.remove();
      road.racer.remove();
      road.ghost.remove();
      !!this.indicators && this.indicators.remove();
      this.map.remove();
      this.register.remove();
      this.meter.remove();
      this.clock.remove();
      this.set_progress();
      this.update_expert_progress();
      this.initialize_history();
      this.save_trail();
      this.cheers.scroll();
      this.set_state(LEVEL_STATE_FINISHED, true);
      this.display_summary();
   }
}
EVR.Level.prototype.set_progress = function()
{
   var query = null;
   if (this.goal_cleared())
   {
      query = "clear=" + this.id;
   }
   var path = SOURCE_PATH + "level/update_progress.php";
   this.progress = parseInt(new EVR.Requester(path, query, true).execute());
}
EVR.Level.prototype.goal_cleared = function()
{
   return this.clock.time.get() <= this.goal.get();
}
EVR.Level.prototype.update_expert_progress = function()
{
   if (this.expert_goal_cleared())
   {
      var query = "id=" + this.id;
      var path = SOURCE_PATH + "level/update_expert_progress.php";
      new EVR.Requester(path, query, true).execute();
   }
}
EVR.Level.prototype.expert_goal_cleared = function()
{
   return this.clock.time.get() <= this.advanced.get();
}
EVR.Level.prototype.initialize_history = function()
{
   var history = this.evr.history;
   history.set_level(this);
   history.store_newest_record();
   this.history = history;
}
EVR.Level.prototype.save_trail = function()
{
   var best = this.history.get_best_time();
   if (best == null || this.clock.time.get() <= best)
   {
      this.road.path.trail.save();
   }
}
EVR.Level.prototype.display_summary = function()
{
   this.set_state(LEVEL_STATE_SUMMARIZING, true);
   this.summary = new EVR.Level.Summary(this);
}
EVR.Level.prototype.set_state = function(name, state)
{
   this.states[name] = !!state ? state : !this.states[name];
}
EVR.Level.prototype.remove = function()
{
   this.road.remove();
   this.prompt.attached && this.prompt.remove();
   !!this.indicators && this.indicators.remove();
   this.streak.clear();
   this.cheers.remove();
}
EVR.Level.prototype.pause = function()
{
   this.clock.toggle();
   this.road.path.toggle();
   this.set_state(LEVEL_STATE_PAUSED);
   if (this.states[LEVEL_STATE_PAUSED])
   {
      this.prompt.append();
   }
   else
   {
      this.prompt.remove();
   }
}
EVR.Level.prototype.is_clear = function()
{
   return this.progress >= this.id;
}
EVR.Level.prototype.next_level_is_available = function()
{
   return this.is_clear() && this.id < LEVEL_LIMIT;
}
EVR.Level.prototype.show_records = function()
{
   this.summary.remove();
   this.set_state(LEVEL_STATE_SUMMARIZING, false);
   this.records = new EVR.Level.Records(this);
}
EVR.Level.prototype.toString = function()
{
   return "[object EVR.Level]";
}
54.224.108.238
54.224.108.238
54.224.108.238
 
June 5, 2016

↠ RSS Feed ↞