Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex_Maze
#1
This is Hex_Maze version 0B. It generates a crude labyrinth using hexes as cells as opposed to a standard orthogonal square grid.
There are a couple subs in it that don't get used in this run but would prove useful in using the hex-grid in a program.


 
Code: (Select All)
'hex_maze
'by James D. Jarvis   Mar. 14,2023
' geneate a haex "maze" in a hex grid as opposed to a more standard orthogonal square grid
'generates a new hexmaze on a keypress press q to exit
Screen _NewImage(1100, 600, 32)
_FullScreen _SquarePixels , _Smooth
Randomize Timer
Dim Shared hexradius
Dim Shared hexborder As _Unsigned Long
hexborder = _RGB32(100, 100, 100)
hexradius = 8 'can be any value but draws cleaner if radius is evenly divisible by 4
maxx = 80: maxy = 40 'maxx is the maxximum number  of columns    and maxy is the maximum height of a column
Dim Shared map(maxx, maxy)
Dim Shared hgrid(0 To maxx + 1, 0 To maxy + 1, 6)
Do
    Cls
    For y = 1 To maxy
        For x = 1 To maxx
            map(x, y) = 1
        Next x
    Next y

    sx = Int(maxx / 5 + Rnd * maxx / 2)
    sy = Int(maxy / 5 + Rnd * maxy / 2)
    'map(sx, sy) = 0
    lastgo = Int(1 + Rnd * 6)
    c = 0
    clim = 600 + Int((1 + Rnd * 4) * (Rnd * (maxx + maxy))) 'determine how many hex cells will be dug for this hex maze   haven't found an ideal ratio yet
    hrun = 7
    lasthrun = Int(1 + Rnd * 3)
    Do
        'generate hex maze with a drunken wanderer method. Not a true maze but it will work for a shoot-n-scoot or a roguelike
        dgo = Int(1 + Rnd * 8) 'generate direction to send the tunnel
        hrun = Int(1 + Rnd * (2 + Sqr(maxy))) 'generate a length  for the tunnel being dug
        If hrun > Sqr(maxy) Then hrun = lasthrun
        If sx = 2 And dgo = 5 Then dgo = 3
        If sx = 2 And dgo = 6 Then dgo = 2
        If dgo > 6 Then dgo = lastgo
        For hgo = 1 To hrun
            Select Case dgo
                Case 1
                    If sy - 1 > 1 Then
                        sy = sy - 1
                    End If
                Case 2
                    If sx + 1 < maxx Then
                        If sx Mod 2 Then
                            If sy - 1 > 1 Then
                                sx = sx + 1
                                sy = sy - 1
                            End If
                        Else
                            sx = sx + 1
                        End If
                    End If
                Case 3
                    If sx + 1 < maxx Then
                        If sx Mod 2 Then
                            sx = sx + 1
                        Else
                            If sy + 1 < (maxy - 1) Then
                                sx = sx + 1
                                sy = sy + 1
                            End If
                        End If
                    End If
                Case 4
                    If sy + 1 < maxy Then
                        sy = sy + 1
                    End If
                Case 5
                    If sx - 1 > 1 Then
                        If sx Mod 2 Then
                            If sy - 1 > 1 Then
                                sx = sx - 1
                                sy = sy - 1
                            End If
                        Else
                            sx = sx - 1
                        End If
                    End If
                Case 6
                    If sx - 1 > 1 Then
                        If sx Mod 2 Then
                            sx = sx - 1
                        Else
                            If sy + 1 < (maxy - 1) Then
                                sx = sx - 1
                                sy = sy + 1
                            End If
                        End If
                    End If
            End Select
            If map(sx, sy) = 1 Then 'only dig out and count the hex-cell if it is filled
                map(sx, sy) = 0
                c = c + 1
            End If
            lastgo = dgo
            lasthrun = hrun
        Next hgo
    Loop Until c >= clim
    'draw the hex grid
    For y = 1 To maxy
        For x = 1 To maxx
            If map(x, y) = 1 Then
                hexat x, y
                hexpaint x, y, _RGB32(200, 200, 200)
            End If
        Next x
    Next y
    _Display
    Do
        _KeyClear
        _Limit 60
        kk$ = InKey$
    Loop Until kk$ <> ""
Loop Until kk$ = "q"

Sub hexpaint (x, y, hklr As _Unsigned Long)
    'paint an arbitrary hex
    'hexradius and hexborder defined as shared variables in main program
    hr = hexradius
    If x Mod 2 Then
        Paint ((x * 2) * hr * .75, y * (hr * 1.75)), hklr, hexborder
    Else
        Paint ((x * 2) * hr * .75, y * (hr * 1.75) + (hr * .875)), hklr, hexborder
    End If
End Sub

Sub hexput (sp&, x, y, sscale, hf)
    'drop a sprite/image inside a hex , hf is hexfacing given in degrees
    'sp& would be an image handle to a sprite created elsewere in program
    hr = hexradius
    If x Mod 2 Then
        RotoZoom23d (x * 2) * hr * .75, y * (hr * 1.75), sp&, sscale, sscale, hf
    Else
        RotoZoom23d (x * 2) * hr * .75, y * (hr * 1.75) + (hr * .875), sp&, sscale, sscale, hf
    End If
End Sub

Sub hexat (xx, yy)
    'draw an arbitrary hex, hexradius and hexborder are shared variables created in main porgram
    hr = hexradius
    y = yy
    x = xx
    If x Mod 2 Then
        rotpoly (x * 2) * hr * .75, y * (hr * 1.75), hr, 60, 30, hexborder
    Else
        rotpoly (x * 2) * hr * .75, y * (hr * 1.75) + (hr * .875), hr, 60, 30, hexborder
    End If
End Sub

Sub hexgrid (xx, yy)
    'draw a whole empty hexgrid
    hr = hexradius
    For y = 1 To yy
        For x = 1 To xx
            If x Mod 2 Then
                rotpoly (x * 2) * hr * .75, y * (hr * 1.75), hr, 60, 30, hexborder
            Else
                rotpoly (x * 2) * hr * .75, y * (hr * 1.75) + (hr * .875), hr, 60, 30, hexborder
            End If
        Next x
    Next y
End Sub

Sub rotpoly (cx, cy, rr, shapedeg, turn, klr As _Unsigned Long)
    'draw an equilateral polygon (if shapedeg divides evenly into 360) centered on cx and cy
    x = rr * Sin(0.01745329 * turn)
    y = rr * Cos(0.01745329 * turn)
    Line (cx + x, cy + y)-(cx + x, cy + y), klr
    For deg = turn To turn + 360 Step shapedeg
        x2 = rr * Sin(0.01745329 * deg)
        y2 = rr * Cos(0.01745329 * deg)
        Line -(cx + x2, cy + y2), klr
    Next
End Sub

'used in hexput to drop a sprite in a hex
Sub RotoZoom23d (centerX As Long, centerY As Long, Image As Long, xScale As Single, yScale As Single, Rotation As Single)
    Dim px(3) As Single: Dim py(3) As Single
    Wi& = _Width(Image&): Hi& = _Height(Image&)
    W& = Wi& / 2 * xScale
    H& = Hi& / 2 * yScale
    px(0) = -W&: py(0) = -H&: px(1) = -W&: py(1) = H&
    px(2) = W&: py(2) = H&: px(3) = W&: py(3) = -H&
    sinr! = Sin(-0.01745329 * Rotation): cosr! = Cos(-0.01745329 * Rotation)
    For i& = 0 To 3
        x2& = (px(i&) * cosr! + sinr! * py(i&)) + centerX: y2& = (py(i&) * cosr! - px(i&) * sinr!) + centerY
        px(i&) = x2&: py(i&) = y2&
    Next
    _MapTriangle (0, 0)-(0, Hi& - 1)-(Wi& - 1, Hi& - 1), Image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MapTriangle (0, 0)-(Wi& - 1, 0)-(Wi& - 1, Hi& - 1), Image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub
Reply
#2
Nice start. 

First question that comes to mind is how to navigate in such a maze. Up and down arrows OK but left and right, upper and lower? hmm...

