Frame 1
_global.WIDTH = 800;
_global.HEIGHT = 600;
_global.POSITION_RADIUS = 280;
_global.KEY1 = 42454;
_global.KEY2 = 38747;
function draw_edge(edge, vertex_u, vertex_v, color) {
edge.clear();
edge.lineStyle(2, (color ? (color) : 0), 100);
edge.moveTo(vertex_u._x, vertex_u._y);
edge.lineTo(vertex_v._x, vertex_v._y);
}
function start_game() {
level = 1;
num_lines = 4;
score = 0;
init_level();
}
function init_level() {
_root.createEmptyMovieClip("stage", 0);
num_vertices = (num_lines * (num_lines - 1)) / 2;
start_time = getTimer();
delete last_intersection;
level_label.text = "Level: " + level;
score_label.text = "Score: " + score;
make_adj_matrix(num_vertices);
make_vertices(num_vertices);
make_lines(num_lines);
generate_graph();
}
function hide_high_score_prompt() {
i = 0;
while (i < vertices.length) {
vertices[i].reincarnate();
i++;
}
high_score_prompt._visible = false;
shuffle_button.enabled = true;
quit_button.enabled = true;
high_score_list_button.enabled = true;
}
function show_level_screen() {
i = 0;
while (i < vertices.length) {
vertices[i].kill();
i++;
}
time = (getTimer() - start_time) / 1000;
mins = Math.floor(time / 60);
secs = Math.floor(time % 60);
bonus = Math.max((100 * Math.pow(2, level - 1)) - Math.floor(time), 0);
score = score + bonus;
level_screen.title.text = ("Level " + level) + " completed.";
level_screen.time.text = ((("Elapsed time: " + mins) + ":") + ((secs < 10) ? "0" : "")) + secs;
level_screen.bonus.text = "Bonus: " + bonus;
level_screen.score.text = "Score: " + score;
level_screen._visible = true;
shuffle_button.enabled = false;
quit_button.enabled = false;
high_score_list_button.enabled = false;
}
function test_segment(vertex_u1, vertex_v1, vertex_u2, vertex_v2) {
var _local6 = {x:vertex_u1._x, y:vertex_u1._y, dx:vertex_v1._x - vertex_u1._x, dy:vertex_v1._y - vertex_u1._y};
var _local5 = {x:vertex_u2._x, y:vertex_u2._y, dx:vertex_v2._x - vertex_u2._x, dy:vertex_v2._y - vertex_u2._y};
var _local3 = intercept_value(_local6, _local5);
var _local4 = intercept_value(_local5, _local6);
if ((((0 <= _local3) && (_local3 <= 1)) && (0 <= _local4)) && (_local4 <= 1)) {
return(true);
}
return(false);
}
function adj_matrix_get(u, v) {
if (v < u) {
return(adj_matrix_get(v, u));
}
return(adj_matrix[u][(v - u) - 1]);
}
function adj_matrix_put(u, v, val) {
if (v < u) {
return(adj_matrix_put(v, u, val));
}
return((adj_matrix[u][(v - u) - 1] = val));
}
function make_adj_matrix(num_vertices) {
adj_matrix = new Array(num_vertices - 1);
i = 0;
while (i < (num_vertices - 1)) {
adj_matrix[i] = new Array((num_vertices - i) - 1);
i++;
}
}
function make_vertices(num_vertices) {
vertices = new Array(num_vertices);
vertex_depth = vertices.length * vertices.length;
i = 0;
while (i < vertices.length) {
vertices[i] = stage.attachMovie("Vertex", "vertex_" + i, vertex_depth++);
vertices[i]._x = (_global.WIDTH / 2) + (_global.POSITION_RADIUS * Math.cos(((i * 2) * Math.PI) / vertices.length));
vertices[i]._y = (_global.HEIGHT / 2) + (_global.POSITION_RADIUS * Math.sin(((i * 2) * Math.PI) / vertices.length));
vertices[i].index = i;
i++;
}
}
function make_lines(num_lines) {
lines = new Array();
i = 0;
while (i < num_lines) {
lines.push({x:random(1024) - 512, y:random(1024) - 512, dx:random(1024) - 512, dy:random(1024) - 512});
i++;
}
}
function intercept_value(l1, l2) {
return(((((l2.dx * l1.y) - (l2.dy * l1.x)) + (l2.dy * l2.x)) - (l2.dx * l2.y)) / ((l2.dy * l1.dx) - (l2.dx * l1.dy)));
}
function pair_index(p, q, n) {
if (((((p == q) || (p < 0)) || (q < 0)) || (p >= n)) || (q >= n)) {
return(-1);
}
if (p > q) {
return(pair_index(q, p, n));
}
return(((((p == 0) ? 0 : (((((2 * n) - p) - 1) * p) / 2)) + q) - p) - 1);
}
function generate_graph() {
edge_depth = 0;
i = 0;
while (i < lines.length) {
intercepts = new Array();
j = 0;
while (j < num_lines) {
if (j != i) {
intercepts.push({index:j, value:intercept_value(lines[i], lines[j])});
}
j++;
}
intercepts.sortOn("value", Array.NUMERIC);
j = 0;
while (j < (intercepts.length - 1)) {
vertex1 = pair_index(i, intercepts[j].index, lines.length);
vertex2 = pair_index(i, intercepts[j + 1].index, lines.length);
adj_matrix_put(vertex1, vertex2, stage.createEmptyMovieClip((("edge_" + vertex1) + "_") + vertex2, edge_depth++));
draw_edge(adj_matrix_get(vertex1, vertex2), vertices[vertex1], vertices[vertex2]);
j++;
}
i++;
}
}
function load_high_scores(show_scores) {
loader = new LoadVars();
loader.onLoad = function () {
i = 1;
while (i <= 10) {
if (i <= this.n) {
high_scores_list["score" + i].text = (((i + ". ") + this["name" + i]) + " - ") + this["score" + i];
} else {
high_scores_list["score" + i].text = "";
}
i++;
}
if (show_scores) {
show_high_scores_list();
}
};
loader.load("http://lynn.dhs.org:81/Planarity/scores.php");
}
_root.attachMovie("NextLevelScreen", "level_screen", 1);
level_screen._x = _global.WIDTH / 2;
level_screen._y = _global.HEIGHT / 2;
level_screen._visible = false;
_root.attachMovie("HighScoresList", "high_scores_list", 2);
high_scores_list._x = _global.WIDTH / 2;
high_scores_list._y = _global.HEIGHT / 2;
high_scores_list._visible = false;
_root.attachMovie("HighScorePrompt", "high_score_prompt", 3);
high_score_prompt._x = _global.WIDTH / 2;
high_score_prompt._y = _global.HEIGHT / 2;
high_score_prompt._visible = false;
start_game();
load_high_scores();
_global.draw_vertex_edges = function (v, color) {
u = 0;
while (u < vertices.length) {
if (u != v) {
edge = adj_matrix_get(v, u);
if (edge != null) {
draw_edge(edge, vertices[u], vertices[v], color);
}
}
u++;
}
};
_global.highlight_vertex_neighbors = function (v) {
u = 0;
while (u < vertices.length) {
if ((u != v) && (adj_matrix_get(v, u) != null)) {
vertices[u].gotoAndStop("highlight");
}
u++;
}
};
_global.check_edges = function () {
if (last_intersection && (test_segment(vertices[last_intersection.u], vertices[last_intersection.v], vertices[last_intersection.s], vertices[last_intersection.t]))) {
return(undefined);
}
var _local2 = 0;
while (_local2 < (vertices.length - 1)) {
var _local1 = _local2 + 1;
while (_local1 < vertices.length) {
if (adj_matrix_get(_local2, _local1) != null) {
var _local4 = 0;
while (_local4 < (vertices.length - 1)) {
var _local3 = _local4 + 1;
while (_local3 < vertices.length) {
if ((((((_local4 != _local2) && (_local3 != _local1)) && (_local4 != _local1)) && (_local3 != _local2)) && (adj_matrix_get(_local4, _local3) != null)) && (test_segment(vertices[_local2], vertices[_local1], vertices[_local4], vertices[_local3]))) {
last_intersection = {u:_local2, v:_local1, s:_local4, t:_local3};
return(undefined);
}
_local3++;
}
_local4++;
}
}
_local1++;
}
_local2++;
}
show_level_screen();
};
_global.next_level = function () {
level++;
num_lines++;
level_screen._visible = false;
shuffle_button.enabled = true;
quit_button.enabled = true;
high_score_list_button.enabled = true;
init_level();
};
_global.shuffle = function () {
i = 0;
while (i < vertices.length) {
vertices[i]._x = random(WIDTH);
vertices[i]._y = random(HEIGHT);
draw_vertex_edges(i);
i++;
}
};
_global.show_high_score_prompt = function () {
i = 0;
while (i < vertices.length) {
vertices[i].kill();
i++;
}
high_score_prompt._visible = true;
high_score_prompt.score.text = "Score: " + score;
shuffle_button.enabled = false;
quit_button.enabled = false;
high_score_list_button.enabled = false;
};
_global.submit_high_score = function (name) {
if ((name == "") || (score == 0)) {
hide_high_score_prompt();
return(undefined);
}
loader = new LoadVars();
loader.onLoad = function () {
id = (this.id ^ KEY1) ^ KEY2;
loader = new LoadVars();
loader.id = id;
loader.name = name;
loader.score = score;
loader.onLoad = function () {
game_over = true;
hide_high_score_prompt();
load_high_scores(true);
};
loader.sendAndLoad("http://lynn.dhs.org:81/Planarity/submit.php", loader, "GET");
};
loader.load("http://lynn.dhs.org:81/Planarity/getid.php");
};
_global.show_high_scores_list = function () {
i = 0;
while (i < vertices.length) {
vertices[i].kill();
i++;
}
high_scores_list._visible = true;
shuffle_button.enabled = false;
quit_button.enabled = false;
high_score_list_button.enabled = false;
};
_global.hide_high_scores_list = function () {
i = 0;
while (i < vertices.length) {
vertices[i].reincarnate();
i++;
}
high_scores_list._visible = false;
shuffle_button.enabled = true;
quit_button.enabled = true;
high_score_list_button.enabled = true;
if (game_over) {
game_over = false;
start_game();
}
};
Symbol 5 MovieClip [Vertex] Frame 1
onRollOver = function () {
gotoAndStop ("select");
};
onRollOut = (onMouseUp = function () {
mouse_down = false;
gotoAndStop ("default");
});
onRelease = function () {
gotoAndStop ("select");
check_edges();
};
onPress = function () {
offset_x = _root._xmouse - _x;
offset_y = _root._ymouse - _y;
mouse_down = true;
_global.highlight_vertex_neighbors(index);
};
onMouseMove = function () {
if (mouse_down) {
_x = Math.min(Math.max(_root._xmouse - offset_x, 0), _global.WIDTH);
_y = Math.min(Math.max(_root._ymouse - offset_y, 0), _global.HEIGHT);
_global.draw_vertex_edges(index);
}
};
kill = function () {
delete onRollOver;
delete onRollOut;
delete onRelease;
delete onPress;
delete onMouseMove;
gotoAndStop ("default");
};
reincarnate = function () {
gotoAndPlay ("initialize");
};
gotoAndStop ("default");
Symbol 14 Button
on (release) {
_global.submit_high_score(this.name.text);
}
Symbol 25 Button
on (release) {
_global.hide_high_scores_list();
}
Symbol 43 Button
on (release) {
_global.next_level();
}
Symbol 53 Button
on (release) {
_global.shuffle();
}
Symbol 58 Button
on (release) {
_global.show_high_score_prompt();
}
Symbol 63 Button
on (release) {
_global.show_high_scores_list();
}