Author Topic: Alphabet Invaders  (Read 5497 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Alphabet Invaders
« on: July 21, 2019, 05:47:21 pm »
I made this game in ASIC 5.0 back in the 90's which is why you see so many lines in this game, ASIC was a lot like GW-BASIC. For example, you couldn't separate code lines on the same line using : and many other things you couldn't do. One thing is that I had to add goto to the IF/THEN commands which ASIC just did like If a$="Ken" then Ken: I also had to change the speed using _DELAY and RND stuff on it as well. I think ASIC couldn't even use the arrow keys, if I recall right, which is why originally this game had to use the numbers on the number pad  lol. So I changed that to arrow keys and added Esc instead of the old fashioned Q to quit. It's a very simple game, no graphics, just text animation. :D Soon I might try to make a game like this again, except you have to press the right letters on the keyboard to shoot the letter out of the sky. Someone made that back in the 90's but I have no idea who did it and would like a try myself. It would be a good way for people to learn how to type as well. But try this one first, you move your + guy back and forth to shoot the oncoming letters before they reach the bottom. You have to shoot down 100 of them to win the game. If you miss one, your guy explodes lol. Tell me what you think. :)

Code: QB64: [Select]
  1. _TITLE "Alphabet Invaders"
  2. begin:
  3. x = 20
  4. y = 20
  5. p = 0
  6.  
  7. PRINT "        Alphabet Invaders"
  8. PRINT "        -----------------"
  9. PRINT "           By Ken G."
  10. PRINT "Destroy 100 falling aliens to win the game."
  11. PRINT "         Use These Keys"
  12. PRINT "Left Arrow Key and Right Arrow Key"
  13. PRINT "          Esc=Quit"
  14. PRINT "        Space Bar=Fire"
  15. PRINT "You= +"
  16. PRINT "Fire Power= *"
  17. INPUT "Press Enter to begin.", a$
  18. pick:
  19. diffic:
  20. LOCATE 4, 10
  21. PRINT "Difficulty"
  22. LOCATE 5, 10
  23. PRINT "----------"
  24. PRINT "(1) 10 cannons - Easy"
  25. PRINT "(2) 5 cannons - Average"
  26. PRINT "(3) 3 cannons - Hard"
  27. PRINT "Type a number here (1 to 30):";
  28. INPUT dif
  29. IF dif > 3 THEN GOTO diffic:
  30. IF dif < 1 THEN GOTO diffic:
  31. IF dif = 1 THEN GOTO easy:
  32. IF dif = 2 THEN GOTO average:
  33. IF dif = 3 THEN GOTO hard:
  34. easy:
  35. m = 10
  36. GOTO wow:
  37. average:
  38. m = 5
  39. GOTO wow:
  40. hard:
  41. m = 3
  42. wow:
  43. GOTO ggo:
  44. miss:
  45. hy = y - 2
  46. jy = y - 1
  47. hx = x + 1
  48. jx = x - 1
  49. LOCATE y, x
  50. PRINT "@"
  51. LOCATE hy, hx
  52. PRINT "@"
  53. LOCATE jy, jx
  54. PRINT "@"
  55. LOCATE y, hx
  56. PRINT "@"
  57. LOCATE hy, x
  58. PRINT "@"
  59. LOCATE hy, jx
  60. PRINT "@"
  61. LOCATE jy, hx
  62. PRINT "@"
  63. LOCATE y, jx
  64. PRINT "@"
  65. SOUND 300, .5
  66. SOUND 200, .5
  67. m = m - 1
  68. IF m = 0 THEN GOTO lose:
  69. ggo:
  70. YY = 1
  71. LOCATE 10, 55
  72. PRINT "Score: ";
  73. LOCATE 12, 55
  74. PRINT "Cannons Left: ";
  75. L = INT(RND * 25) + 65
  76. B$ = CHR$(L)
  77. XX = INT(RND * 9) + 1
  78. XX = XX * 5
  79. N = 0
  80.  
  81. TIME1:
  82. N = N + 1
  83. IF N = 2 THEN GOTO GO:
  84. GOTO GO:
  85. ST:
  86. GO:
  87. N = 0
  88. LOCATE YY, XX
  89. PRINT " "
  90. YY = YY + 1
  91. ff = YY
  92. IF YY > 21 THEN GOTO miss:
  93. LOCATE YY, XX
  94. LOCATE y, x
  95. PRINT "+"
  96.  
  97. E$ = INKEY$
  98. IF E$ = CHR$(0) + CHR$(75) THEN GOTO LEFT1:
  99. IF E$ = CHR$(0) + CHR$(77) THEN GOTO RIGHT1:
  100. IF E$ = " " THEN GOTO FIRE:
  101. IF E$ = CHR$(27) THEN GOTO DONE:
  102. GOTO TIME1:
  103. LEFT1:
  104. LOCATE y, x
  105. PRINT " "
  106. x = x - 5
  107. IF x < 5 THEN GOTO LEFT2:
  108. GOTO GO:
  109. LEFT2:
  110. x = 5
  111. GOTO GO:
  112. RIGHT1:
  113. LOCATE y, x
  114. PRINT " "
  115. x = x + 5
  116. IF x > 50 THEN GOTO right2:
  117. GOTO GO:
  118. right2:
  119. x = 50
  120. GOTO GO:
  121. FIRE:
  122. R = x
  123. sy = y - 1
  124. FOR LS = ff TO sy
  125.     LOCATE LS, R
  126.     PRINT "*"
  127. NEXT LS
  128. SOUND 300, .5
  129. FOR LL = ff TO sy
  130.     LOCATE LL, R
  131.     PRINT " "
  132. NEXT LL
  133. IF x = XX THEN GOTO HIT:
  134. GOTO GO:
  135. HIT:
  136. p = p + 100
  137. tx = XX - 1
  138. rx = XX - 2
  139. LOCATE YY, tx
  140. PRINT "{ }"
  141. SOUND 600, .5
  142. _DELAY .15
  143. LOCATE YY, rx
  144. PRINT "{   }"
  145. SOUND 200, .5
  146. _DELAY .15
  147. cont:
  148. IF p = 10000 THEN GOTO WIN:
  149. GOTO ggo:
  150.  
  151. lose:
  152. LOCATE 3, 5
  153. PRINT "Y O U  L O S T"
  154. GOTO ending:
  155.  
  156. WIN:
  157. LOCATE 1, 5
  158. PRINT "Score: ";
  159. LOCATE 3, 5
  160. PRINT "Y O U   W I N   T H E   G A M E"
  161. ending:
  162. SOUND 230, .5
  163. SOUND 200, .5
  164. SOUND 210, .5
  165. SOUND 150, .5
  166. SOUND 100, .5
  167. PRINT "Do you want to play again(Y/N)";
  168. INPUT ag$
  169. IF ag$ = "Y" OR ag$ = "y" OR ag$ = "YES" OR ag$ = "Yes" OR ag$ = "yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  170. DONE:
  171.  