Also I wonder if possible to generate a maze that passes through every room like orthogonal maze generators do.
b = b + ...
Reply
#3
(03-14-2023, 02:54 PM)bplus Wrote: First question that comes to mind is how to navigate in such a maze. Up and down arrows OK but left and right, upper and lower? hmm...

Use the number pad if your computer supports it.

Otherwise, recall "7" "8" "9" the regular keys match the ones on the number pad my computer doesn't have, then "U" "I" "O" just below them ("I" would be a dead key then) and finally "J" "K" "L" the bottom row. Or for two-player game that could be for the second player while the keys that begin with "1" "Q" "A" would be for player one.

This is a good beginning to a simple shooter game like a certain shareware one, many many years ago done I think in Turbo Pascal with "SCREEN 0". I liked that one a lot although I didn't spend a lot of time on it and I got stuck cooked in the "lava" LOL.
Reply
#4
WASD just becomes QWEASD.
Reply
#5
(03-15-2023, 01:25 AM)johannhowitzer Wrote: WASD just becomes QWEASD.

Yeah I can see that!
b = b + ...
Reply
#6
When dealing with hex maps, I always just use an arrow to indicate a character direction, and then left/right arrows change heading by 60 degrees for that arrow and up moves forward, down moves backwards in that direction.

Say arrow is pointing North...  press up, move one hex north.   press down, move one hext south.   Press right, arrow now faces north-east diagional.  (Assuming the hex grid looks somewhat similar to the below.)

 _
/ \
\_/
Reply
#7
Code: (Select All)
Type MapInfo
    Wall As _Unsigned _Byte
    Distance As _Byte
End Type


Const min = 1, max = 20
Const TopLeftX = 50, TopLeftY = 50 'just where I want to put my top left corner of my map on the screen
Const HexSize = 16 'Size of Hex

Const NE = 1, East = 2, SE = 4, SW = 8, West = 16, NW = 32



Dim Shared HeroPointer, HeroHeading, Difficulty
Dim Shared map(min - 1 To max + 1, min - 1 To max + 1) As MapInfo

Difficulty = 140

Screen _NewImage(800, 600, 32)
Color -1

Randomize Timer

HeroX = 1: HeroY = 1: HeroHeading = SE: direction = 2

HeroPointer = TextToImage("", 16, &HFFFF0000, 0, 0)

CreateMap
TargetX = Int(Rnd * max) + min: TargetY = Int(Rnd * max) + min

Do
    _Limit 30
    Cls , 0
    _DontBlend: DrawMap
    _Blend: DrawHero HeroX, HeroY

    k = _KeyHit
    Select Case k
        Case 19200 'left arrow
            direction = direction - 1: If direction < 0 Then direction = 5
            HeroHeading = 2 ^ direction
        Case 20480 'down arrow
            Select Case HeroHeading
                Case NE: HeroX = HeroX - .5: HeroY = HeroY + 1
                Case East: HeroX = HeroX - 1
                Case SE: HeroX = HeroX - .5: HeroY = HeroY - 1
                Case SW: HeroX = HeroX + .5: HeroY = HeroY - 1
                Case West: HeroX = HeroX + 1
                Case NW: HeroX = HeroX + .5: HeroY = HeroY + 1
            End Select

        Case 19712 'right arrow
            direction = direction + 1: If direction > 5 Then direction = 0
            HeroHeading = 2 ^ direction
        Case 18432 'up arrow
            Select Case HeroHeading
                Case NE: If (map(_Ceil(HeroX), HeroY).Wall And 1) = 0 Then HeroX = HeroX + .5: HeroY = HeroY - 1
                Case East: If (map(_Ceil(HeroX), HeroY).Wall And 2) = 0 Then HeroX = HeroX + 1
                Case SE: If (map(_Ceil(HeroX), HeroY).Wall And 4) = 0 Then HeroX = HeroX + .5: HeroY = HeroY + 1
                Case SW: If (map(_Ceil(HeroX), HeroY).Wall And 8) = 0 Then HeroX = HeroX - .5: HeroY = HeroY + 1
                Case West: If (map(_Ceil(HeroX), HeroY).Wall And 16) = 0 Then HeroX = HeroX - 1
                Case NW: If (map(_Ceil(HeroX), HeroY).Wall And 32) = 0 Then HeroX = HeroX - .5: HeroY = HeroY - 1
            End Select
        Case Asc("r"), Asc("R")
            TargetX = Int(Rnd * max) + min: TargetY = Int(Rnd * max) + min
    End Select
    _PrintString (680, 100), "AV: " + Str$(HeroX) + "," + Str$(HeroY)
    _PrintString (680, 130), "TV: " + Str$(_Ceil(HeroX)) + "," + Str$(HeroY)
    _PrintString (680, 160), "WL: " + Str$(map(_Ceil(HeroX), HeroY).Wall)
    DrawHex TargetX, TargetY, &HFFFF00FF

    If _Ceil(HeroX) = TargetX And HeroY = TargetY Then
        CreateMap
        Difficulty = Difficulty + 5
        TargetX = Int(Rnd * max) + min: TargetY = Int(Rnd * max) + min
    End If
    _Display
