3D Virtual Reality MazeKeith Ballard253 Honors Spring 2009restart:with(Maplets[Tools]): with(Maplets[Elements]): with(plots):
StartEngine();
randomize():lightcyan:="#DDFFFF":
ColorFooter:=lightcyan:
FontFooter:=Font("helvetica",10):WallDepth:=12:
rand12:=rand(1..2):correctVec:=[rand12(),rand12(),rand12(),rand12(),rand12()]:currentVec:=[0,0,0,0,0]:correctColors:=["Red", "Orange", yellow, green, blue, magenta]:leftColor:=black:rightColor:=black:backColor:=correctColors[1]:moveCount:=0:PlotHall:=proc(lWall,rWall,bWall,depth)
local lowerYEnd, upperYEnd, wallLength,leftWallEnd, rightWallEnd, BWallDepth, enviroment;
upperYEnd:=(wallLength)->11-wallLength*.3;
lowerYEnd:=(wallLength)->1+wallLength*.3;
leftWallEnd:=(wallLength)->.45*wallLength;
rightWallEnd:=(wallLength)->14-.45*wallLength;
if depth>3 then
BWallDepth:=depth+1/depth*20;
else
BWallDepth:=depth+5;
end if;
if moveCount=5 then
BWallDepth:=depth;
end if;
if depth>-1 then
enviroment:=plot([
[[0,0],[0,1],[leftWallEnd(depth),lowerYEnd(depth)],[leftWallEnd(depth),0],[0,0]],
[[14,0],[14,1],[rightWallEnd(depth),lowerYEnd(depth)],[rightWallEnd(depth),0],[0,0]],
[[0,1],[0,11],[leftWallEnd(depth),upperYEnd(depth)],[leftWallEnd(depth),lowerYEnd(depth)]],
[[14,1],[14,11],[rightWallEnd(depth),upperYEnd(depth)],[rightWallEnd(depth),lowerYEnd(depth)]],
[[leftWallEnd(depth),0],[leftWallEnd(depth),lowerYEnd(BWallDepth)],
[rightWallEnd(depth),lowerYEnd(BWallDepth)],[rightWallEnd(depth),0],[leftWallEnd(BWallDepth),0]],
[[leftWallEnd(depth),lowerYEnd(BWallDepth)],[leftWallEnd(depth),upperYEnd(BWallDepth)],
[rightWallEnd(depth),upperYEnd(BWallDepth)],[rightWallEnd(depth),lowerYEnd(BWallDepth)]],
[[0,0],[0,12],[14,12],[14,0],[0,0]]
],
x=0..14,y=0..12,filled=true,color=["DarkGray","DarkGray",lWall,rWall,"DarkGray",bWall,"LightGray"],axes=none);
Set(myplot=enviroment);
end if;
end proc:moveForward:=proc()
global WallDepth, correctColors, leftColor, rightColor, moveCount, backColor;
if WallDepth>0 then
WallDepth:=WallDepth - 3;
end if;
Set(Lrestarted(caption)=" ");
PlotHall(leftColor,rightColor,backColor,WallDepth);
if moveCount<>5 then
if WallDepth=0 then
Set(Bleft(enabled)=true);
Set(Bright(enabled)=true);
Set(Bforward(enabled)=false);
end if;
end if;
if moveCount=5 then
Set(Bleft(enabled)=false);
Set(Bright(enabled)=false);
Set(Bforward(enabled)=false);
end if;
end proc:moveLeft:=proc()
global moveCount, currentVec, correctVec, WallDepth, correctColors, leftColor, rightColor, backColor;
moveCount:=moveCount+1;
currentVec[moveCount]:=1;
WallDepth:=9;
rightColor:=backColor;
if currentVec[moveCount]=correctVec[moveCount] then
backColor:=correctColors[moveCount+1];
Set(Bforward(enabled)=true);
else
backColor:="Black";
Set(Afailure(run)=true);
Set(Bforward(enabled)=false);
end if;
PlotHall(leftColor,rightColor,backColor,WallDepth);
Set(Bleft(enabled)=false);
Set(Bright(enabled)=false);
if moveCount=5 and currentVec=correctVec then
Set(Asuccess(run)=true);
Set(Bforward(enabled)=false);
end if;
end proc:moveRight:=proc()
global moveCount, currentVec, correctVec, WallDepth, correctColors, leftColor, rightColor, backColor;
moveCount:=moveCount+1;
currentVec[moveCount]:=2;
WallDepth:=9;
leftColor:=backColor;
if currentVec[moveCount]=correctVec[moveCount] then
backColor:=correctColors[moveCount+1];
Set(Bforward(enabled)=true);
else
backColor:="Black";
Set(Afailure(run)=true);
Set(Bforward(enabled)=false);
end if;
PlotHall(leftColor,rightColor,backColor,WallDepth);
Set(Bleft(enabled)=false);
Set(Bright(enabled)=false);
if moveCount=5 and currentVec=correctVec then
Set(Asuccess(run)=true);
Set(Bforward(enabled)=false);
end if;
end proc:
restartProc:=proc()
global WallDepth, correctColors, leftColor, rightColor, moveCount, currentVec, backColor;
currentVec:=[0,0,0,0,0]:
leftColor:=black:
rightColor:=black:
backColor:=correctColors[1]:
moveCount:=0:
WallDepth:=9;
Set(Arestart(run)=true);
PlotHall(leftColor,rightColor,backColor,WallDepth);
Set(Bforward(enabled)=true);
end proc:VR3DMaze:=Maplet(onstartup = Astart,
Window[MAIN](title="3D Virtual Reality Maze",
[ ["Follow the spectrum. If you do not succeed, remember your steps and press the restart button."],
[Plotter[myplot](width=630, height=500, play=true)],
[ halign=none,
Button[Brestart]("Restart", Evaluate(function = "restartProc"),
background=magenta),
Label[Lrestarted](" "),
HorizontalGlue(),
Button[Bleft]("< Left", Evaluate(function = "moveLeft"),
background=cyan, enabled=false),
Button[Bforward]("Forward", Evaluate(function = "moveForward"),
background=cyan, enabled=true),
Button[Bright]("Right >", Evaluate(function = "moveRight"),
background=cyan, enabled=false),
HorizontalGlue(),
" ",
Button[Bquit]("Quit", Shutdown(), background=pink)
],
[ halign=none, background=ColorFooter,
Label("Programmer: Keith Ballard", font=FontFooter),
HorizontalGlue(),
Label("Copyright: P. Yasskin 2009", font=FontFooter)
]
]
),
MessageDialog[Success](title="Good Job!",caption="Congratulations, you have successfully completed the maze."),
MessageDialog[Failure](title="Sorry",caption="You have unsuccessfully navigated the maze. Please try again."),
Action[Astart](RunWindow(MAIN), Evaluate(function = "moveForward")),
Action[Arestart](SetOption(Lrestarted(caption)="Restarted")),
Action[Asuccess](RunDialog(Success)),
Action[Afailure](RunDialog(Failure))
):Maplets[Display]( VR3DMaze );