Advertisement
LBASIC

A_WORM.BAS

Jun 5th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 1.97 KB | Source Code | 0 0
  1. '_|_|_|   A_WORM.BAS
  2. '_|_|_|   This program creates a 'worm' that eats all the characters
  3. '_|_|_|   on your screen. Hitting a key restores them and exits.
  4. '_|_|_|   No warrantee or guarantee is given or implied.
  5. '_|_|_|   Released to   PUBLIC DOMAIN   by Kurt Kuzba.  (5/10/96)
  6. DECLARE SUB worm ()
  7. TYPE bodySegments
  8.    x AS INTEGER
  9.    y AS INTEGER
  10. END TYPE
  11. worm
  12. SUB worm
  13.    DIM buf(4000) AS STRING * 1, body(11) AS bodySegments
  14.    DEF SEG = &HB800: RANDOMIZE (TIMER * 1000)
  15.    xd% = 0: yd% = 0: chx% = 0: chy% = 0: wc% = 0
  16.    FOR t% = 0 TO 3999: buf(t%) = CHR$(PEEK(t%)): NEXT
  17.    segs$ = CHR$(219) + CHR$(178) + CHR$(177) + CHR$(176) + "  "
  18.    FOR t% = 0 TO 10: body(t%).x = 12: body(t%).y = 39: NEXT
  19.    WHILE INKEY$ = ""
  20.       IF wc% = 0 THEN COLOR RND * 14 + 1, 0: clim% = RND * 50 + 50
  21.       wc% = (wc% + 1) MOD clim%
  22.       FOR t% = 9 TO 0 STEP -1
  23.          LOCATE body(t%).x, body(t%).y
  24.          WHILE (INP(&H3DA) AND 8) = 0: WEND
  25.          WHILE (INP(&H3DA) AND 8) <> 0: WEND
  26.          PRINT STRING$(2, MID$(segs$, t% \ 2 + 1, 1));
  27.          body(t% + 1).x = body(t%).x
  28.          body(t% + 1).y = body(t%).y
  29.       NEXT
  30.       IF chx% = 0 THEN
  31.          xd% = ((RND * 999) MOD 3) - 1
  32.          xlim% = RND * 20 + 10
  33.       END IF
  34.       chx% = (chx% + 1) MOD xlim%
  35.       IF chy% = 0 THEN
  36.          yd% = 2 * (((RND * 999) MOD 3) - 1)
  37.          ylim% = RND * 20 + 10
  38.       END IF
  39.       chy% = (chy% + 1) MOD ylim%
  40.       IF (yd% = 0) AND (xd% = 0) THEN
  41.          yd% = 2 - 4 * (INP(64) AND 1): xd% = 1 - 2 * (INP(64) AND 1)
  42.       END IF
  43.       IF (yd% < 0) AND (body(0).y < 3) THEN yd% = (RND * 999) AND 2
  44.       IF (yd% > 0) AND (body(0).y > 77) THEN yd% = -((RND * 999) AND 2)
  45.       IF (xd% < 0) AND (body(0).x = 1) THEN xd% = (RND * 999) AND 1
  46.       IF (xd% > 0) AND (body(0).x = 25) THEN xd% = -((RND * 999) AND 1)
  47.       body(0).y = body(0).y + yd%
  48.       body(0).x = body(0).x + xd%
  49.    WEND
  50.    FOR t% = 0 TO 3999: POKE t%, ASC(buf(t%)): NEXT
  51. END SUB
  52. '_|_|_|   end   A_WORM.BAS
  53.  
Tags: qbasic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement