Advertisement
LBASIC

TREKWAR.BAS

Jun 5th, 2023
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 5.13 KB | None | 0 0
  1. '============================================================================
  2. '     To: All                           Number: 11       Refer: 0009  
  3. '   From: Denis Boyles              Conference: FidoQBasic   (139)
  4. '   Date: 01-22-97 19:24              BBS Name: Exec-PC
  5. 'Subject: TrekWar experiment    1/      BBS ID: EXECPC
  6. '----------------------------------------------------------------------------
  7. '
  8. 'Hi All,
  9. 'Don't ask, :p but I was experimenting with a few things here and there and
  10. 'I came up with the following program. The USS Enterprise-D battles it out
  11. 'with a Klingon battle cruiser in space! Nothing super fancy here, just two
  12. 'little sprites that I drew for the ships. The sprites `fly' in wax on wax
  13. 'off motion using a random attack schedule. The attack schedule just decides
  14. 'which ship should fire at the other. A red dashed line is the Enterprise
  15. 'firing and a green dashed line is the Klingon.
  16. 'The program goes into a loop having the ships battle it out and keeps track
  17. 'of damage and wins. When you've had enough, just press the ESC key to quit
  18. 'the program.
  19. 'Enjoy!
  20. '  Denis Boyles
  21. '[Cut-'N'-Save-(TREKWAR.BAS)------------------------------------------------]
  22. 'TREKWAR.BAS - Public Domain by Denis Boyles
  23. '            ! Microsoft QBASIC v1.1
  24. '            ? a mad programming experiment involving the USS-Enterprise-D
  25. '              and a Klingon battle cruiser battling it out in space.
  26. DECLARE SUB ReadSprite ()
  27. DECLARE SUB ReadBits ()
  28. DECLARE SUB DrawSprite (x%, y%, c%, num%)
  29. DECLARE SUB DrawStars ()
  30. DECLARE SUB CalcCircle ()
  31. DEFINT A-Z
  32. CONST NumStars = 400
  33. CONST FlyRad = 80
  34. DIM SHARED sprite(2, 16), bits(16), cosx(360), siny(360)
  35. DIM spritea(324), spriteb(324)
  36. PRINT "Please Wait..."
  37. RANDOMIZE TIMER
  38. ReadSprite
  39. ReadBits
  40. CalcCircle
  41. SCREEN 13
  42. ct = 0: ed = 0: kd = 0: el = 0: kl = 0
  43. DEF SEG = &H40
  44. DrawSprite cosx(ct) + 220, siny(ct) + 100, 7, 0
  45. GET (cosx(ct) + 218, siny(ct) + 98)-(cosx(ct) + 238, siny(ct) + 120), spritea
  46. DrawSprite siny(ct) + 110, cosx(ct) + 100, 2, 1
  47. GET (siny(ct) + 108, cosx(ct) + 98)-(siny(ct) + 128, cosx(ct) + 120), spriteb
  48. CLS
  49. DrawStars
  50. LOCATE 1, 1
  51. PRINT USING "Enterprise Damage: ###% Wins: #####"; ed; kl
  52. PRINT USING "   Klingon Damage: ###% Wins: #####"; kd; el
  53. DO
  54.   WAIT &H3DA, 8
  55.   PUT (cosx(ct) + 218, siny(ct) + 98), spritea, PSET
  56.   PUT (siny(ct) + 108, cosx(ct) + 96), spriteb, PSET
  57.   SELECT CASE INT(RND * PEEK(&H6C))
  58.     CASE 0
  59.       LINE (cosx(ct) + 230, siny(ct) + 110)-(siny(ct) + 120, cosx(ct) + 110), 12, , &HFFF
  60.       WAIT &H3DA, 8: WAIT &H3DA, 8
  61.       LINE (cosx(ct) + 230, siny(ct) + 110)-(siny(ct) + 120, cosx(ct) + 110), 0
  62.       kd = kd + INT(RND * 5)
  63.       LOCATE 2, 20
  64.       PRINT USING "###%"; kd
  65.     CASE 1
  66.       LINE (siny(ct) + 120, cosx(ct) + 110)-(cosx(ct) + 230, siny(ct) + 110), 10, , &HFFF
  67.       WAIT &H3DA, 8: WAIT &H3DA, 8
  68.       LINE (siny(ct) + 120, cosx(ct) + 110)-(cosx(ct) + 230, siny(ct) + 110), 0
  69.       ed = ed + INT(RND * 5)
  70.       LOCATE 1, 20
  71.       PRINT USING "###%"; ed
  72.   END SELECT
  73.   IF kd >= 100 THEN
  74.     kd = 0
  75.     kl = kl + 1
  76.     LOCATE 2, 20
  77.     PRINT USING "###%"; kd
  78.     LOCATE 1, 31
  79.     PRINT USING "#####"; kl
  80.     FOR r = 0 TO 32
  81.       WAIT &H3DA, 8
  82.       CIRCLE (siny(ct) + 120, cosx(ct) + 110), r, 14, , , .5
  83.     NEXT
  84.     FOR r = 32 TO 0 STEP -1
  85.       WAIT &H3DA, 8
  86.       CIRCLE (siny(ct) + 120, cosx(ct) + 110), r, 0, , , .5
  87.     NEXT
  88.   END IF
  89.   IF ed >= 100 THEN
  90.     ed = 0
  91.     el = el + 1
  92.     LOCATE 1, 20
  93.     PRINT USING "###%"; ed
  94.     LOCATE 2, 31
  95.     PRINT USING "#####"; el
  96.     FOR r = 0 TO 32
  97.       WAIT &H3DA, 8
  98.       CIRCLE (cosx(ct) + 230, siny(ct) + 110), r, 14, , , .5
  99.     NEXT
  100.     FOR r = 32 TO 0 STEP -1
  101.       WAIT &H3DA, 8
  102.       CIRCLE (cosx(ct) + 230, siny(ct) + 110), r, 0, , , .5
  103.     NEXT
  104.   END IF
  105.   IF ct = 359 THEN
  106.     ct = 0
  107.   ELSE
  108.     ct = ct + 1
  109.   END IF
  110. LOOP WHILE INKEY$ <> CHR$(27)
  111. SCREEN 0
  112. WIDTH 80
  113. 'USS Enterprise, NCC-1701-D :) (b/w bitmap image)
  114. DATA &H0000,&H07E0,&H0FF0,&H0FF0,&H1FF8,&H1FF8,&H1FF8,&H1FF8
  115. DATA &H07E0,&H6186,&H6186,&H6186,&H7FFE,&H7FFE,&H63C6,&H0000
  116. 'Klingon Warbird
  117. DATA &HFE7F,&HFC3F,&HF81F,&HF81F,&HFC3F,&HFE7F,&HFE7F,&HFE7F
  118. DATA &H3C3C,&H300C,&H0000,&H0000,&H0000,&H0660,&H3FFC,&H3FFC
  119. '16 bits lookup table
  120. DATA &H0001,&H0002,&H0004,&H0008,&H0010,&H0020,&H0040,&H0080
  121. DATA &H0100,&H0200,&H0400,&H0800,&H1000,&H2000,&H4000,&H8000
  122.  
  123. SUB CalcCircle
  124.   FOR ct = 0 TO 359
  125.     cosx(ct) = INT(COS(ct * (3.14 / 180)) * FlyRad)
  126.     siny(ct) = INT(SIN(ct * (3.14 / 180)) * FlyRad)
  127.   NEXT
  128. END SUB
  129.  
  130. SUB DrawSprite (x, y, c, num)
  131.   FOR yct = 0 TO 15
  132.     FOR xct = 15 TO 0 STEP -1
  133.       IF sprite(num, yct) AND bits(xct) THEN
  134.         PSET (x + xct, y + yct), c
  135.       END IF
  136.     NEXT
  137.   NEXT
  138. END SUB
  139.  
  140. SUB DrawStars
  141.   DIM StarColor(3): StarColor(0) = 7: StarColor(1) = 8: StarColor(2) = 15
  142.   FOR ct = 1 TO NumStars
  143.     PSET (INT(RND * 320), INT(RND * 200)), StarColor(INT(RND * 3))
  144.   NEXT
  145. END SUB
  146.  
  147. SUB ReadBits
  148.   FOR ct = 0 TO 15
  149.     READ bits(ct)
  150.   NEXT
  151. END SUB
  152.  
  153. SUB ReadSprite
  154.   FOR num = 0 TO 1
  155.     FOR ct = 0 TO 15
  156.       READ sprite(num, ct)
  157.       IF num = 1 THEN
  158.         sprite(num, ct) = NOT sprite(num, ct)
  159.       END IF
  160.     NEXT
  161.   NEXT
  162. END SUB
  163.  
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement