Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
X-Racer
#1
It's rude, it's crude, it's a classic that works most of the time. 
X-Racer is a text mode racing game where you are in a timed trial to get to the finish line.

Avoid the barriers and the sides or you are going to crash. The game is key driven but doesn't wait for you to press the enter key for long.

space bar -  to accelerate
     <       -  turn (screen) left
     >       -  turn (screen) right
     b        - to brake

(there's still a few problems with the code but if you don't explode at the start of the race you might be able to race to the end) 

Code: (Select All)
'X-racer is an old school racing game using text graphics only
'press spacebar to get that engine going and < or > to steer  b to brake!
_Title "X-RACER"
track$ = "####OOO................OOO####"
n = 13
trend = 0
obstacle = 10
Randomize Timer
Dim b$(2010)
Dim nn(2010)
start:
ask$ = "."
spd = 1
Do
    Cls
    For x = 1 To 2010
        A$ = String$(n, 32)
        b$(x) = A$ + track$
        If x > 100 And x Mod obstacle Then
            If Rnd * 100 < obstacle Then Mid$(b$(x), n + Int(3 + Rnd * 18), 1) = "O"
        End If

        n = n + Int(Rnd * 2) - Int(Rnd * 2) + trend
        If n < 2 Then n = 2
        If n > 35 Then n = 35
        nn(x) = n
        If Rnd * 100 < 3 Then
            Select Case Int(Rnd * 3)
                Case 0
                    trend = 0
                Case 1
                    trend = -1

                Case 2
                    trend = 1
            End Select
        End If
    Next x
    b$(1995) = A$ + "####O============O####"
    b$(1991) = A$ + "####O============O####"
    b$(1992) = A$ + "####O            O####"
    b$(1993) = A$ + "####O   FINISH   O####"
    b$(1994) = A$ + "####O            O####"
    b$(1995) = A$ + "####O============O####"
    For x = 1996 To 2010
        b$(x) = A$ + "####O            O####"
    Next x
    dp = nn(1) + 11
    op = dp
    For x = 1 To 2010
        _Limit 20
        If x > 10 Then Color 12: _PrintString (dp, 10), "X": Color 15
        _PrintString (op, 9), "."
        Print b$(x);
        If x > 12 Then
            If Mid$(b$(x - 13), dp, 1) = "O" Then GoTo crash
        End If
        op = dp
        If x Mod 20 = 0 Then
            Print " - "; x * 5
        Else
            Print
        End If
        If x > 10 Then
            gg = 0
            Do
                _Limit 60
                gg = gg + 1
                kk$ = InKey$
            Loop Until kk$ <> "" Or gg = 30 - spd
        End If
        If x = 12 Then t1 = Timer
        Select Case kk$
            Case ".", ">"
                op = dp
                dp = dp + 1

            Case ",", "<"
                op = dp
                dp = dp - 1.
            Case " "
                spd = spd + 1
                If spd > 28 Then spd = 28
            Case "b"
                spd = spd - 2
                If spd < 1 Then spd = 1
        End Select
        mph$ = "MPH : " + Str$(spd * 10)
        _PrintString (1, 2), mph$
    Next x
    t2 = Timer
    Print
    Print "Finished Course !"
    Print
    Print "Finish Time "; t2 - t1
    Input "Play again (Y or N) ", ask$
    ask$ = UCase$(ask$)
    If ask$ = "N" Then GoTo alldone
Loop
End
crash:
For c = 1 To 6
    _Limit 8
    Color 12
    For cx = dp - c To dp + c
        For cy = 10 - c To c + 10
            If Rnd * 6 < 3 Then _PrintString (cx, cy), "@"
        Next cy
    Next cx
Next c
Color 15
Print "YOU CRASHED"
Input "Play again (Y or N) ", ask$
ask$ = UCase$(ask$)
If ask$ = "N" Then GoTo alldone
GoTo start
alldone:
End
Reply
#2
Played it...
Modified it...