Loop Until k = 27
System

Sub CreateMap
    For x = min - 1 To max + 1 'Reset the map to just borders
        For y = min - 1 To max + 1
            map(x, y).Distance = -1: map(x, y).Wall = 0
    Next y, x
    For x = min - 1 To max + 1 'borders are non-moveable
        map(x, min - 1).Wall = -1
        map(x, max + 1).Wall = -1
        map(min - 1, x).Wall = -1
        map(max + 1, x).Wall = -1
    Next

    D = 256 - Difficulty: If D < 63 Then D = 63
    For x = min To max
        For y = min To max
            r = Int(Rnd * D)
            If r > 63 Then r = 0
            If r > 0 Then map(x, y).Wall = map(x, y).Wall Or r
        Next
    Next
    For x = min - 1 To max + 1
        For y = min - 1 To max + 1
            If y Mod 2 = 0 Then xmod = 0 Else xmod = 1

            If map(x, y).Wall And NE And x <= max And y >= min Then map(x + xmod, y - 1).Wall = map(x + xmod, y - 1).Wall Or SW
            If map(x, y).Wall And East And x <= max Then map(x + 1, y).Wall = map(x + 1, y).Wall Or West
            If map(x, y).Wall And SE And y <= max And x <= max Then map(x + xmod, y + 1).Wall = map(x + xmod, y + 1).Wall Or NW
            If xmod = 0 Then xmod = 1 Else xmod = 0
            If map(x, y).Wall And SW And x >= min And y <= max Then map(x - xmod, y + 1).Wall = map(x - xmod, y + 1).Wall Or NE
            If map(x, y).Wall And West And x >= min Then map(x - 1, y).Wall = map(x - 1, y).Wall Or East
            If map(x, y).Wall And NW And x >= min And y >= min Then map(x - xmod, y - 1).Wall = map(x - xmod, y - 1).Wall Or SE
        Next
    Next

End Sub


Sub DrawHero (TempX, Y)
    X = _Ceil(TempX)
    HexWidth = Sqr(3) * HexSize: HexHeight = 2 * HexSize 'Height and Width of each individual hex
    CenterX = TopLeftX + X * HexWidth
    CenterY = TopLeftY + Y * HexHeight * 0.75
    If Y Mod 2 Then CenterX = CenterX + HexWidth / 2 'offset for odd/even rows
    Select Case HeroHeading
        Case NE: Angle = -30
        Case East: Angle = -90
        Case SE: Angle = -150
        Case SW: Angle = 150
        Case West: Angle = 90
        Case NW: Angle = 30
    End Select
    DisplayImage HeroPointer, CenterX, CenterY, Angle, 0

End Sub

