Code: Select all
;Free to use and abuse. Love, Jag.
Enumeration
#F5key
EndEnumeration
Declare generate_map()
OpenWindow(0, 0, 0, 600, 600, "map gen", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
AddKeyboardShortcut(0, #PB_Shortcut_F5, #F5key)
BindEvent(#PB_Event_Menu, @generate_map(), 0, #F5key)
Procedure generate_map()
X = (WindowWidth(0)/2)
Y = (WindowHeight(0)/2)
line_x = X
line_y = Y
StartDrawing(WindowOutput(0))
Box(0,0,600,600,$000000) ; background for contrast
StopDrawing()
Repeat
If StartDrawing(WindowOutput(0))
dir = Random(4,1) ; Change to 8 for diagonal
If dir <> last_dir
Select dir
Case 1 ; north
line_y - 20
Case 2 ; east
line_x + 20
Case 3 ; south
line_y + 20
Case 4 ; west
line_x - 20
Case 5 ; northeast
line_y - 20 : line_x + 20
Case 6 ; southeast
line_x + 20 : line_y + 20
Case 7 ; southwest
line_y + 20 : line_x - 20
Case 8 ; northwest
line_y - 20 : line_x - 20
EndSelect
LineXY(x,y,line_x,line_y,$00FFFF)
Box(X-7,Y-7,15,15,$FF0000)
x = line_x
y = line_y
EndIf
last_dir = dir
StopDrawing()
EndIf
l + 1
Until l = 140 ; number of iterations. Won't produce exact as there is no overlap check
EndProcedure
generate_map()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End