12-23-2022, 12:15 PM
(This post was last modified: 12-23-2022, 12:17 PM by mnrvovrfc.
Edit Reason: Needed to add back OP's comments inside code
)
Really nice game. I made a few improvements.
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.
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.