Sub DrawHex (X, Y, C As _Unsigned Long)
    HexWidth = Sqr(3) * HexSize: HexHeight = 2 * HexSize 'Height and Width of each individual hex
    CenterX = TopLeftX + X * HexWidth
    CenterY = TopLeftY + Y * HexHeight * 0.75
    If Y Mod 2 Then CenterX = CenterX + HexWidth / 2 'offset for odd/even rows
    Color C
    Point1X = CenterX - HexWidth / 2
    Point2X = CenterX
    Point3x = CenterX + HexWidth / 2
    Point1y = CenterY - HexHeight / 2
    Point2y = CenterY - HexHeight / 4
    Point3y = CenterY + HexHeight / 4
    Point4y = CenterY + HexHeight / 2
    Line (Point1X, Point2y)-(Point2X, Point1y) 'NorthWest
    Line (Point2X, Point1y)-(Point3x, Point2y) 'NorthEast
    Line (Point3x, Point2y)-(Point3x, Point3y) 'East
    Line (Point3x, Point3y)-(Point2X, Point4y) 'SouthEast
    Line (Point2X, Point4y)-(Point1X, Point3y) 'SouthWest
    Line (Point1X, Point3y)-(Point1X, Point2y) 'West
    Paint (CenterX, CenterY), C
    Color -1
End Sub



Sub DrawMap
    HexWidth = Sqr(3) * HexSize: HexHeight = 2 * HexSize 'Height and Width of each individual hex
    For X = min - 1 To max + 1
        For Y = min - 1 To max + 1
            CenterX = TopLeftX + X * HexWidth
            CenterY = TopLeftY + Y * HexHeight * 0.75
            If Y Mod 2 Then CenterX = CenterX + HexWidth / 2 'offset for odd/even rows
            Point1X = CenterX - HexWidth / 2
            Point2X = CenterX
            Point3x = CenterX + HexWidth / 2
            Point1y = CenterY - HexHeight / 2
            Point2y = CenterY - HexHeight / 4
            Point3y = CenterY + HexHeight / 4
            Point4y = CenterY + HexHeight / 2
            If map(X, Y).Wall And NW Then Line (Point1X, Point2y)-(Point2X, Point1y) 'NorthWest
            If map(X, Y).Wall And NE Then Line (Point2X, Point1y)-(Point3x, Point2y) 'NorthEast
            If map(X, Y).Wall And East Then Line (Point3x, Point2y)-(Point3x, Point3y) 'East
            If map(X, Y).Wall And SE Then Line (Point3x, Point3y)-(Point2X, Point4y) 'SouthEast
            If map(X, Y).Wall And SW Then Line (Point2X, Point4y)-(Point1X, Point3y) 'SouthWest
            If map(X, Y).Wall And West Then Line (Point1X, Point3y)-(Point1X, Point2y) 'West
            If (map(X, Y).Wall And 63) = 63 Then Paint (CenterX, CenterY)
        Next
    Next
End Sub