« Last Edit: July 21, 2019, 05:56:41 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Alphabet Invaders
« Reply #1 on: July 21, 2019, 05:54:36 pm »
Cool game... I still get killed off but a cool game just the same.... lol
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Alphabet Invaders
« Reply #2 on: July 21, 2019, 05:55:45 pm »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #3 on: July 21, 2019, 05:57:42 pm »
Thanks guys. I just removed 3 lines of code with time variables that are not needed anymore, so if you want, you can copy/paste it again with the same code above.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #4 on: July 21, 2019, 06:04:09 pm »
LOL Pete dang that's pretty good programming! Amazing how you copied the IDE perfectly lol. Great job.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #5 on: July 21, 2019, 06:05:42 pm »
This used to ask you what kind of computer you had so it could set the TIMER command even with the speed of your computer lol. Gotta love the old days.  Oh, and ASIC also changed the SOUND command so you had to actually type in the frequency of the sound, like this had around SOUND 20000,1 and when I played it on this computer, it squeeled so much I thought it would break my windows. LOL
« Last Edit: July 21, 2019, 06:08:30 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #6 on: July 21, 2019, 06:30:54 pm »
I see there's too many other games out there that use Space Invaders as a way to learn to type on the keyboard, so I'm going to try to think of something else.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Alphabet Invaders
« Reply #7 on: July 21, 2019, 07:17:57 pm »
Yep, I suspected I'd lose again. I think the old style games are often the most challenging.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Alphabet Invaders
« Reply #8 on: July 21, 2019, 09:42:32 pm »
Sorry I can not shoot at B nor will I shoot at U. :D

