Skip to content

Commit

Permalink
Refactor path resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
bni committed Apr 20, 2011
1 parent 2c9793d commit f9140a9
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 96 deletions.
5 changes: 1 addition & 4 deletions js/crosstile.js
Expand Up @@ -6,10 +6,7 @@
orbium.Tile.prototype.construct.call(this, ["crosstile"+x], count,
xnr, ynr);

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.construct.apply(this, arguments);
Expand Down
5 changes: 1 addition & 4 deletions js/director.js
Expand Up @@ -8,10 +8,7 @@
orbium.Tile.prototype.construct.call(this, ["modtile0", null,
"director"+direction], count, xnr, ynr);

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.setBase = function() {
Expand Down
3 changes: 1 addition & 2 deletions js/falltile.js
Expand Up @@ -7,8 +7,7 @@
xnr, ynr);

this.inducesSink = true;

this.inducesTopPath = true;
this.inducesPaths = [true, false, false, false];
};

this.fallMarble = function(marble) {
Expand Down
3 changes: 1 addition & 2 deletions js/horiztile.js
Expand Up @@ -6,8 +6,7 @@
orbium.Tile.prototype.construct.call(this, ["horiztile"+x], count,
xnr, ynr);

this.inducesRightPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [false, true, false, true];
};

this.construct.apply(this, arguments);
Expand Down
5 changes: 1 addition & 4 deletions js/inspector.js
Expand Up @@ -9,10 +9,7 @@
orbium.Tile.prototype.construct.call(this, ["modtile0", null,
"inspector"+color], count, xnr, ynr);

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.setBase = function() {
Expand Down
14 changes: 5 additions & 9 deletions js/rotator.js
Expand Up @@ -23,11 +23,7 @@
"rotator0"], count, xnr, ynr);

