[Tools][Expand/Collapse All]Note that automatic extraction of ActionScript 3 is still pretty much unsupported by swfchan. AS1/AS2 works okay most of the time.Frame 1 (456 B)
function statemachine(currentstate) {
switch (currentstate) {
case "menu" :
attachMovie("movMenu", "attachedmov", 1);
break;
case "game" :
attachMovie("movGame", "attachedmov", 1, {diff:difficulty});
break;
case "lose" :
attachMovie("movLose", "attachedmov", 1);
break;
case "win" :
attachMovie("movWin", "attachedmov", 1);
}
}
stop();
difficulty = 0;
currentstate = "menu";
statemachine(currentstate);
Symbol 22 MovieClip [treasure] Frame 1 (8 B)
stop();
Symbol 23 MovieClip [dragon] Frame 1 (8 B)
stop();
Symbol 25 MovieClip [base] Frame 1 (8 B)
stop();
Symbol 28 MovieClip [ghost] Frame 1 (8 B)
stop();
Symbol 33 MovieClip [square] Frame 1 (75 B)
#initclip 2
Object.registerClass("square", Cell);
#endinitclip
stop();
Symbol 38 MovieClip [dude] Frame 1 (8 B)
stop();
Symbol 42 MovieClip [squareNext] Frame 1 (8 B)
stop();
Symbol 49 MovieClip Frame 1 (8 B)
stop();
Symbol 50 MovieClip Frame 1 (8 B)
stop();
Symbol 52 MovieClip Frame 1 (8 B)
stop();
Symbol 57 MovieClip [speechbubble] Frame 40 (8 B)
stop();
Symbol 62 MovieClip Frame 1 (8 B)
stop();
Symbol 63 MovieClip [movgame] Frame 1 (13.66 KiB) ● ●
function randRange(min, max) {
var _local1 = Math.floor(Math.random() * ((max - min) + 1)) + min;
return(_local1);
}
function shuffle(a) {
var _local3;
var _local2;
i = 0;
while (i < a.length) {
_local2 = randRange(0, a.length - 1);
_local3 = a[i];
a[i] = a[_local2];
a[_local2] = _local3;
i++;
}
}
function manhattandist(r1, c1, r2, c2) {
return(Math.abs(r1 - r2) + Math.abs(c1 - c2));
}
function buildboard() {
row = 0;
while (row <= 7) {
col = 0;
while (col <= 7) {
var _local2 = (row * 8) + col;
sqref = this.attachMovie("square", ("sq" + row) + col, _local2, {_x:40 + (col * 40), _y:40 + (row * 40), row:row, col:col});
sqref.onRelease = clickcell;
sqref.attachMovie("flagstone", ("flag" + row) + col, sqref.getNextHighestDepth(), {_x:20, _y:20, _rotation:quadrants[(row + col) % 4]});
boardarr[row][col] = sqref;
col++;
}
row++;
}
this.attachMovie("base", "baseclip", this.getNextHighestDepth());
this.attachMovie("dude", "dudeclip", this.getNextHighestDepth());
this.attachMovie("treasure", "treasureclip", this.getNextHighestDepth());
this.attachMovie("ghost", "ghostclip", this.getNextHighestDepth());
}
function resetmaze() {
wallcount = 112;
row = 0;
while (row <= 7) {
col = 0;
while (col <= 7) {
if (boardarr[row][col].treasureroom != undefined) {
boardarr[row][col].treasureroom.removeMovieClip();
}
boardarr[row][col].resetcell();
col++;
}
row++;
}
}
function carvestep() {
resetmaze();
startrow = randRange(0, 7);
startcol = randRange(0, 7);
boardarr[startrow][startcol].see();
carved.push([startrow, startcol]);
var _local3 = [];
var _local1;
var _local2;
while (carved.length > 0) {
var _local4;
_local4 = randRange(0, carved.length - 1);
_local1 = carved[_local4][0];
_local2 = carved[_local4][1];
_local3 = [];
if ((_local1 > 0) and (boardarr[_local1 - 1][_local2].seen == false)) {
_local3.push("n");
}
if ((_local1 < 7) and (boardarr[_local1 + 1][_local2].seen == false)) {
_local3.push("s");
}
if ((_local2 > 0) and (boardarr[_local1][_local2 - 1].seen == false)) {
_local3.push("w");
}
if ((_local2 < 7) and (boardarr[_local1][_local2 + 1].seen == false)) {
_local3.push("e");
}
if (_local3.length == 0) {
carved.splice(_local4, 1);
} else {
shuffle(_local3);
switch (_local3[0]) {
case "n" :
boardarr[_local1][_local2].breakwall("n");
boardarr[_local1 - 1][_local2].breakwall("s");
boardarr[_local1 - 1][_local2].see();
carved.push([_local1 - 1, _local2]);
break;
case "e" :
boardarr[_local1][_local2].breakwall("e");
boardarr[_local1][_local2 + 1].breakwall("w");
boardarr[_local1][_local2 + 1].see();
carved.push([_local1, _local2 + 1]);
break;
case "s" :
boardarr[_local1][_local2].breakwall("s");
boardarr[_local1 + 1][_local2].breakwall("n");
boardarr[_local1 + 1][_local2].see();
carved.push([_local1 + 1, _local2]);
break;
case "w" :
boardarr[_local1][_local2].breakwall("w");
boardarr[_local1][_local2 - 1].breakwall("e");
boardarr[_local1][_local2 - 1].see();
carved.push([_local1, _local2 - 1]);
}
wallcount--;
}
}
i = 0;
while (i <= 14) {
viable = 0;
do {
_local1 = randRange(0, 7);
_local2 = randRange(0, 7);
side = sides[randRange(0, 3)];
if (((((_local1 == 0) and (side == "n")) or ((_local1 == 7) and (side == "s"))) or ((_local2 == 0) and (side == "w"))) or ((_local2 == 7) and (side == "e"))) {
viable = 0;
} else if (((((side == "n") and (boardarr[_local1][_local2].n == 0)) or ((side == "e") and (boardarr[_local1][_local2].e == 0))) or ((side == "s") and (boardarr[_local1][_local2].s == 0))) or ((side == "w") and (boardarr[_local1][_local2].w == 0))) {
viable = 0;
} else {
viable = 1;
}
} while (viable == 0);
switch (side) {
case "n" :
boardarr[_local1][_local2].breakwall("n");
boardarr[_local1 - 1][_local2].breakwall("s");
break;
case "e" :
boardarr[_local1][_local2].breakwall("e");
boardarr[_local1][_local2 + 1].breakwall("w");
break;
case "s" :
boardarr[_local1][_local2].breakwall("s");
boardarr[_local1 + 1][_local2].breakwall("n");
break;
case "w" :
boardarr[_local1][_local2].breakwall("w");
boardarr[_local1][_local2 - 1].breakwall("e");
}
wallcount--;
i++;
}
initialize();
}
function taketurn(ref) {
rowdelta = ref.row - playerrow;
coldelta = ref.col - playercol;
if (baserow < 0) {
baserow = ref.row;
playerrow = ref.row;
basecol = ref.col;
playercol = ref.col;
dudeclip._x = ref._x;
dudeclip._y = ref._y;
dudeclip._visible = true;
baseclip._x = ref._x;
baseclip._y = ref._y;
baseclip._visible = true;
do {
treasurerow = randRange(0, 7);
treasurecol = randRange(0, 7);
} while (manhattandist(playerrow, playercol, treasurerow, treasurecol) < 6);
soundqueue.push("tik");
} else if (((endingturn == true) or ((Math.abs(rowdelta) == 1) and (Math.abs(coldelta) == 0))) or ((Math.abs(rowdelta) == 0) and (Math.abs(coldelta) == 1))) {
if ((rowdelta == -1) and (boardarr[ref.row][ref.col].s == 1)) {
boardarr[ref.row][ref.col].showwall("s");
boardarr[ref.row + 1][ref.col].showwall("n");
usedsteps = maxsteps;
soundqueue.push("hitawall");
} else if ((rowdelta == 1) and (boardarr[ref.row][ref.col].n == 1)) {
boardarr[ref.row][ref.col].showwall("n");
boardarr[ref.row - 1][ref.col].showwall("s");
usedsteps = maxsteps;
soundqueue.push("hitawall");
} else if ((coldelta == -1) and (boardarr[ref.row][ref.col].e == 1)) {
boardarr[ref.row][ref.col].showwall("e");
boardarr[ref.row][ref.col + 1].showwall("w");
usedsteps = maxsteps;
soundqueue.push("hitawall");
} else if ((coldelta == 1) and (boardarr[ref.row][ref.col].w == 1)) {
boardarr[ref.row][ref.col].showwall("w");
boardarr[ref.row][ref.col - 1].showwall("e");
usedsteps = maxsteps;
soundqueue.push("hitawall");
} else {
playerrow = ref.row;
playercol = ref.col;
usedsteps = usedsteps + 1;
soundqueue.push("tik");
if ((dragonrow < 0) and (manhattandist(playerrow, playercol, treasurerow, treasurecol) <= 3)) {
dragonrow = treasurerow;
dragoncol = treasurecol;
soundqueue.push("ghostawakes");
}
if ((playerrow == treasurerow) and (playercol == treasurecol)) {
if (carrying == false) {
soundqueue.push("foundtreasure");
carrying = true;
maxsteps = 4;
usedsteps = 4;
if (ref.treasureroom == undefined) {
ref.attachMovie("treasure", "treasureroom", 20, {_x:0, _y:0});
ref.treasureroom._alpha = 30;
}
}
}
if (((playerrow == dragonrow) and (playercol == dragoncol)) and ((playerrow != baserow) or (playercol != basecol))) {
lives = lives - 1;
playerrow = baserow;
playercol = basecol;
maxsteps = maxsteplist[lives];
usedsteps = 0;
carrying = false;
soundqueue.push("ghostattacks");
}
if (((carrying == true) and (playerrow == baserow)) and (playercol == basecol)) {
lives = 0;
soundqueue.push("youwin");
}
}
if ((usedsteps == maxsteps) or (endingturn == true)) {
if ((dragonrow >= 0) and (lives > 0)) {
if ((playerrow == baserow) and (playercol == basecol)) {
if ((dragonrow != treasurerow) or (dragoncol != treasurecol)) {
soundqueue.push("ghostmoves");
}
if (dragonrow < treasurerow) {
dragonrow++;
}
if (dragonrow > treasurerow) {
dragonrow--;
}
if (dragoncol < treasurecol) {
dragoncol++;
}
if (dragoncol > treasurecol) {
dragoncol--;
}
} else {
if ((dragonrow != playerrow) or (dragoncol != playercol)) {
soundqueue.push("ghostmoves");
}
if (dragonrow < playerrow) {
dragonrow++;
}
if (dragonrow > playerrow) {
dragonrow--;
}
if (dragoncol < playercol) {
dragoncol++;
}
if (dragoncol > playercol) {
dragoncol--;
}
}
if ((dragonrow == playerrow) and (dragoncol == playercol)) {
if ((playerrow == baserow) and (playercol == basecol)) {
} else if ((carrying == true) and (!((playerrow == treasurerow) and (playercol == treasurecol)))) {
lives = 0;
soundqueue.push("ghostattacks");
} else {
lives = lives - 1;
playerrow = baserow;
playercol = basecol;
maxsteps = maxsteplist[lives];
carrying = false;
soundqueue.push("ghostattacks");
}
}
}
usedsteps = 0;
endingturn = false;
}
if (lives == 0) {
soundqueue.push("gameover");
}
} else {
soundqueue.push("no");
}
printsteps();
}
function printsteps() {
if (soundqueue.length > 0) {
soundplaying = true;
var _local1 = soundqueue[0];
soundqueue.shift();
beep.attachSound((soundprefix + _local1) + ".wav");
beep.onSoundComplete = printsteps;
beep.start();
bub.bubbletxt.text = soundcaptions[_local1];
bub._visible = true;
bub.gotoAndPlay(1);
} else {
soundplaying = false;
bub._visible = false;
}
dudecountdown.gotoAndStop(lives + 1);
stepcountdown.gotoAndStop(maxstepframes[maxsteps] - usedsteps);
dudeclip._x = (playercol * 40) + 40;
dudeclip._y = (playerrow * 40) + 40;
treasureclip._x = dudeclip._x + 16;
treasureclip._y = dudeclip._y - 22;
if (carrying) {
treasureclip._visible = true;
} else {
treasureclip._visible = false;
}
}
function initialize() {
playerrow = -1;
playercol = -1;
baserow = -1;
basecol = -1;
treasurerow = -1;
treasurecol = -1;
dragonrow = -1;
dragoncol = -1;
ghostrow = -1;
ghostcol = -1;
baseclip._visible = false;
dudeclip._visible = false;
treasureclip._visible = false;
ghostclip._x = 400;
ghostclip._y = 215;
lives = 3;
usedsteps = 0;
maxsteps = 8;
carrying = false;
endingturn = false;
dudecountdown.gotoAndStop(1);
bub._visible = false;
}
function clickcell() {
if (soundplaying == false) {
if (lives > 0) {
taketurn(this);
}
}
}
stop();
var beep = new Sound();
var quadrants = [0, 90, 180, 270];
var maxsteplist = [0, 4, 6, 8];
var maxstepframes = new Object();
maxstepframes[8] = 28;
maxstepframes[6] = 17;
maxstepframes[4] = 6;
maxstepframes[0] = 1;
var boardarr = [[], [], [], [], [], [], [], []];
var carved = [];
var wallcount = 115;
var sides = ["n", "e", "s", "w"];
var soundqueue = [];
var soundplaying = false;
var endingturn = false;
var soundprefix = "sayit-";
var soundcaptions = {tik:"Tick.", no:"No.", hitawall:"Ouch.", ghostmoves:"Ghost moves.", ghostawakes:"Ghost awakes!", ghostattacks:"Ghost attacks!", gameover:"Game over.", youwin:"You win!", foundtreasure:"Found treasure!"};
buildboard();
carvestep();
var playerrow;
var playercol;
var baserow;
var basecol;
var treasurerow;
var treasurecol;
var dragonrow;
var dragoncol;
var ghostrow;
var ghostcol;
var lives;
var usedsteps;
var maxsteps;
var carrying;
btnReset.debugtxt.text = "Reset";
btnReset.onRelease = carvestep;
btnExit.debugtxt.text = "Exit";
btnExit.onRelease = function () {
_parent.statemachine("menu");
};
btnEndturn.onRelease = function () {
if (soundplaying == false) {
if (((lives > 0) and (baserow > -1)) and (basecol > -1)) {
endingturn = true;
taketurn(boardarr[playerrow][playercol]);
}
}
};
voiceswitch.onRelease = function () {
if (soundprefix == "nat-") {
soundprefix = "sayit-";
voiceswitch.gotoAndStop(1);
} else {
soundprefix = "nat-";
voiceswitch.gotoAndStop(2);
}
};
var keyListener = new Object();
keyListener.onKeyDown = function () {
switch (Key.getCode()) {
case 32 :
if ((soundplaying == false) and (lives > 0)) {
btnEndturn.onRelease();
}
return;
case 8 :
if (soundplaying == false) {
carvestep();
}
return;
case 37 :
if (((soundplaying == false) and (lives > 0)) and (playercol > 0)) {
taketurn(boardarr[playerrow][playercol - 1]);
}
return;
case 38 :
if (((soundplaying == false) and (lives > 0)) and (playerrow > 0)) {
taketurn(boardarr[playerrow - 1][playercol]);
}
return;
case 39 :
if (((soundplaying == false) and (lives > 0)) and (playercol < 7)) {
taketurn(boardarr[playerrow][playercol + 1]);
}
return;
case 40 :
if (((soundplaying == false) and (lives > 0)) and (playerrow < 7)) {
taketurn(boardarr[playerrow + 1][playercol]);
}
return;
case 68 :
if ((ghostcol != -1) && (ghostcol < 8)) {
ghostclip._x = ghostclip._x + 40;
ghostcol = ghostcol + 1;
}
return;
case 65 :
if ((ghostcol != -1) && (ghostcol > 1)) {
ghostclip._x = ghostclip._x - 40;
ghostcol = ghostcol - 1;
}
return;
case 83 :
if ((ghostrow != -1) && (ghostrow < 8)) {
ghostclip._y = ghostclip._y + 40;
ghostrow = ghostrow + 1;
}
return;
case 87 :
if (!((ghostrow != -1) && (ghostrow > 1))) {
break;
}
ghostclip._y = ghostclip._y - 40;
ghostrow = ghostrow - 1;
}
};
Key.addListener(keyListener);
ghostclip.onPress = function () {
this.startDrag();
};
ghostclip.onRelease = function () {
this.stopDrag();
if ((((this._x > 20) and (this._x < 340)) and (this._y > 20)) and (this._y < 340)) {
ghostcol = Math.floor((this._x + 20) / 40);
this._x = ghostcol * 40;
ghostrow = Math.floor((this._y + 20) / 40);
this._y = ghostrow * 40;
} else {
this._x = 400;
this._y = 215;
ghostrow = -1;
ghostcol = -1;
}
};
Symbol 64 MovieClip [movMenu] Frame 1 (361 B)
stop();
btnAbout.debugtxt.text = "About";
btnAbout.onRelease = function () {
_parent.attachMovie("movAbout", "dialog", 2, {_x:51, _y:84});
};
btnHelp.debugtxt.text = "Help";
btnHelp.onRelease = function () {
_parent.attachMovie("movInstructions", "dialog", 2, {_x:51, _y:34});
};
btnPlay.onRelease = function () {
_parent.statemachine("game");
};
Symbol 76 MovieClip [movAbout] Frame 1 (110 B)
stop();
btnOK.debugtxt.text = "OK";
btnOK.onRelease = function () {
_parent.dialog.removeMovieClip();
};
Symbol 82 MovieClip [movInstructions] Frame 1 (110 B)
stop();
btnOK.debugtxt.text = "OK";
btnOK.onRelease = function () {
_parent.dialog.removeMovieClip();
};
Symbol 83 MovieClip [__Packages.Cell] Frame 0 (2.38 KiB) ●
class Cell extends MovieClip
{
var nclip, attachMovie, eclip, sclip, wclip, n, e, s, w, seen, debugtxt, col, row;
function Cell () {
super();
nclip = attachMovie("wall", "northwall", 0, {_x:20, _y:0});
eclip = attachMovie("wall", "eastwall", 1, {_x:40, _y:20, _rotation:-90});
sclip = attachMovie("wall", "southwall", 2, {_x:20, _y:40});
wclip = attachMovie("wall", "westwall", 3, {_x:0, _y:20, _rotation:-90});
resetcell();
}
function buildwall(wallname) {
switch (wallname) {
case "n" :
n = 1;
break;
case "e" :
e = 1;
break;
case "s" :
s = 1;
break;
case "w" :
w = 1;
}
}
function breakwall(wallname) {
switch (wallname) {
case "n" :
n = 0;
hidewall("n");
break;
case "e" :
e = 0;
hidewall("e");
break;
case "s" :
s = 0;
hidewall("s");
break;
case "w" :
w = 0;
hidewall("w");
}
}
function showwall(wallname) {
switch (wallname) {
case "n" :
nclip._visible = true;
nclip._alpha = 100;
break;
case "e" :
eclip._visible = true;
eclip._alpha = 100;
break;
case "s" :
sclip._visible = true;
sclip._alpha = 100;
break;
case "w" :
wclip._visible = true;
wclip._alpha = 100;
}
}
function ghostwall(wallname) {
switch (wallname) {
case "n" :
nclip._visible = true;
nclip._alpha = 10;
break;
case "e" :
eclip._visible = true;
eclip._alpha = 10;
break;
case "s" :
sclip._visible = true;
sclip._alpha = 10;
break;
case "w" :
wclip._visible = true;
wclip._alpha = 10;
}
}
function hidewall(wallname) {
switch (wallname) {
case "n" :
nclip._visible = false;
break;
case "e" :
eclip._visible = false;
break;
case "s" :
sclip._visible = false;
break;
case "w" :
wclip._visible = false;
}
}
function see() {
seen = true;
}
function resetcell() {
buildwall("n");
hidewall("n");
buildwall("e");
hidewall("e");
buildwall("s");
hidewall("s");
buildwall("w");
hidewall("w");
seen = false;
debugtxt.text = "";
}
function toString() {
var _local2 = ((((((((((("id" + row.toString()) + col.toString()) + " n") + n) + " e") + e) + " s") + s) + " w") + w) + " seen") + seen;
return(_local2);
}
}