January 28, 2014♦
☀
E
F
F
L
U
E
N
C
E
☀
<?php
$GLOBALS["CACHE_PATH"] = "flash/cache/";
$GLOBALS["FILE_EXTENSION"] = ".gif";
$GLOBALS["RELATIVE_IMAGE_DIRECTORY_PATH"] = "img/";
remove_cached_strip();
function remove_cached_strip()
{
go_to_cache_directory();
$path = find_image_file();
unlink($path);
}
function go_to_cache_directory()
{
go_to_image_directory();
chdir($GLOBALS["CACHE_PATH"]);
}
function go_to_image_directory()
{
$path = $GLOBALS["RELATIVE_IMAGE_DIRECTORY_PATH"];
while (!is_dir($path))
{
chdir("..");
}
chdir($path);
}
function find_image_file()
{
$index = $_GET["index"];
foreach (scandir(".") as $file)
{
if (fnmatch($index . "_*", $file))
{
return $file;
}
}
}
EVR.Level.Road.Path.Line = function(container, style)
{
EVR.Graphic.call(this, container, RATIO_HEIGHT, null, ALIGN_LEFT);
this.style = style;
this.margin = LINE_MARGIN;
this.checkers = [];
this.build();
}
EVR.Level.Road.Path.Line.prototype = new EVR.Graphic;
EVR.Level.Road.Path.Line.prototype.build = function()
{
this.set_proportions(LINE_WIDTH, 1);
this.set_color(LINE_COLOR);
this.set_opacity(LINE_OPACITY);
if (this.style == LINE_FINISH)
{
this.add_checkers();
}
}
EVR.Level.Road.Path.Line.prototype.add_checkers = function()
{
var count = LINE_CHECKER_COUNT;
var width = .5;
var height = 1.0 / count;
var alignment;
for (var ii = 0; ii < count; ii++)
{
alignment = ii % 2 ? ALIGN_TOP_RIGHT : ALIGN_TOP_LEFT;
var checker = new EVR.Graphic(this, null, null, alignment);
checker.set_color(LINE_CHECKER_COLOR);
checker.set_proportions(width, height);
checker.place(null, height * ii);
checker.append();
this.checkers.push(checker);
}
}
EVR.Level.Road.Path.Line.prototype.draw = function()
{
EVR.Graphic.prototype.draw.call(this);
if (this.style != LINE_FINISH)
{
this.set_border();
}
for (var ii = 0; ii < this.checkers.length; ii++)
{
this.checkers[ii].draw();
}
}
EVR.Level.Road.Path.Line.prototype.set_border = function()
{
var width = this.container.get_dimensions()[0] * this.get_margin();
var color = this.container.level.background;
if (!!window.ActiveXObject)
{
this.set_dimensions(this.get_dimensions()[0] + width);
}
this.css.borderRight = width + "px solid " + color;
}
EVR.Level.Road.Path.Line.prototype.get_margin = function()
{
var dimensions = this.container.get_dimensions();
return dimensions[1] / dimensions[0] * this.margin;
}
EVR.Level.Road.Path.Line.prototype.toString = function()
{
return "[object EVR.Level.Road.Path.Line]";
}
EVR.include("level/road/path/Line.js");
EVR.include("level/road/path/trail/Trail.js");
EVR.Level.Road.Path = function(container, level)
{
EVR.Animation.call(this, PATH_INITIAL_RATE, true, PATH_TIMING_BUFFER);
this.container = container;
this.level = level;
this.clusters = level.clusters;
this.racer = container.racer;
this.sprinting = false;
this.offset = 0;
this.speed = PATH_INITIAL_SPEED;
this.visible = 0;
this.color = null;
this.variance = [0, 0];
this.meter_unlocked = false;
this.trail = new EVR.Level.Road.Path.Trail(level);
this.populate();
this.last_ms = +new Date;
}
EVR.Level.Road.Path.prototype = new EVR.Animation;
EVR.Level.Road.Path.prototype.populate = function()
{
this.items = [new EVR.Level.Road.Path.Line(this.container)];
for (var ii = 0; ii < this.clusters.length; ii++)
{
this.clusters[ii].initiate(this.container, this.level);
}
this.items = this.items.concat(this.clusters);
this.items.push(new EVR.Level.Road.Path.Line(this.container, LINE_FINISH));
this.set_origin();
this.arrange();
}
EVR.Level.Road.Path.prototype.set_origin = function()
{
var racer = this.racer;
var offset = racer.get_coordinates(true)[0] + racer.get_dimensions(true)[0];
this.origin = offset + this.items[0].get_margin();
}
EVR.Level.Road.Path.prototype.arrange = function()
{
var x = this.origin - this.offset;
var container = this.container;
var border = container.get_dimensions()[0];
var racer = this.racer.get_coordinates()[0];
var cluster, left, width, right, ratio, inhabited = null;
for (var ii = this.visible, len = this.items.length; ii < len; ii++)
{
cluster = this.items[ii];
if (!cluster.attached)
{
cluster.append();
}
cluster.place(x);
left = cluster.get_coordinates()[0];
width = cluster.get_dimensions()[0];
right = left + width;
if (inhabited == null)
{
inhabited = this.locate_racer(racer, left, right, ii, len);
if (inhabited != null)
{
this.trail.add(this.speed, this.racer.lane);
}
}
ratio = width / border;
x += ratio;
if (right < 0)
{
cluster.remove();
this.visible++;
this.offset -= ratio;
}
else if (left > border)
{
break;
}
}
return inhabited;
}
EVR.Level.Road.Path.prototype.locate_racer = function(x, left, right, ii, len)
{
if (ii == 0 && x < left)
{
return -1;
}
else if (this.intersect(x, left, right) || ii == len - 1)
{
return ii;
}
return null;
}
EVR.Level.Road.Path.prototype.intersect = function(x, left, right)
{
return x >= left && x < right;
}
EVR.Level.Road.Path.prototype.sequence = function()
{
var ii = this.arrange();
var item = this.items[ii];
if (item instanceof EVR.Level.Road.Path.Line)
{
if (item.style == LINE_FINISH)
{
this.stop();
this.update_cheers();
this.level.finish();
return;
}
}
else if (item != null)
{
this.cluster = item;
this.update_color();
this.update_variance();
this.update_streak();
this.update_sprint_state();
this.update_flame();
this.update_flash();
this.set_instruments(ii);
this.set_speed();
// this.update_scoreboard(ii);
this.update_cheers();
}
this.step();
this.update_ghost(ii);
this.unlock_meter(ii);
}
EVR.Level.Road.Path.prototype.unlock_meter = function(index)
{
if (index >= this.items.length - PATH_METER_UNLOCK_OFFSET)
{
if (!this.meter_unlocked)
{
this.meter_unlocked = true;
this.set_meter_color();
}
}
}
EVR.Level.Road.Path.prototype.update_color = function()
{
var cluster = this.cluster;
var racer = this.racer;
var x = racer.get_coordinates()[0];
var gap_x = cluster.get_gap_x();
if (x >= gap_x)
{
this.color = null;
}
else
{
this.color = racer.lane;
if (!this.level.practice)
{
this.racer.add_color(this.color, cluster.passage);
}
}
}
EVR.Level.Road.Path.prototype.update_variance = function()
{
if (this.color != null)
{
this.variance[0]++;
this.variance[1] += !this.is_in_passage();
}
}
EVR.Level.Road.Path.prototype.is_in_passage = function()
{
return this.color == this.cluster.passage;
}
EVR.Level.Road.Path.prototype.update_streak = function()
{
var streak = this.level.streak;
if (this.color != null)
{
if (this.is_in_passage())
{
streak.increase();
}
else
{
streak.reset();
}
}
}
EVR.Level.Road.Path.prototype.set_instruments = function(ii)
{
if (ii > 0)
{
this.level.map.advance_player(ii - 1);
this.level.register.advance(ii - 1);
}
this.set_meter();
}
EVR.Level.Road.Path.prototype.set_meter = function()
{
var meter = this.level.meter;
if (this.sprinting)
{
meter.adjust(-this.rate);
}
var color = this.color;
if (color != null && this.is_in_passage())
{
adjustment = PATH_METER_BONUS + this.level.streak * PATH_STREAK_BONUS;
meter.adjust(adjustment);
}
this.set_meter_color();
}
EVR.Level.Road.Path.prototype.set_meter_color = function()
{
var meter = this.level.meter;
var reading = meter.read();
if (this.sprinting)
{
meter.set_color(METER_DRAINING_COLOR);
}
else if (reading >= this.level.threshold || this.meter_unlocked)
{
meter.set_color(METER_READY_COLOR);
}
else
{
meter.set_color(METER_DISABLED_COLOR);
}
}
EVR.Level.Road.Path.prototype.set_speed = function()
{
if (this.sprinting && this.level.meter.read() > 0)
{
this.speed = PATH_SPRINT_SPEED;
}
else
{
this.speed = PATH_INITIAL_SPEED;
}
var color = this.color;
if (color != null && !this.is_in_passage())
{
this.speed *= PATH_SPEED_PENALTY;
}
}
EVR.Level.Road.Path.prototype.update_ghost = function(ii)
{
var road = this.level.road;
if (!!road.ghost)
{
road.ghost.update(this.speed, this.rate, ii);
}
}
EVR.Level.Road.Path.prototype.update_sprint_state = function()
{
if (this.sprinting && this.level.meter.read() <= 0)
{
this.sprinting = false;
}
}
EVR.Level.Road.Path.prototype.update_flame = function()
{
this.racer.flame.update(this.sprinting, this.speed);
}
EVR.Level.Road.Path.prototype.update_flash = function()
{
this.racer.flash.update();
}
EVR.Level.Road.Path.prototype.update_scoreboard = function(item_index)
{
// this.level.scoreboard.update(item_index - 1);
this.level.scoreboard.update(this.speed);
}
EVR.Level.Road.Path.prototype.update_cheers = function()
{
this.level.cheers.update(this.sprinting, this.speed);
}
EVR.Level.Road.Path.prototype.step = function()
{
var dimensions = this.container.get_dimensions();
var ratio = dimensions[1] / dimensions[0];
this.offset += ratio * this.speed * this.rate;
}
EVR.Level.Road.Path.prototype.stop = function()
{
EVR.Animation.prototype.stop.call(this);
this.level.clock.stop();
this.sprinting = false;
}
EVR.Level.Road.Path.prototype.draw = function()
{
var cluster, y, boundary, started = false;
for (var ii = 0, len = this.items.length; ii < len; ii++)
{
cluster = this.items[ii];
if (cluster.attached)
{
started = true;
cluster.shape();
y = cluster.get_coordinates()[0];
boundary = this.container.get_coordinates()[0];
if (y > boundary)
{
cluster.remove();
}
}
else if (started)
{
break;
}
}
this.set_origin();
this.arrange();
this.update_cluster_dimensions();
}
EVR.Level.Road.Path.prototype.update_cluster_dimensions = function()
{
var items = this.items;
for (var ii = 1; ii < items.length - 1; ii++)
{
items[ii].update_dimensions();
}
}
EVR.Level.Road.Path.prototype.calculate_accuracy = function()
{
var variance = this.variance;
return 1 - (variance[1] / variance[0]);
}
EVR.Level.Road.Path.prototype.sprint = function()
{
var level = this.level;
if (level.meter.read() >= level.threshold || this.meter_unlocked)
{
this.sprinting = true;
}
}
EVR.Level.Road.Path.prototype.remove = function()
{
var item, items = this.items;
for (var ii = 0; ii < items.length; ii++)
{
item = items[ii];
item.attached && item.remove();
}
}
EVR.Level.Road.Path.prototype.toString = function()
{
return "[object EVR.Level.Road.Path]";
}