2D Maze Loader and 3D Conversion by puzzler201824th Jul 2018 7:18
|
---|
Summary This will load a previous saved Maze Generated and convert to 3D - Use the Generator and Loader first Description Enjoy! Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com [code] // Project: maze gen v3 // Created: 2018-07-06 // show all errors SetErrorMode(2) #constant swidth = 1024 #constant sheight = 768 #constant white = MakeColor(0,0,255) #constant green = MakeColor(0,255,0) #constant blue = MakeColor(0,0,255) #constant black = MakeColor(0,0,0) #constant wallheight = 3 // set window properties SetWindowTitle( "3D maze loader" ) SetWindowSize( swidth, sheight, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( swidth, sheight ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts global cols,rows,width type _cells ObjID x,y walls as integer[3] visited current direction endtype global cells as _cells[] global emptycell as _cells global stack as _cells[] global stackcount, completed=0 global current=0 loadmaze("Level1.Dat") plane = CreateObjectPlane(1000,1000) SetObjectRotation(plane,90,0,0) SetObjectColor(plane,0,200,0,255) wall = CreateObjectBox(1,wallheight,1) for a=0 to cells.length if cells[a].walls[0] = 1 // top or bottom cells[a].ObjID = InstanceObject(wall) SetObjectPosition(cells[a].ObjID, cells[a].x*4, 1, cells[a].y*4-2) // SetObjectRotation(cells[a].ObjID, 0,90,0) SetObjectScale(cells[a].ObjID, 4,1,1) endif if cells[a].walls[2] = 1 // top or bottom cells[a].ObjID = InstanceObject(wall) SetObjectPosition(cells[a].ObjID, cells[a].x*4, 1, cells[a].y*4+2) // SetObjectRotation(cells[a].ObjID, 0,90,0) SetObjectScale(cells[a].ObjID, 4,1,1) endif if cells[a].walls[1] = 1 // left or right cells[a].ObjID = InstanceObject(wall) SetObjectPosition(cells[a].ObjID, cells[a].x*4+2, 1, cells[a].y*4) SetObjectRotation(cells[a].ObjID, 0,90,0) SetObjectScale(cells[a].ObjID,4,1,1) endif if cells[a].walls[3] = 1 // left or right cells[a].ObjID = InstanceObject(wall) SetObjectPosition(cells[a].ObjID, cells[a].x*4-2, 1, cells[a].y*4) SetObjectRotation(cells[a].ObjID, 0,90,0) SetObjectScale(cells[a].ObjID,4,1,1) endif next cx# = 0 : cy# = 10: cz# = -10 do if viewmaze=1 for x=0 to cells.length xx = cells[x].x * width yy = cells[x].y * width if cells[x].walls[0]=1 then DrawLine(xx ,yy ,xx+width, yy ,white,white) if cells[x].walls[1]=1 then DrawLine(xx+width,yy ,xx+width, yy+width,white,white) if cells[x].walls[2]=1 then DrawLine(xx+width,yy+width,xx , yy+width,white,white) if cells[x].walls[3]=1 then DrawLine(xx ,yy+width,xx , yy ,white,white) next DrawBox(cells[current].x * width+2 ,cells[current].y * width+2 ,cells[current].x * width+width-2 ,cells[current].y * width+width - 2,blue,blue,blue,blue,1) endif if GetRawKeyState(87) then inc cz#,.2 if GetRawKeyState(83) then dec cz#,.2 if GetRawKeyState(65) then dec cx#,.2 if GetRawKeyState(68) then inc cx#,.2 if GetRawKeyState(38) then inc cy#,.2 if GetRawKeyState(40) then dec cy#,.2 if GetRawKeyPressed(86) if viewmaze=1 viewmaze=0 else viewmaze = 1 endif endif SetCameraPosition(1, cx#, cy#, cz#) print ("Use WASD and UP and DOWN to move around") print ("Press 'V' to view the 2D Maze") Sync() sleep(0) loop function loadmaze(mazefile as string) loadfile = OpenToRead(mazefile) length = ReadInteger(loadfile) width = ReadInteger(loadfile) cells.length = length for loops = 0 to length cells[loops].x = ReadInteger(loadfile) cells[loops].y = ReadInteger(loadfile) cells[loops].walls[0] = ReadInteger(loadfile) cells[loops].walls[1] = ReadInteger(loadfile) cells[loops].walls[2] = ReadInteger(loadfile) cells[loops].walls[3] = ReadInteger(loadfile) next CloseFile(loadfile) endfunction [/code] |