Sub DisplayImage (Image As Long, x As Integer, y As Integer, angle As Single, mode As _Byte)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of oour image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    Dim px(3) As Integer, py(3) As Integer, w As Integer, h As Integer
    Dim sinr As Single, cosr As Single, i As _Byte
    w = _Width(Image): h = _Height(Image)
    Select Case mode
        Case 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
        Case 1 'top left
            px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h: px(2) = w: py(2) = h
        Case 2 'bottom left
            px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
        Case 3 'top right
            px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
        Case 4 'bottom right
            px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    End Select
    sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
    For i = 0 To 3
        x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2: py(i) = y2
    Next
    _MapTriangle (0, 0)-(0, h - 1)-(w - 1, h - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MapTriangle (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub

Function TextToImage& (text$, font&, fc&, bfc&, mode As _Byte)
    'text$ is the text that we wish to transform into an image.
    'font& is the handle of the font we want to use.
    'fc& is the color of the font we want to use.
    'bfc& is the background color of the font.

    'Mode 1 is print forwards
    'Mode 2 is print backwards
    'Mode 3 is print from top to bottom
    'Mode 4 is print from bottom up
    'Mode 0 got lost somewhere, but it's OK.  We check to see if our mode is < 1 or > 4 and compensate automatically if it is to make it one (default).

    If mode < 1 Or mode > 4 Then mode = 1
    dc& = _DefaultColor: bgc& = _BackgroundColor
    D = _Dest
    F = _Font
    T2Idown = CsrLin: T2Iright = Pos(0)
    If font& <> 0 Then _Font font&
    If mode < 3 Then
        'print the text lengthwise
        w& = _PrintWidth(text$): h& = _FontHeight
    Else
        'print the text vertically
        For i = 1 To Len(text$)
            If w& < _PrintWidth(Mid$(text$, i, 1)) Then w& = _PrintWidth(Mid$(text$, i, 1))
        Next
        h& = _FontHeight * (Len(text$))
    End If

    TextToImage_temp& = _NewImage(w&, h&, 32)
    TextToImage = TextToImage_temp&
    _Dest TextToImage_temp&
    If font& <> 0 Then _Font font&
    Color fc&, bfc&

    Select Case mode
        Case 1
            'Print text forward
            _PrintString (0, 0), text$
        Case 2
            'Print text backwards
            temp$ = ""
            For i = 0 To Len(text$) - 1
                temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
            Next
            _PrintString (0, 0), temp$
        Case 3
            'Print text upwards
            'first lets reverse the text, so it's easy to place
            temp$ = ""
            For i = 0 To Len(text$) - 1
                temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
            Next
            'then put it where it belongs
            For i = 1 To Len(text$)
                fx = (w& - _PrintWidth(Mid$(temp$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
                _PrintString (fx, _FontHeight * (i - 1)), Mid$(temp$, i, 1)
            Next
        Case 4
            'Print text downwards
            For i = 1 To Len(text$)
                fx = (w& - _PrintWidth(Mid$(text$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
                _PrintString (fx, _FontHeight * (i - 1)), Mid$(text$, i, 1)
            Next
    End Select
    _Dest D
    Color dc&, bgc&
    _Font F
    Locate T2Idown, T2Iright
End Function


^ An old hex maze generator which I wrote several years back.  Wink

Notice that the game gets consistently harder as you progress, with more walls blocking your path, and I must admit:  I didn't bother to have the program check to make certain that you can actually reach the target location.  In fact, I freely confess, if you keep playing, you'll eventually get to a stage where you WON'T be able to reach the target -- the non-intelligent randomness of this little demo WILL make it an impossible task eventually. 

ESC stops the program.
R will Relocate the target location.
Left/Right allows us to change heading.
Up moves us in the direction we're facing.
Down is a terrible cheat (intentionally left at this point, to allow full map movement), which moves us away from the direction we're facing. 

Try it out and see what you think; it's definitely different than most other quad-directional maze-generators which I've seen and played around with in the past.  Smile
Reply
#8
(03-14-2023, 02:54 PM)bplus Wrote: Nice start. 

First question that comes to mind is how to navigate in such a maze. Up and down arrows OK but left and right, upper and lower? hmm...

Also I wonder if possible to generate a maze that passes through every room like orthogonal maze generators do.

You could navigate with forward, backward  and rotation left or right  like SMcNiel shows. Use the number keys 1 through 6 is pretty quick and easy as well. You can also just stick with the player and sprites still interacting in a standard x-y grid with the hexes just defining the overall geometry. 

I suppose a standard maze generating algorithm that visits every cell would still function as the hex grid is ultimately just a standard grid where the geometry is offset every other column (or row) of cells. The resulting mazes may demonstrate a bias but they'd likely work.
Reply
#9
(03-15-2023, 05:49 AM)SMcNeill Wrote: ^ An old hex maze generator which I wrote several years back.  Wink

Notice that the game gets consistently harder as you progress, with more walls blocking your path, and I must admit:  I didn't bother to have the program check to make certain that you can actually reach the target location.  In fact, I freely confess, if you keep playing, you'll eventually get to a stage where you WON'T be able to reach the target -- the non-intelligent randomness of this little demo WILL make it an impossible task eventually. 

ESC stops the program.
R will Relocate the target location.
Left/Right allows us to change heading.
Up moves us in the direction we're facing.
Down is a terrible cheat (intentionally left at this point, to allow full map movement), which moves us away from the direction we're facing. 

Try it out and see what you think; it's definitely different than most other quad-directional maze-generators which I've seen and played around with in the past.  Smile

I got stuck the very first run, except for the backing up through walls with the down key I'd have been doomed.

I like it, definitely a different look than what I'm going for but it does tackle some of the same issues.
Reply




Users browsing this thread: 1 Guest(s)