Instance of Symbol 28 MovieClip "screen" in Frame 1
onClipEvent (enterFrame) {
_root.main();
}
Instance of Symbol 38 MovieClip "numOfRaysSlider" in Frame 1
onClipEvent (load) {
initValue = 50;
minValue = 25;
maxValue = 100;
float = "false";
}
Instance of Symbol 38 MovieClip "fovSlider" in Frame 1
onClipEvent (load) {
initValue = 75;
minValue = 30;
maxValue = 120;
float = "false";
}
Instance of Symbol 45 MovieClip "interlaceCheckBox" in Frame 1
onClipEvent (load) {
initValue = "false";
}
Frame 2
function preCalc() {
fov_div_rays = fovAngle / numOfRays;
h_fov = fovAngle / 2;
lineWidth = imageWidth / numOfRays;
var i = 0;
while (i < numOfRays) {
dist[i] = imageHeight / Math.cos((Math.PI * ((i * fov_div_rays) - h_fov)) / 180);
var ang = ((viewAngle - h_fov) + (i * fov_div_rays));
if (ang >= 360) {
ang = ang - 360;
} else if (ang < 0) {
ang = ang + 360;
}
if ((270 < ang) || (ang < 90)) {
right[i] = true;
} else {
right[i] = false;
}
if ((0 < ang) && (ang < 180)) {
down[i] = true;
} else {
down[i] = false;
}
tAng1[i] = Math.tan(Math.PI * (ang / 180));
tAng2[i] = Math.tan(Math.PI * ((90 - ang) / 180));
tAng3[i] = Math.tan(Math.PI * ((270 - ang) / 180));
screen.attachMovie("wall", "w" + i, i + 1);
screen["w" + i]._x = Math.round(i * lineWidth);
screen["w" + i]._xscale = 100 * (Math.ceil(lineWidth) / 1);
i++;
}
var del = numOfRays;
while (screen["w" + del] != undefined) {
screen["w" + del].removeMovieClip();
del++;
}
if (interlace) {
step = 2;
} else {
step = 1;
}
strt = 0;
frames = 0;
fpsTime = 0;
}
function rayCasting() {
if (interlace) {
strt = 1 - strt;
}
var i = strt;
while (i < numOfRays) {
if (right[i]) {
var xIsect1 = (xViewMap + 1);
var tanAngle = tAng1[i];
var yIsect1 = (yView + (tanAngle * (xIsect1 - xView)));
while (((m[xIsect1][Math.floor(yIsect1)] == null) && (xIsect1 < mapWidth)) && (yIsect1 < mapHeight)) {
xIsect1++;
yIsect1 = yIsect1 + tanAngle;
}
} else {
var xIsect1 = (xViewMap - 0.01);
var tanAngle = tAng1[i];
var yIsect1 = (yView + (tanAngle * (xIsect1 - xView)));
while (((m[Math.floor(xIsect1)][Math.floor(yIsect1)] == null) && (0 < xIsect1)) && (0 < yIsect1)) {
xIsect1--;
yIsect1 = yIsect1 - tanAngle;
}
}
if (down[i]) {
var yIsect2 = (yViewMap + 1);
var tanAngle = tAng2[i];
var xIsect2 = (xView + (tanAngle * (yIsect2 - yView)));
while (((m[Math.floor(xIsect2)][yIsect2] == null) && (xIsect2 < mapWidth)) && (yIsect2 < mapHeight)) {
yIsect2++;
xIsect2 = xIsect2 + tanAngle;
}
} else {
var yIsect2 = (yViewMap - 0.01);
var tanAngle = tAng3[i];
var xIsect2 = (xView + (tanAngle * (yIsect2 - yView)));
while (((m[Math.floor(xIsect2)][Math.floor(yIsect2)] == null) && (0 < xIsect2)) && (0 < yIsect2)) {
yIsect2--;
xIsect2 = xIsect2 - tanAngle;
}
}
var v1 = (xView - xIsect1);
var v2 = (yView - yIsect1);
var dis1 = Math.sqrt((v1 * v1) + (v2 * v2));
var v1 = (xView - xIsect2);
var v2 = (yView - yIsect2);
var dis2 = Math.sqrt((v1 * v1) + (v2 * v2));
if (dis1 < dis2) {
var r = screen["w" + i];
r._height = dist[i] / dis1;
r.gotoAndStop(1 + Math.round((yIsect1 - Math.floor(yIsect1)) * 100));
r.s.gotoAndStop(1 + Math.round(dis1 * 10), 79);
r.s.t.gotoAndStop(m[Math.floor(xIsect1)][Math.floor(yIsect1)]);
} else {
var r = screen["w" + i];
r._height = dist[i] / dis2;
r.gotoAndStop(1 + Math.round((xIsect2 - Math.floor(xIsect2)) * 100));
r.s.gotoAndStop(1 + Math.round(dis2 * 10), 79);
r.s.t.gotoAndStop(m[Math.floor(xIsect2)][Math.floor(yIsect2)]);
}
i = i + step;
}
}
function main() {
if (Key.isDown(38)) {
move = 0.12;
strafe = 0;
} else if (Key.isDown(40)) {
move = -0.12;
strafe = 0;
} else {
move = 0;
}
if (Key.isDown(37)) {
if (Key.isDown(16)) {
move = 0.12;
strafe = -90;
} else {
rotate = -6;
}
} else if (Key.isDown(39)) {
if (Key.isDown(16)) {
move = 0.12;
strafe = 90;
} else {
rotate = 6;
}
} else {
rotate = 0;
}
if (move) {
newXPos = xView + (Math.cos(Math.PI * ((viewAngle + strafe) / 180)) * move);
newYPos = yView + (Math.sin(Math.PI * ((viewAngle + strafe) / 180)) * move);
if (m[Math.floor(newXPos)][Math.floor(newYPos)] == null) {
xView = newXPos;
yView = newYPos;
xViewMap = Math.floor(xView);
yViewMap = Math.floor(yView);
} else if (m[Math.floor(newXPos)][Math.floor(yView)] == null) {
xView = newXPos;
xViewMap = Math.floor(xView);
} else if (m[Math.floor(xView)][Math.floor(newYPos)] == null) {
yView = newYPos;
yViewMap = Math.floor(yView);
}
}
if (rotate) {
viewAngle = viewAngle + rotate;
if (viewAngle < 0) {
viewAngle = viewAngle + 360;
} else if (viewAngle >= 360) {
viewAngle = viewAngle - 360;
}
var i = 0;
while (i < numOfRays) {
ang = (viewAngle - h_fov) + (i * fov_div_rays);
if (ang >= 360) {
ang = ang - 360;
} else if (ang < 0) {
ang = ang + 360;
}
if ((270 < ang) || (ang < 90)) {
right[i] = true;
} else {
right[i] = false;
}
if ((0 < ang) && (ang < 180)) {
down[i] = true;
} else {
down[i] = false;
}
tAng1[i] = Math.tan(Math.PI * (ang / 180));
tAng2[i] = Math.tan(Math.PI * ((90 - ang) / 180));
tAng3[i] = Math.tan(Math.PI * ((270 - ang) / 180));
i++;
}
}
rayCasting();
if (fpsTime < getTimer()) {
if (frames == 0) {
fps = "fps: -";
} else {
fps = "fps: " + (frames / 5);
frames = 1;
}
fpsTime = getTimer() + 5000;
} else {
frames++;
}
}
function checkBoxChanged(instance) {
if (instance == interlaceCheckBox) {
interlace = interlaceCheckBox.getValue();
preCalc();
}
}
function sliderChanged(instance) {
if (instance == fovSlider) {
fovAngle = fovSlider.getValue();
preCalc();
} else if (instance == numOfRaysSlider) {
numOfRays = numOfRaysSlider.getValue();
preCalc();
}
}
_quality = "LOW";
_focusrect = false;
dist = new Array();
down = new Array();
fovAngle = 75;
fpsTime = 0;
frames = 0;
imageHeight = 240;
imageWidth = 320;
interlace = false;
m = new Array();
mapWidth = 14;
mapHeight = 16;
move = 0;
numOfRays = 64;
right = new Array();
rotate = 0;
step = 1;
strt = 0;
tAng1 = new Array();
tAng2 = new Array();
tAng3 = new Array();
xView = 2;
yView = 2.8;
xViewMap = Math.floor(xView);
yViewMap = Math.floor(yView);
viewAngle = 30;
var x = 0;
while (x < mapWidth) {
m[x] = new Array();
x++;
}
m[0][0] = 7;
m[0][1] = 7;
m[0][2] = 7;
m[0][3] = 7;
m[0][4] = 7;
m[0][5] = 7;
m[0][6] = 7;
m[0][7] = 7;
m[0][8] = 7;
m[0][9] = 7;
m[0][10] = 7;
m[1][10] = 7;
m[2][10] = 7;
m[3][10] = 7;
m[4][10] = 7;
m[5][10] = 7;
m[6][10] = 7;
m[7][10] = 7;
m[8][10] = 7;
m[9][10] = 7;
m[10][10] = 7;
m[10][9] = 7;
m[10][8] = 7;
m[10][7] = 7;
m[10][6] = 7;
m[10][5] = 7;
m[10][4] = 7;
m[10][3] = 7;
m[10][2] = 7;
m[10][1] = 7;
m[10][0] = 7;
m[9][0] = 7;
m[8][0] = 7;
m[7][0] = 7;
m[6][0] = 7;
m[5][0] = 7;
m[4][0] = 7;
m[3][0] = 7;
m[2][0] = 7;
m[1][0] = 7;
m[5][9] = 6;
m[6][9] = 1;
m[4][9] = 1;
m[7][7] = 1;
m[3][7] = 1;
m[7][5] = 1;
m[3][5] = 1;
m[7][3] = 1;
m[3][3] = 1;
numOfRaysSlider.setValue(numOfRays);
fovSlider.setValue(fovAngle);
interlaceCheckBox.setValue(interlace);
preCalc();
_root.attachMovie("startScreen", "startScreen", 1);
startScreen._x = 160;
startScreen._y = 20;
Frame 3
stop();
Instance of Symbol 28 MovieClip in Symbol 29 MovieClip [startScreen] Frame 1
onClipEvent (mouseDown) {
_parent.removeMovieClip();
}
onClipEvent (keyDown) {
_parent.removeMovieClip();
}
Symbol 38 MovieClip Frame 1
function newValue() {
setValue(minValue + ((_xmouse / border._width) * (maxValue - minValue)));
_root.sliderChanged(this);
}
function getValue() {
return(value);
}
function setValue(newVal) {
if (!float) {
newVal = Math.round(newVal);
}
newVal = Math.min(newVal, maxValue);
newVal = Math.max(newVal, minValue);
value = newVal;
marker._x = ((value - minValue) / (maxValue - minValue)) * border._width;
}
if (value == undefined) {
setValue(initValue);
}
Instance of Symbol 35 MovieClip "border" in Symbol 38 MovieClip Frame 1
onClipEvent (mouseDown) {
if (this.hitTest(_parent._parent._xmouse, _parent._parent._ymouse, false) || (_parent.marker.hitTest(_parent._parent._xmouse, _parent._parent._ymouse, false))) {
_parent.newValue();
mouseIsDown = true;
}
}
onClipEvent (mouseUp) {
mouseIsDown = false;
}
onClipEvent (mouseMove) {
if (mouseIsDown) {
_parent.newValue();
}
}
Symbol 45 MovieClip Frame 1
function newValue() {
setValue(!value);
_root.checkBoxChanged(this);
}
function getValue() {
return(value);
}
function setValue(newVal) {
value = newVal;
checked._visible = value;
}
if (value == undefined) {
setValue(initValue);
}
Instance of Symbol 42 MovieClip "border" in Symbol 45 MovieClip Frame 1
onClipEvent (mouseDown) {
if (this.hitTest(_parent._parent._xmouse, _parent._parent._ymouse, false)) {
_parent.newValue();
}
}