I like how the brackets fly away when letter is shot.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #9 on: July 21, 2019, 09:58:39 pm »
Thanks B+. :) It's a fun little game, would be good for new programmers to learn. Same with my Lemonade Stand.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Alphabet Invaders
« Reply #10 on: July 22, 2019, 08:21:50 am »
Nice game. I like these types of the game where you have to shoot to enemies. (like COD-MW2, BF3...,  etc) :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Alphabet Invaders
« Reply #11 on: July 22, 2019, 05:27:26 pm »
Cool
fine to type type to shoot letters!
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Alphabet Invaders
« Reply #12 on: July 22, 2019, 06:10:40 pm »
Thanks guys!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Alphabet Invaders
« Reply #13 on: July 22, 2019, 07:48:26 pm »
Yep, I suspected I'd lose again. I think the old style games are often the most challenging.

What is challenging is to read through this spaghetti to find a place to install a _LIMIT so you can adjust the play action to your system and skill level.

Now you can!
Code: QB64: [Select]
  1. _TITLE "Alpha-Bit Invaders" 'mod Ken's original from spaghetti version
  2. DEFINT A-Z
  3. SCREEN _NEWIMAGE(640, 360, 32)
  4. DIM SHARED x, y, p, m, xx, yy, gameOver, goAgain
  5. goAgain = -1
  6. COLOR _RGB32(180, 180, 225), _RGB32(25, 10, 50)
  7.     Begin
  8.     GoRounds
  9. LOOP UNTIL goAgain = 0
  10.  
  11. SUB GoRounds
  12.     DIM b$, e$, l
  13.     WHILE gameOver = 0 'setup next letter round
  14.         yy = 1
  15.         CLS
  16.         LOCATE 10, 55: PRINT "Score: "; p;
  17.         LOCATE 12, 55: PRINT "Cannons Left: "; m;
  18.         b$ = CHR$(INT(RND * 26) + 65)
  19.         xx = (INT(RND * 9) + 1) * 5
  20.         LOCATE yy, xx: PRINT b$;
  21.         _DELAY .5
  22.         DO
  23.             LOCATE yy, xx: PRINT " ";
  24.             yy = yy + 1
  25.             IF yy > 21 THEN Miss: EXIT DO
  26.             LOCATE yy, xx: PRINT b$;
  27.             e$ = INKEY$
  28.             IF e$ = CHR$(0) + CHR$(75) THEN
  29.                 LOCATE y, x: PRINT " ";
  30.                 x = x - 5
  31.                 IF x < 5 THEN x = 5
  32.                 LOCATE y, x: PRINT "+";
  33.             END IF
  34.             IF e$ = CHR$(0) + CHR$(77) THEN
  35.                 LOCATE y, x: PRINT " ";
  36.                 x = x + 5
  37.                 IF x > 50 THEN x = 50
  38.                 LOCATE y, x: PRINT "+";
  39.             END IF
  40.             IF e$ = " " THEN
  41.                 FOR l = yy TO y - 1
  42.                     LOCATE l, x: PRINT "*";
  43.                 NEXT
  44.                 _DELAY .1
  45.                 SOUND 300, .5
  46.                 FOR l = yy TO y - 1
  47.                     LOCATE l, x: PRINT " ";
  48.                 NEXT
  49.                 IF x = xx THEN Hit: EXIT DO
  50.             END IF
  51.             IF e$ = CHR$(27) THEN END
  52.             LOCATE y, x: PRINT "+";
  53.             _LIMIT 10  '<<<<<<<<<<<<<<<<<<<<< old geezers with bad eyes adjust here!
  54.         LOOP
  55.     WEND
  56.     Ending
  57.  
  58. SUB Hit
  59.     p = p + 100
  60.     LOCATE yy, xx - 1: PRINT "{ }";
  61.     SOUND 600, .5
  62.     _DELAY .15
  63.     LOCATE yy, xx - 2
  64.     PRINT "{   }";
  65.     SOUND 200, .5
  66.     _DELAY .15
  67.     IF p = 10000 THEN
  68.         CLS
  69.         LOCATE 10, 55: PRINT "Score: "; p;
  70.         LOCATE 12, 55: PRINT "Cannons Left: "; m;
  71.         LOCATE 1, 5: PRINT "Score: "; p;
  72.         LOCATE 3, 5: PRINT "Y O U   W I N   T H E   G A M E";
  73.         gameOver = -1
  74.     END IF
  75.  
  76. SUB Miss
  77.     DIM row, col
  78.     FOR row = (y - 1) TO (y + 1)
  79.         FOR col = (x - 1) TO (x + 1)
  80.             IF row = y AND col = x THEN LOCATE row, col: PRINT " "; ELSE LOCATE row, col: PRINT "@";
  81.         NEXT
  82.     NEXT
  83.     SOUND 300, .5
  84.     SOUND 200, .5
  85.     _DELAY 1
  86.     m = m - 1
  87.     IF m = 0 THEN
  88.         CLS
  89.         LOCATE 10, 55: PRINT "Score: "; p;
  90.         LOCATE 12, 55: PRINT "Cannons Left: "; m;
  91.         LOCATE 3, 5: PRINT "Y O U  L O S T";: gameOver = -1
  92.     END IF
  93.  
  94. SUB Ending
  95.     DIM ag$, k$
  96.     SOUND 230, .5
  97.     SOUND 200, .5
  98.     SOUND 210, .5
  99.     SOUND 150, .5
  100.     SOUND 100, .5
  101.     PRINT
  102.     CP "Do you want to play again(Y/N)"
  103.     WHILE LEN(ag$) = 0
  104.         k$ = INKEY$
  105.         IF LEN(k$) THEN ag$ = k$
  106.     WEND
  107.     IF LEFT$(UCASE$(ag$), 1) <> "Y" THEN goAgain = 0
  108.  
  109. SUB Begin
  110.     DIM dif, k$
  111.     x = 20: y = 20: p = 0: gameOver = 0
  112.     CLS
  113.     LOCATE 4, 1: CP "Alpha-Bit Invaders"
  114.     CP "-----------------": PRINT
  115.     CP "By Ken G. mod bplus 2019-07-22": PRINT
  116.     CP "Destroy 100 falling aliens to win the game.": PRINT: PRINT
  117.     CP "Use These Keys": PRINT
  118.     CP "Arrow Keys Left and Right to position under letter for firing."
  119.     CP "Space Bar to Fire": PRINT
  120.     CP "You are here + firing these *": PRINT
  121.     CP "Esc to Quit": PRINT
  122.     CP "Press any to begin."
  123.     SLEEP
  124.     CLS
  125.     DO
  126.         CLS: PRINT: PRINT: PRINT
  127.         CP "Difficulty"
  128.         CP "----------"
  129.         PRINT
  130.         CP "(1) 10 cannons - Easy  "
  131.         CP "(2) 5 cannons - Average"
  132.         CP "(3) 3 cannons - Hard   "
  133.         PRINT
  134.         CP "Press a number (1 to 3):"
  135.         WHILE dif = 0
  136.             k$ = INKEY$
  137.             IF LEN(k$) THEN dif = VAL(k$)
  138.         WEND
  139.         IF dif = 1 THEN m = 10
  140.         IF dif = 2 THEN m = 5
  141.         IF dif = 3 THEN m = 3
  142.     LOOP UNTIL 0 < dif AND dif < 4
  143.  
  144. SUB CP (s$)
  145.     LOCATE CSRLIN, (80 - LEN(s$)) / 2: PRINT s$
  146.  
  147.  

EDIT: Almost missed, "Your guy explodes on Miss."
« Last Edit: July 22, 2019, 11:18:01 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Alphabet Invaders
« Reply #14 on: July 23, 2019, 03:09:47 am »
Really cool game :-D