SCREEN ZERO HERO VERSION: E-Racer! (Just press the "E" key and go for the finish line!

Code: (Select All)
'X-racer is an old school racing game using text graphics only
'press spacebar to get that engine going and < or > to steer  b to brake!
_TITLE "X-RACER"
track$ = "####OOO................OOO####"
n = 13
trend = 0
obstacle = 10
RANDOMIZE TIMER
DIM b$(2010)
DIM nn(2010)
start:
ask$ = "."
spd = 1
DO
    CLS
    FOR x = 1 TO 2010
        A$ = STRING$(n, 32)
        b$(x) = A$ + track$
        IF x > 100 AND x MOD obstacle THEN
            IF RND * 100 < obstacle THEN MID$(b$(x), n + INT(3 + RND * 18), 1) = "O"
        END IF

        n = n + INT(RND * 2) - INT(RND * 2) + trend
        IF n < 2 THEN n = 2
        IF n > 35 THEN n = 35
        nn(x) = n
        IF RND * 100 < 3 THEN
            SELECT CASE INT(RND * 3)
                CASE 0
                    trend = 0
                CASE 1
                    trend = -1

                CASE 2
                    trend = 1
            END SELECT
        END IF
    NEXT x
    b$(1995) = A$ + "####O============O####"
    b$(1991) = A$ + "####O============O####"
    b$(1992) = A$ + "####O            O####"
    b$(1993) = A$ + "####O  FINISH  O####"
    b$(1994) = A$ + "####O            O####"
    b$(1995) = A$ + "####O============O####"
    FOR x = 1996 TO 2010
        b$(x) = A$ + "####O            O####"
    NEXT x
    dp = nn(1) + 11
    op = dp
    FOR x = 1 TO 2010
        _LIMIT 20
        IF x > 10 THEN COLOR 12: _PRINTSTRING (dp, 10), "E": COLOR 15
        _PRINTSTRING (op, 9), "."
        PRINT b$(x);
        IF x > 12 THEN
            IF MID$(b$(x - 13), dp, 1) = "O" THEN GOTO crash
        END IF
        op = dp
        IF x MOD 20 = 0 THEN
            PRINT " - "; x * 5
        ELSE
            PRINT
        END IF
        IF x > 10 THEN
            gg = 0
            DO
                _LIMIT 60
                gg = gg + 1
                kk$ = INKEY$
            LOOP UNTIL kk$ <> "" OR gg = 30 - spd
        END IF
        IF kk$ = "E" OR kk$ = "e" THEN
            IF pete = 0 THEN
                pete = 1
                track$ = "                              "
                FOR xx = 1 TO 1990
                    A$ = STRING$(n, 32)
                    b$(xx) = A$ + track$
                NEXT xx
            END IF
        END IF
        IF x = 12 THEN t1 = TIMER
        SELECT CASE kk$
            CASE ".", ">"
                op = dp
                dp = dp + 1

            CASE ",", "<"
                op = dp
                dp = dp - 1.
            CASE " "
                spd = spd + 1
                IF spd > 28 THEN spd = 28
            CASE "b"
                spd = spd - 2
                IF spd < 1 THEN spd = 1
        END SELECT
        mph$ = "MPH : " + STR$(spd * 10)
        _PRINTSTRING (1, 2), mph$
    NEXT x
    t2 = TIMER
    PRINT
    PRINT "Finished Course !"
    PRINT
    PRINT "Finish Time "; t2 - t1
    INPUT "Play again (Y or N) ", ask$
    ask$ = UCASE$(ask$)
    IF ask$ = "N" THEN GOTO alldone
LOOP
END
crash:
FOR c = 1 TO 6
    _LIMIT 8
    COLOR 12
    FOR cx = dp - c TO dp + c
        FOR cy = 10 - c TO c + 10
            IF RND * 6 < 3 THEN _PRINTSTRING (cx, cy), "@"
        NEXT cy
    NEXT cx
NEXT c
COLOR 15
PRINT "YOU CRASHED"
INPUT "Play again (Y or N) ", ask$
ask$ = UCASE$(ask$)
IF ask$ = "N" THEN GOTO alldone
GOTO start
alldone:
END

Seriously, that's a loooooong course.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#3
I think erasing the track just might not be in the spirit of fair play.


Yeah the track could be shorter or maybe vary a bit more.
Reply
#4
(12-22-2022, 07:44 PM)James D Jarvis Wrote: I think erasing the track just might not be in the spirit of fair play.

Kirk would be totally onboard with it.

Pete
Reply
#5
Really nice game. I made a few improvements.

Code: (Select All)
'X-racer is an old school racing game using text graphics only
'press spacebar to get that engine going and < or > to steer, b to brake!
'press e for Pete's modification
CONST RACETRACKLEN = 2010
_TITLE "X-RACER"
track$ = "####OOO................OOO####"
n = 13
trend = 0
obstacle = 10
RANDOMIZE TIMER
DIM b$(RACETRACKLEN)
DIM nn(RACETRACKLEN)
start:
ask$ = "."
spd = 1
DO
    CLS
    FOR x = 1 TO RACETRACKLEN
        A$ = STRING$(n, 32)
        b$(x) = A$ + track$
        IF x > 100 AND x MOD obstacle THEN
            IF RND * 100 < obstacle THEN MID$(b$(x), n + INT(3 + RND * 18), 1) = "O"
        END IF

        n = n + INT(RND * 2) - INT(RND * 2) + trend
        IF n < 2 THEN n = 2
        IF n > 35 THEN n = 35
        nn(x) = n
        IF RND * 100 < 3 THEN
            SELECT CASE INT(RND * 3)
                CASE 0
                    trend = 0
                CASE 1
                    trend = -1

                CASE 2
                    trend = 1
            END SELECT
        END IF
    NEXT x
    b$(RACETRACKLEN - 19) = A$ + "####O============O####"
    b$(RACETRACKLEN - 18) = A$ + "####O            O####"
    b$(RACETRACKLEN - 17) = A$ + "####O  FINISH  O####"
    b$(RACETRACKLEN - 16) = A$ + "####O            O####"
    b$(RACETRACKLEN - 15) = A$ + "####O============O####"
    FOR x = 14 TO 0 STEP -1
        b$(RACETRACKLEN - x) = A$ + "####O            O####"
    NEXT x
    dp = nn(1) + 11
    op = dp
    FOR x = 1 TO RACETRACKLEN
        _LIMIT 20
        PRINT b$(x);
        IF x > 12 THEN
            IF MID$(b$(x - 13), dp, 1) = "O" THEN GOTO crash
        END IF
        op = dp
        IF x MOD 20 = 0 THEN
            PRINT " - "; x * 5
        ELSE
            PRINT
        END IF
        IF x > 10 THEN
            gg = 0
            DO
                _LIMIT 60
                gg = gg + 1
                kk$ = INKEY$
            LOOP UNTIL kk$ <> "" OR gg = 30 - spd
        END IF
        _PRINTSTRING (op, 9), "."
        IF x = 12 THEN t1 = TIMER
        SELECT CASE kk$
            CASE CHR$(27)
                _AUTODISPLAY
                GOTO alldone
            CASE ".", ">"
                op = dp
                dp = dp + 1
            CASE ",", "<"
                op = dp
                dp = dp - 1.
            CASE " "
                spd = spd + 1
                IF spd > 28 THEN spd = 28
            CASE "B", "b"
                spd = spd - 2
                IF spd < 1 THEN spd = 1
            case "E", "e"
                IF pete = 0 THEN
                    pete = 1
                    track$ = "                              "
                    FOR xx = 1 TO RACETRACKLEN - 20
                        A$ = STRING$(n, 32)
                        b$(xx) = A$ + track$
                    NEXT xx
                END IF
        END SELECT
        mph$ = "MPH : " + STR$(spd * 10)
        _PRINTSTRING (1, 1), mph$
        IF x > 10 THEN COLOR 12: _PRINTSTRING (dp, 10), "E": COLOR 15
        _DISPLAY
    NEXT x
    t2 = TIMER
    _AUTODISPLAY
    PRINT
    PRINT "Finished Course !"
    PRINT
    PRINT "Finish Time "; t2 - t1
    INPUT "Play again (Y or N) ", ask$
    ask$ = UCASE$(ask$)
    IF ask$ = "N" THEN GOTO alldone
LOOP
END
crash:
_AUTODISPLAY
FOR c = 1 TO 6
    _LIMIT 8
    COLOR 12
    FOR cx = dp - c TO dp + c
        FOR cy = 10 - c TO c + 10
            IF RND * 6 < 3 THEN _PRINTSTRING (cx, cy), "@"
        NEXT cy
    NEXT cx
NEXT c
COLOR 15
PRINT "YOU CRASHED"
INPUT "Play again (Y or N) ", ask$
ask$ = UCASE$(ask$)
IF ask$ = "N" THEN GOTO alldone
GOTO start
alldone:
END

Press [ESC] to quit.
Added "_DISPLAY" to make "MPH" display more tolerable.
Car is drawn properly only while moving down the course, but not before the spacebar could be pressed LOL.

Set "RACETRACKLEN" to a smaller value if you want a smaller racetrack. Currently it is set to the same value as before.
I haven't tested this particular change. I've just noticed those computations with "nn" array.
Reply
#6
Cool! 

Implemented a couple of your changes and a couple of mine (something isn't working right, I blame myself)

Code: (Select All)
'X-racer is an old school racing game using text graphics only
'press spacebar to get that engine going and < or > to steer  b to brake!
_Title "X-RACER"
track$ = "####OOO................OOO####"
n = 13
trend = 0
obstacle = 10
Randomize Timer
Dim b$(2010)
Dim nn(0 To 2010)
start:
ask$ = "."
spd = 1
tracksize = 310
srun = 8
Do
    Cls
    For x = 1 To tracksize
        A$ = String$(n, 32)
        b$(x) = A$ + track$
        If x > 100 And x Mod obstacle Then
            If Rnd * 100 < obstacle Then Mid$(b$(x), n + Int(3 + Rnd * 18), 1) = "O"
        End If

        n = n + Int(Rnd * 2) - Int(Rnd * 2) + trend
        If n < 2 Then n = 2
        If n > 35 Then n = 35
        nn(x) = n
        If nn(x - 1) = nn(x) Then srun = srun - 1 Else srun = 8
        If srun = 0 Then
            If n < 25 Then
                trend = 1
            Else
                trend = -1
            End If
        End If

        If Rnd * 100 < 3 Then
            Select Case Int(Rnd * 3)
                Case 0
                    trend = 0
                Case 1
                    trend = -1

                Case 2
                    trend = 1
            End Select
        End If
    Next x
    A$ = String$(n, 32)
    b$(tracksize - 20) = A$ + "####O============O####"
    b$(tracksize - 19) = A$ + "####O============O####"
    b$(tracksize - 18) = A$ + "####O            O####"
    b$(tracksize - 17) = A$ + "####O   FINISH   O####"
    b$(tracksize - 16) = A$ + "####O            O####"
    b$(tracksize - 15) = A$ + "####O============O####"
    For x = tracksize - 14 To tracksize
        A$ = String$(n, 32)
        b$(x) = A$ + "####O            O####"
    Next x
    dp = nn(10) + 15
    op = dp
    For x = 1 To tracksize
        _Limit 20
        _PrintString (op, 9), "."
        Print b$(x);
        If x > 12 Then
            If Mid$(b$(x - 13), dp, 1) = "O" Then GoTo crash
        End If
        op = dp
        If x Mod 20 = 0 Then
            Print " - "; x * 5
        Else
            Print
        End If
        If x > 10 Then
            gg = 0
            Do
                _Limit 60
                gg = gg + 1
                kk$ = InKey$
            Loop Until kk$ <> "" Or gg = 30 - spd
        End If
        If x = 12 Then t1 = Timer
        Select Case kk$
            Case ".", ">"
                op = dp
                dp = dp + 1

            Case ",", "<"
                op = dp
                dp = dp - 1.
            Case " "
                spd = spd + 1
                If spd > 28 Then spd = 28
            Case "b"
                spd = spd - 2
                If spd < 1 Then spd = 1
        End Select
        mph$ = "MPH : " + Str$(spd * 10)
        _PrintString (1, 1), mph$
        If x > 10 Then Color 12: _PrintString (dp, 10), "X": Color 15
        _Display
    Next x
    t2 = Timer
    Print
    Print "Finished Course !"
    Print
    Print "Finish Time "; t2 - t1
    Input "Play again (Y or N) ", ask$
    ask$ = UCase$(ask$)
    If ask$ = "N" Then GoTo alldone
Loop
End
crash:
For c = 1 To 6
    _Limit 8
    Color 12
    For cx = dp - c To dp + c
        For cy = 10 - c To c + 10
            If Rnd * 6 < 3 Then _PrintString (cx, cy), "@"
        Next cy
    Next cx
Next c
Color 15
Print "YOU CRASHED"
Input "Play again (Y or N) ", ask$
ask$ = UCase$(ask$)
If ask$ = "N" Then GoTo alldone
GoTo start
alldone:
End
Reply
#7
Add "_AUTODISPLAY" just below "crash:" (both without double-quotation marks) so it displays the car crash.

Also Pete isn't going to be very happy you left out his special feature...
Reply
#8
Oh E-Racer is a legit branch, just not one I'm working on.   This ain't the Kobayashi Maru after all.
Reply




Users browsing this thread: 2 Guest(s)