Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MazeRogue
#7
gosh darn... I'm messing something up big time.  might have to strip this down and rebuild from scratch. More happens in this listing just not like I wanted it to, posting this failure as an example of what no to do:

Code: (Select All)
'mazerogue the bad code... doesn't work like it is suposed to... bad code...bad
' a micro rogue by James D. Jarvis October 2022
'navigate with arrow ke
Screen _NewImage(81, 30, 0)
'$dynamic
Randomize Timer
Dim T$
Dim crn$(4)
_ControlChr Off
_Scrolllock Off
Dim mz(0 To 80, 1 To 25) As String
Dim crnr(4, 2), loot(3), monst(3), mcount, mpos(0, 2), mnd(0, 4)
'mnd(n,1)= asc code, mnd(n,2)= monster toughness  , mnd(n,3)= behavior flag, mn(n,4)= behavior record
loot(1) = 4: loot(2) = 3: loot(3) = 15
monst(1) = 132: monst(2) = 42: monst(3) = 111
crnr(1, 1) = 1: crnr(1, 2) = 1
crnr(2, 1) = 79: crnr(2, 2) = 1
crnr(3, 1) = 1: crnr(3, 2) = 25
crnr(4, 1) = 79: crnr(4, 2) = 25
maxx = 80: maxy = 25: mlevel = 0: mcount = 0
herox = Int(_Width / 2): heroy = Int(_Height / 2)
php = 10: ppow = 0: pgems = 0
newlevel:
mlevel = mlevel + 1
mlabel$ = "MazeRogue Level " + Str$(mlevel)
_Title mlabel$
For y = 1 To maxy
    For x = 0 To maxx
        mz(x, y) = Chr$(219)
    Next
Next
nx = 3: ny = 3: done = 0: mcount = 0
Do While done = 0
    _Limit 1000
    For reps = 0 To 99
        ox = nx: oy = ny
        Rem move in random direction
        Select Case Int(Rnd * 4)
            Case 0
                If nx + 2 <= maxx Then nx = nx + 2
            Case 1
                If ny + 2 <= maxy Then ny = ny + 2
            Case 2
                If nx - 2 > 0 Then nx = nx - 2
            Case 3
                If ny - 2 > 0 Then ny = ny - 2
        End Select
        If mz(nx, ny) = Chr$(219) Then
            mz(nx, ny) = ".": If 1 + Int(Rnd * 50) = 1 Then mz(nx, ny) = Chr$(loot(1 + Int(Rnd * 3)))
            If mz(nx, ny) = "." And 1 + Int(Rnd * 50) <= mlevel Then
                mr = 1 + Int(Rnd * 3): mz(nx, ny) = Chr$(monst(mr)): mcount = mcount + 1
                ReDim _Preserve mpos(mcount, 2)
                ReDim _Preserve mnd(mcount, 4)
                mnd(mcount, 1) = monst(mr): mnd(mcount, 2) = 1 + Int(Rnd * ((4 * mr / 2) + ((mlevel) / 2)))
                mnd(mcount, 3) = 0: mnd(mcount, 4) = 0
                mpos(mcount, 1) = nx: mpos(mcount, 2) = ny
            End If
            mz(Int((nx + ox) / 2), ((ny + oy) / 2)) = "."

        End If
    Next
    done = 1
    For x = 1 To maxx - 1 Step 2
        For y = 1 To maxy - 1 Step 2
            If mz(x, y) = Chr$(219) Then done = 0
        Next y
    Next x