this.inducesSink = true;

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.destruct = function() {
Expand Down Expand Up @@ -314,20 +310,20 @@

var proceed = false;

if (dir === 0 && that.hasTopPath &&
if (dir === 0 && that.hasPaths[0] &&
that.count >= orbium.Machine.horizTiles) {
proceed = true;
}

if (dir === 1 && that.hasRightPath) {
if (dir === 1 && that.hasPaths[1]) {
proceed = true;
}

if (dir === 2 && that.hasBottomPath) {
if (dir === 2 && that.hasPaths[2]) {
proceed = true;
}

if (dir === 3 && that.hasLeftPath) {
if (dir === 3 && that.hasPaths[3]) {
proceed = true;
}

Expand Down
5 changes: 1 addition & 4 deletions js/teleporter.js
Expand Up @@ -6,10 +6,7 @@
orbium.Tile.prototype.construct.call(this, ["modtile0", null,
"teleporter"+this.variant], count, xnr, ynr);

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.setBase = function() {
Expand Down
108 changes: 47 additions & 61 deletions js/tile.js
Expand Up @@ -7,33 +7,19 @@
this.variant = null;

this.inducesSink = null;
this.inducesPaths = null;

this.inducesTopPath = null;
this.inducesRightPath = null;
this.inducesBottomPath = null;
this.inducesLeftPath = null;

this.hasTopPath = null;
this.hasRightPath = null;
this.hasBottomPath = null;
this.hasLeftPath = null;
this.hasPaths = null;

this.construct = function(images, count, xnr, ynr) {
this.count = count;
this.xnr = xnr;
this.ynr = ynr;

this.inducesSink = false;
this.inducesPaths = [false, false, false, false];

this.inducesTopPath = false;
this.inducesRightPath = false;
this.inducesBottomPath = false;
this.inducesLeftPath = false;

this.hasTopPath = false;
this.hasRightPath = false;
this.hasBottomPath = false;
this.hasLeftPath = false;
this.hasPaths = [false, false, false, false];

var xpos = orbium.Tile.size*this.xnr;
var ypos = orbium.Tile.size*this.ynr+orbium.Bar.height;
Expand All @@ -50,104 +36,104 @@
idx = this.count-orbium.Machine.horizTiles;
if (idx >= 0 &&
idx < orbium.Machine.horizTiles*orbium.Machine.vertTiles &&
orbium.machine.tiles[idx].inducesTopPath &&
orbium.machine.tiles[idx].inducesPaths[0] &&
this.variant !== 1 &&
orbium.machine.tiles[idx].variant !== 1) {
this.hasTopPath = true;
this.hasPaths[0] = true;
} else {
this.hasTopPath = false;
this.hasPaths[0] = false;
}

// Should tile have right path?
idx = this.count+1;
if (idx >= 0 &&
idx < orbium.Machine.horizTiles*orbium.Machine.vertTiles &&
(this.count+1)%orbium.Machine.horizTiles !== 0 &&
orbium.machine.tiles[idx].inducesRightPath &&
orbium.machine.tiles[idx].inducesPaths[1] &&
this.variant !== 0 &&
orbium.machine.tiles[idx].variant !== 0) {
this.hasRightPath = true;
this.hasPaths[1] = true;
} else {
this.hasRightPath = false;
this.hasPaths[1] = false;
}

// Should tile have bottom path?
idx = this.count+orbium.Machine.horizTiles;
if (idx >= 0 &&
idx < orbium.Machine.horizTiles*orbium.Machine.vertTiles &&
orbium.machine.tiles[idx].inducesBottomPath &&
orbium.machine.tiles[idx].inducesPaths[2] &&
this.variant !== 1 &&
orbium.machine.tiles[idx].variant !== 1) {
this.hasBottomPath = true;
this.hasPaths[2] = true;
} else {
this.hasBottomPath = false;
this.hasPaths[2] = false;
}

// Should tile have left path?
idx = this.count-1;
if (idx >= 0 &&
idx < orbium.Machine.horizTiles*orbium.Machine.vertTiles &&
this.count%orbium.Machine.horizTiles !== 0 &&
orbium.machine.tiles[idx].inducesLeftPath &&
orbium.machine.tiles[idx].inducesPaths[3] &&
this.variant !== 0 &&
orbium.machine.tiles[idx].variant !== 0) {
this.hasLeftPath = true;
this.hasPaths[3] = true;
} else {
this.hasLeftPath = false;
this.hasPaths[3] = false;
}

// First row rotators
if (this.count < orbium.Machine.horizTiles &&
this instanceof orbium.Rotator) {
this.hasTopPath = true;
this.hasPaths[0] = true;
}

var frame = 0;

if (this.hasTopPath && !this.hasRightPath &&
!this.hasBottomPath && !this.hasLeftPath) {
if (this.hasPaths[0] && !this.hasPaths[1] &&
!this.hasPaths[2] && !this.hasPaths[3]) {
frame = 0;
} else if (!this.hasTopPath && this.hasRightPath &&
!this.hasBottomPath && !this.hasLeftPath) {
} else if (!this.hasPaths[0] && this.hasPaths[1] &&
!this.hasPaths[2] && !this.hasPaths[3]) {
frame = 1;
} else if (!this.hasTopPath && !this.hasRightPath &&
this.hasBottomPath && !this.hasLeftPath) {
} else if (!this.hasPaths[0] && !this.hasPaths[1] &&
this.hasPaths[2] && !this.hasPaths[3]) {
frame = 2;
} else if (!this.hasTopPath && !this.hasRightPath &&
!this.hasBottomPath && this.hasLeftPath) {
} else if (!this.hasPaths[0] && !this.hasPaths[1] &&
!this.hasPaths[2] && this.hasPaths[3]) {
frame = 3;
} else if (this.hasTopPath && this.hasRightPath &&
!this.hasBottomPath && !this.hasLeftPath) {
} else if (this.hasPaths[0] && this.hasPaths[1] &&
!this.hasPaths[2] && !this.hasPaths[3]) {
frame = 4;
} else if (!this.hasTopPath && this.hasRightPath &&
this.hasBottomPath && !this.hasLeftPath) {
} else if (!this.hasPaths[0] && this.hasPaths[1] &&
this.hasPaths[2] && !this.hasPaths[3]) {
frame = 5;
} else if (!this.hasTopPath && !this.hasRightPath &&
this.hasBottomPath && this.hasLeftPath) {
} else if (!this.hasPaths[0] && !this.hasPaths[1] &&
this.hasPaths[2] && this.hasPaths[3]) {
frame = 6;
} else if (this.hasTopPath && !this.hasRightPath &&
!this.hasBottomPath && this.hasLeftPath) {
} else if (this.hasPaths[0] && !this.hasPaths[1] &&
!this.hasPaths[2] && this.hasPaths[3]) {
frame = 7;
} else if (this.hasTopPath && this.hasRightPath &&
this.hasBottomPath && !this.hasLeftPath) {
} else if (this.hasPaths[0] && this.hasPaths[1] &&
this.hasPaths[2] && !this.hasPaths[3]) {
frame = 8;
} else if (!this.hasTopPath && this.hasRightPath &&
this.hasBottomPath && this.hasLeftPath) {
} else if (!this.hasPaths[0] && this.hasPaths[1] &&
this.hasPaths[2] && this.hasPaths[3]) {
frame = 9;
} else if (this.hasTopPath && !this.hasRightPath &&
this.hasBottomPath && this.hasLeftPath) {
} else if (this.hasPaths[0] && !this.hasPaths[1] &&
this.hasPaths[2] && this.hasPaths[3]) {
frame = 10;
} else if (this.hasTopPath && this.hasRightPath &&
!this.hasBottomPath && this.hasLeftPath) {
} else if (this.hasPaths[0] && this.hasPaths[1] &&
!this.hasPaths[2] && this.hasPaths[3]) {
frame = 11;
} else if (this.hasTopPath && !this.hasRightPath &&
this.hasBottomPath && !this.hasLeftPath) {
} else if (this.hasPaths[0] && !this.hasPaths[1] &&
this.hasPaths[2] && !this.hasPaths[3]) {
frame = 12;
} else if (!this.hasTopPath && this.hasRightPath &&
!this.hasBottomPath && this.hasLeftPath) {
} else if (!this.hasPaths[0] && this.hasPaths[1] &&
!this.hasPaths[2] && this.hasPaths[3]) {
frame = 13;
} else if (this.hasTopPath && this.hasRightPath &&
this.hasBottomPath && this.hasLeftPath) {
} else if (this.hasPaths[0] && this.hasPaths[1] &&
this.hasPaths[2] && this.hasPaths[3]) {
frame = 14;
}

Expand Down
5 changes: 1 addition & 4 deletions js/transformer.js
Expand Up @@ -9,10 +9,7 @@
orbium.Tile.prototype.construct.call(this, ["modtile0", null,
"transformer"+color], count, xnr, ynr);

this.inducesTopPath = true;
this.inducesRightPath = true;
this.inducesBottomPath = true;
this.inducesLeftPath = true;
this.inducesPaths = [true, true, true, true];
};

this.setBase = function() {
Expand Down
3 changes: 1 addition & 2 deletions js/verttile.js
Expand Up @@ -6,8 +6,7 @@
orbium.Tile.prototype.construct.call(this, ["verttile"+x], count,
xnr, ynr);

this.inducesTopPath = true;
this.inducesBottomPath = true;
this.inducesPaths = [true, false, true, false];
};

this.construct.apply(this, arguments);
Expand Down

0 comments on commit f9140a9

Please sign in to comment.