Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sweet little circuit game space maker
#1
Sets up a board with no dead end tracks, might be used for race track or city roads layout or just nice designs.

Code: (Select All)
Option _Explicit
_Title "Little game Circuit game space" 'b+ 2024-02-18
Randomize Timer
Dim Shared SW, SH: SW = 800: SH = 600
Screen _NewImage(SW, SH, 32)
_ScreenMove 200, 60
Dim As Long UbX, UbY, cx, cy, lastTarget, targets, tx, ty, dx, dy
UbX = 80: UbY = 60 ' the max width and height of board cells
Do ' test board layouts
    Cls: ReDim board$(1 To UbX, 1 To UbY) 'resets
    cx = UbX \ 2: cy = UbY \ 2: lastTarget = 30
    For targets = 1 To lastTarget
        tryAgain: ' to avoid dead end streets
        If targets <> lastTarget Then ' stay off the edges
            tx = 2 * Int((Rnd * (UbX - 3) \ 2)) + 2: ty = 2 * Int(Rnd * (UbY - 3) \ 2) + 2
        Else
            tx = UbX \ 2: ty = UbY \ 2
        End If
        If tx = cx Or ty = cy Then GoTo tryAgain ' to avoid dead end streets
        dx = tx - cx: dy = ty - cy ' the distance and direction we have to go
        While cx <> tx: cx = cx + Sgn(dx): GoSub MakeWay: Wend
        While cy <> ty: cy = cy + Sgn(dy): GoSub MakeWay: Wend
    Next
    Sleep
Loop Until _KeyDown(27)
End
MakeWay: board$(cx, cy) = "S": Line ((cx - 1) * 10, (cy - 1) * 10)-Step(9, 9), , BF: Return

Sample board$()
   
b = b + ...
Reply


Messages In This Thread
sweet little circuit game space maker - by bplus - 02-18-2024, 08:34 PM



Users browsing this thread: 1 Guest(s)