2D Maze Generator Loader by puzzler201824th Jul 2018 7:16
|
---|
Summary This is will a level1.dat file (or what ever you choose - this will load from a previously saved 2D Generated Maze Description See a previous post for the Maze Generator and Save 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 = 800 #constant sheight = 600 #constant white = MakeColor(255,255,255) #constant green = MakeColor(0,255,0) #constant blue = MakeColor(0,0,255) #constant black = MakeColor(0,0,0) // set window properties SetWindowTitle( "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 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") do for x=0 to cells.length xx = cells[x].x * width yy = cells[x].y * width if completed=0 and cells[x].visited = 1 then DrawBox(xx ,yy ,xx+width, yy+width,green,green,green,green,1) 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) 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] |