Loop
cr = 1 + Int(Rnd * 4) 'set a corner for the exit
If herox = crnr(cr, 1) And heroy = crnr(cr, 2) Then cr = 5 - cr
mz(crnr(cr, 1), crnr(cr, 2)) = Chr$(239)
T$ = "" 'load the maze into t$
For y = 1 To 25: For x = 0 To 80: T$ = T$ + mz$(x, y): Next x: Next y
ll$ = String$(81, 219) 'top and botton maze display edges becasue I didn't want to fix the maze generator to account for top and bottom edge
lastX = herox: lasty = heroy
Do 'game play loop
    _Limit 20
    Mid$(T$, (heroy) * 81 + herox - 81) = Chr$(1)
    _PrintString (1, 1), ll$: _PrintString (1, 27), ll$: _PrintString (1, 2), T$
    _PrintString (1, 28), String$(80, " ")
    pcc$ = "Hit Points: " + Str$(php) + "  Power: " + Str$(ppow) + "   Gems: " + Str$(pgems)
    _PrintString (3, 28), pcc$
    nk& = 0
    Do: _Limit 60: KH& = _KeyHit: nk& = KH&: Loop Until nk& > 0

    If KH& = 19200 Then herox = herox - 1
    If KH& = 19712 Then herox = herox + 1
    If KH& = 18432 Then heroy = heroy - 1
    If KH& = 20480 Then heroy = heroy + 1
    If herox < 1 Then herox = 1
    If herox > _Width Then herox = _Width
    If heroy < 1 Then heroy = 1
    If heroy > 25 Then heroy = 25
    Mid$(T$, (lasty) * 81 + lastX - 81) = "."
    If Mid$(T$, (heroy * 81 + herox - 81), 1) = Chr$(219) Then
        herox = lastX: heroy = lasty
    End If
    For lp = 1 To 3
        If Mid$(T$, (heroy * 81 + herox - 81), 1) = Chr$(loot(lp)) Then
            Select Case lp
                Case 1
                    pgems = pgems + 1
                Case 2
                    php = php + 3
                Case 3
                    ppow = ppow + 2
            End Select
        End If
    Next lp
    If Mid$(T$, (heroy * 81 + herox - 81), 1) = Chr$(239) Then
        Beep: Cls: Print: Print "Continue to Next Level ?": Print: Input "Yes or No", ask$
        If Left$(UCase$(ask$), 1) = "N" Then
            heroy = lasty: herox = lastX
        Else
            Cls: GoTo newlevel
        End If
    End If
    If mcount > 0 Then
        For m = 1 To mcount
            If mpos(m, 1) > -1 Then
                mny = mpos(m, 2): mnx = mpos(m, 1)
                Mid$(T$, (mny * 81 + mnx - 81), 1) = "."
                If mnd(m, 3) = 0 Then mact = Int(Rnd * 9) Else mact = mnd(m, 4)
                dth = Sqr((herox - mpos(m, 1)) ^ 2 + (heroy - mpos(m, 2)) ^ 2): If dth < 5 Then mact = Int(Rnd * 4) + 4
                Select Case mact
                    Case 0 'east
                        If Mid$(T$, (mpos(m, 2) * 81 + mpos(m, 1) + 1 - 81), 1) = "." Then mnx = mpos(m, 1) + 1
                    Case 1 'south
                        If Mid$(T$, ((mpos(m, 2) + 1) * 81 + mpos(m, 1) - 81), 1) = "." Then mny = mpos(m, 2) + 1
                    Case 2 'west
                        If Mid$(T$, (mpos(m, 2) * 81 + mpos(m, 1) - 1 - 81), 1) = "." Then mnx = mpos(m, 1) - 1
                    Case 3 'north
                        If Mid$(T$, ((mpos(m, 2) - 1) * 81 + mpos(m, 1) - 81), 1) = "." Then mny = mpos(m, 2) - 1
                    Case 4, 5
                        If heroy = mpos(m, 2) Then
                            If herox < mpos(m, 1) Then
                                If Mid$(T$, (mpos(m, 2) * 81 + mpos(m, 1) - 1 - 81), 1) = "." Then mnx = mpos(m, 1) - 1
                            Else
                                If Mid$(T$, (mpos(m, 2) * 81 + mpos(m, 1) + 1 - 81), 1) = "." Then mnx = mpos(m, 1) + 1
                            End If
                        End If
                    Case 6, 7 ' go player vert
                        If herox = mpos(m, 1) Then
                            If heroy < mpos(m, 2) Then
                                If Mid$(T$, ((mpos(m, 2) - 1) * 81 + mpos(m, 1) - 1 - 81), 1) = "." Then mny = mpos(m, 2) - 1
                            Else
                                If Mid$(T$, ((mpos(m, 2) + 1) * 81 + mpos(m, 1) - 1 - 81), 1) = "." Then mny = mpos(m, 2) + 1
                            End If
                        End If
                    Case 8 ' do nothing
                End Select
                mpos(m, 1) = mnx: mpos(m, 2) = mny
                Mid$(T$, (mpos(m, 2) * 81 + mpos(m, 1) - 81), 1) = Chr$(mnd(m, 1))
                mnd(m, 4) = mact
                If Rnd * 6 < 2 Then mnd(m, 3) = 0 Else mnd(m, 3) = 1
            End If

        Next m
    End If
    lastX = herox: lasty = heroy
    k$ = InKey$
Loop Until k$ = Chr$(27)
System
Reply


Messages In This Thread
MazeRogue - by James D Jarvis - 10-28-2022, 12:12 AM
RE: MazeRogue - by bplus - 10-28-2022, 12:54 AM
RE: MazeRogue - by James D Jarvis - 10-28-2022, 03:36 PM
RE: MazeRogue - by bplus - 10-28-2022, 05:42 PM
RE: MazeRogue - by James D Jarvis - 10-28-2022, 07:43 PM
RE: MazeRogue - by James D Jarvis - 10-29-2022, 01:32 PM
RE: MazeRogue - by James D Jarvis - 10-30-2022, 03:27 PM
RE: MazeRogue - by SierraKen - 08-22-2024, 06:05 PM



Users browsing this thread: 1 Guest(s)