Author Topic: Robot Invaders  (Read 8194 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #15 on: July 23, 2019, 09:55:38 pm »
It did need a larger gap, thanks B+! I widened it much more so now I think just about any hint of it seeming to hit, will hit. Thanks for the comments.

I also changed the looks of the robots a little bit and also the Boss. Plus I removed a couple of _DELAY's so now it runs a little faster and smoother.  Oh also, after the Boss, they shoot a little bit faster and stays on that speed for the rest of the game. I enjoy playing it more now myself, I hope you all do too.... and you can laugh at what the robots look like now. :))

(Note: This version does not make a Top Ten Scores list, the next code on this forum page does.)

Code: QB64: [Select]
  1. 'This version has 5 different colored robots with a Boss Robot after that.
  2. 'Each robot flies a different pattern.
  3. 'Game made on July 22, 2019
  4. 'By Ken G.
  5. 'Freeware
  6. 'I have put some descriptions in the code below to make it easier to learn from.
  7. begin:
  8. _TITLE "Tech Invaders"
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10. PRINT "                                 T E C H      I N V A D E R S"
  11. PRINT "                                        by Ken G."
  12. PRINT "                       Use left and right arrow keys to move back and forth."
  13. PRINT "                            Use up or down arrow keys to stop moving."
  14. PRINT "                                    Use space bar to fire."
  15. PRINT "                                      Esc to end anytime."
  16. INPUT "                                   Press Enter to start."; start$
  17. lives = 5
  18. points = 0
  19. ushoot = 0
  20. shooting = 0
  21. level = 1
  22. level2 = 1
  23. start = 0
  24. s = 0
  25. xt = 400: yt = 550
  26.  
  27. 'Draw your shooter.
  28. LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  29. LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  30.  
  31.  
  32. 'This is the start of the main loop.
  33. go:
  34. 'Choose a random place for the enemy.
  35. xx = INT(RND * 200) + 100
  36. yy = INT(RND * 100) + 40
  37.  
  38. 'Each level has its own loop so it can set a different equation and speed of the enemy.
  39.  
  40. IF level = 1 THEN
  41.     cl = 128: c2 = 127: c3 = 255
  42.     one:
  43.     'sec is not time, it's related to the coordinate of the enemy and speed it goes related to the loop speed.
  44.     sec = sec + .01
  45.     s = (60 - sec) * 6 + 180
  46.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  47.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  48.  
  49.     'GOSUB to drawing draws the enemy robot.
  50.     GOSUB drawing:
  51.     IF sec > 180 THEN
  52.         sec = 0
  53.         GOTO onedone:
  54.     END IF
  55.  
  56.     'GOSUB's go to keyboard control and enemy shooting.
  57.     GOSUB keyboard:
  58.     GOSUB shoot:
  59.     GOSUB youshoot2:
  60.     GOTO one:
  61.     onedone:
  62.  
  63. 'This level uses the spiral equation so it's a bit different than the others.
  64. IF level = 2 THEN
  65.     c1 = 127: c2 = 216: c3 = 127
  66.     FOR d = 160 TO 0 STEP -.125
  67.         _LIMIT 1000
  68.         s = s + .2
  69.         x = COS(s * 3.141592 / 180) * d
  70.         y = SIN(s * 3.151492 / 180) * d
  71.         GOSUB drawing:
  72.         GOSUB keyboard:
  73.         GOSUB shoot:
  74.         GOSUB youshoot2:
  75.     NEXT d
  76.     FOR d = 0 TO 160 STEP .125
  77.         _LIMIT 1000
  78.         s = s - .2
  79.         x = COS(s * 3.141592 / 180) * d
  80.         y = SIN(s * 3.151492 / 180) * d
  81.         GOSUB drawing:
  82.         GOSUB keyboard:
  83.         GOSUB shoot:
  84.         GOSUB youshoot2:
  85.     NEXT d
  86.  
  87. IF level = 3 THEN
  88.     c1 = 255: c2 = 0: c3 = 0
  89.     three:
  90.     sec = sec + .01
  91.     s = (60 - sec) * 6 + 180
  92.     x = INT(SIN(s / 90 * 3.141592) * 180) + 325
  93.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  94.     GOSUB drawing:
  95.     IF sec > 60 THEN
  96.         sec = 0
  97.         GOTO threedone:
  98.     END IF
  99.     GOSUB keyboard:
  100.     GOSUB shoot:
  101.     GOSUB youshoot2:
  102.     GOTO three:
  103.     threedone:
  104.  
  105. IF level = 4 THEN
  106.     c1 = 255: c2 = 255: c3 = 127
  107.     four:
  108.     sec = sec + .01
  109.     s = (60 - sec) * 6 + 180
  110.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  111.     y = INT(COS(s / 90 * 3.141592) * 180) + 225
  112.     GOSUB drawing:
  113.     IF sec > 60 THEN
  114.         sec = 0
  115.         GOTO fourdone:
  116.     END IF
  117.     GOSUB keyboard:
  118.     GOSUB shoot:
  119.     GOSUB youshoot2:
  120.     GOTO four:
  121.     fourdone:
  122. IF level = 5 THEN
  123.     c1 = 133: c2 = 28: c3 = 255
  124.     five:
  125.     sec = sec + .01
  126.     s = (60 - sec) * 6 + 180
  127.     x = INT(SIN(s / 135 * 3.141592) * 180) + 325
  128.     y = INT(COS(s / 33.75 * 3.141592) * 180) + 225
  129.     GOSUB drawing:
  130.     IF sec > 60 THEN
  131.         sec = 0
  132.         GOTO fivedone:
  133.     END IF
  134.     GOSUB keyboard:
  135.     GOSUB shoot:
  136.     GOSUB youshoot2:
  137.     GOTO five:
  138.     fivedone:
  139.  
  140. IF level = 6 THEN
  141.     c1 = 255: c2 = 0: c3 = 0
  142.     six:
  143.     sec = sec + .02
  144.     s = (60 - sec) * 6 + 180
  145.     x = INT(SIN(s / 45 * 3.141592) * 180) + 325
  146.     y = INT(COS(s / 360 * 3.141592) * 180) + 225
  147.     GOSUB drawing2:
  148.     IF sec > 120 THEN
  149.         sec = 0
  150.         GOTO sixdone:
  151.     END IF
  152.     GOSUB keyboard:
  153.     GOSUB shoot:
  154.     GOSUB youshoot2:
  155.     GOTO six:
  156.     sixdone:
  157.  
  158. IF level = 7 THEN level = 1
  159.  
  160. GOTO go:
  161. 'GOTO goes back to the start of the main loop.
  162.  
  163. 'Draws the enemy tank and erases it for animation.
  164. drawing:
  165. x2 = x + xx: y2 = y + yy
  166. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(c1, c2, c3)
  167. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(c1, c2, c3)
  168. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(c1, c2, c3)
  169. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(c1, c2, c3)
  170. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(c1, c2, c3), BF
  171. LINE (x2 + 5, y2 + 5)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  172. LINE (x2 + 12, y2 + 5)-(x2 + 15, y2 + 8), _RGB32(0, 0, 0), BF
  173. LINE (x2 + 5, y2 + 13)-(x2 + 15, y2 + 16), _RGB32(0, 0, 0), BF
  174. _DELAY .004
  175. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(0, 0, 0), BF
  176. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(0, 0, 0)
  177. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(0, 0, 0)
  178. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(0, 0, 0)
  179. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(0, 0, 0)
  180.  
  181.  
  182. 'Draws the Boss Robot.
  183. drawing2:
  184. x2 = x + xx: y2 = y + yy
  185. CIRCLE (x2, y2), 10, _RGB32(c1, c2, c3)
  186. LINE (x2 - 5, y2 - 5)-(x2 - 3, y2 - 2), _RGB32(c1, c2, c3), BF
  187. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(c1, c2, c3), BF
  188. LINE (x2 - 4, y2 + 7)-(x2 + 4, y2 + 8), _RGB32(c1, c2, c3), BF
  189. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(c1, c2, c3)
  190. CIRCLE (x2, y2 - 24), 4, _RGB32(c1, c2, c3)
  191. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(c1, c2, c3)
  192. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(c1, c2, c3)
  193. _DELAY .004
  194. CIRCLE (x2, y2), 10, _RGB32(0, 0, 0)
  195. LINE (x2 - 5, y2 - 5)-(x2 - 3, y2 - 2), _RGB32(0, 0, 0), BF
  196. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(0, 0, 0), BF
  197. LINE (x2 - 7, y2 + 7)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  198. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(0, 0, 0)
  199. CIRCLE (x2, y2 - 24), 4, _RGB32(0, 0, 0)
  200. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(0, 0, 0)
  201. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(0, 0, 0)
  202.  
  203. 'Keyboard control for your movement and shooting.
  204. keyboard:
  205. _LIMIT 1000
  206. a$ = INKEY$
  207. IF a$ = CHR$(27) THEN END
  208. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: l = 0
  209. IF r = 1 THEN
  210.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  211.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  212.     xt = xt + 1
  213.     IF xt > 780 THEN xt = 780
  214.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  215.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  216. IF a$ = CHR$(0) + CHR$(75) THEN l = 1: r = 0
  217. IF l = 1 THEN
  218.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  219.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  220.     xt = xt - 1
  221.     IF xt < 0 THEN xt = 0
  222.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  223.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  224. IF a$ = CHR$(0) + CHR$(72) OR a$ = CHR$(0) + CHR$(80) THEN
  225.     r = 0: l = 0
  226.  
  227. IF a$ = " " THEN GOSUB youshoot:
  228.  
  229. 'The start of your shot.
  230. youshoot:
  231. _LIMIT 1000
  232. IF ushoot = 0 THEN
  233.     sx2 = xt + 10
  234.     sy2 = yt - 11
  235.     ushoot = 1
  236.     SOUND 400, .5
  237.  
  238. 'The drawing and movement of your shot and if it reaches the enemy.
  239. youshoot2:
  240. _LIMIT 1000
  241. IF ushoot = 1 THEN
  242.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  243.     sy2 = sy2 - 3
  244.     IF sy2 < 0 THEN ushoot = 0: RETURN
  245.     CIRCLE (sx2, sy2), 5, _RGB32(255, 0, 0)
  246.     IF sx2 > x2 - 21 AND sx2 < x2 + 41 AND sy2 > y2 - 11 AND sy2 < y2 + 21 THEN
  247.         CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  248.         SOUND 200, 1
  249.         SOUND 100, 1
  250.         FOR explosion = 1 TO 30
  251.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(255, 0, 0)
  252.             _DELAY .02
  253.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(0, 0, 0)
  254.         NEXT explosion
  255.         LINE (x2 - 21, y2 - 21)-(x2 + 41, y2 + 41), _RGB32(0, 0, 0), BF
  256.         points = points + 100
  257.         IF points / 500 = INT(points / 500) THEN level = level + 1: level2 = level2 + 1
  258.         lives$ = STR$(lives)
  259.         points$ = STR$(points)
  260.         level$ = STR$(level2)
  261.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  262.         ushoot = 0
  263.         GOTO go:
  264.     END IF
  265.  
  266. 'The enemy's shot and if it reaches you.
  267. shoot:
  268. _LIMIT 1000
  269. IF shooting = 0 THEN
  270.     IF level2 = 1 THEN shh = 9970
  271.     IF level2 = 2 THEN shh = 9968
  272.     IF level2 = 3 THEN shh = 9966
  273.     IF level2 = 4 THEN shh = 9964
  274.     IF level2 = 5 THEN shh = 9962
  275.     IF level2 = 6 THEN shh = 9940
  276.     IF level2 > 6 THEN shh = 9930
  277.     sh = INT(RND * 10000) + 1
  278.     IF sh < shh THEN RETURN
  279.     sx = x2 + 10
  280.     sy = y2 + 10
  281.     shooting = 1
  282.     SOUND 300, .5
  283. IF shooting = 1 THEN
  284.     CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  285.     sy = sy + 3
  286.     IF sy > 620 THEN shooting = 0: RETURN
  287.     CIRCLE (sx, sy), 5, _RGB32(255, 0, 0)
  288.     IF sx > xt - 1 AND sx < xt + 21 AND sy > yt - 1 AND sy < yt + 21 THEN
  289.         CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  290.         SOUND 200, 1
  291.         SOUND 100, 1
  292.         FOR explosion2 = 1 TO 30
  293.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(255, 0, 0)
  294.             _DELAY .02
  295.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(0, 0, 0)
  296.         NEXT explosion2
  297.         lives = lives - 1
  298.         lives$ = STR$(lives)
  299.         points$ = STR$(points)
  300.         level$ = STR$(level2)
  301.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  302.         LINE (xt - 22, yt - 42)-(xt + 42, yt + 42), _RGB32(0, 0, 0), BF
  303.         IF lives = 0 THEN
  304.             LOCATE 20, 40: PRINT "G A M E   O V E R"
  305.             LOCATE 22, 40: PRINT "Score: "; points
  306.             LOCATE 23, 40: PRINT "Level: "; level2
  307.             LOCATE 24, 40: INPUT "Play Again (Yes/No)", ag$
  308.             IF ag$ = "Y" OR ag$ = "y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "YEs" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO begin:
  309.             END
  310.         END IF
  311.         shooting = 0
  312.         RETURN
  313.     END IF
  314.  
  315.  
  316.  

« Last Edit: July 24, 2019, 12:09:06 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Robot Invaders
« Reply #16 on: July 23, 2019, 10:31:11 pm »
Love it! sure beats ping pong!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #17 on: July 24, 2019, 12:07:34 am »
LOL! Thanks!

Tonight I added a Top Ten Scores sheet to it, using the Race Car one we made a few days ago. So if you run this, it will automatically make a file called TopTenTech.txt and it will put it in the same directory as the program you run this in. I added a few new names and a couple of the old ones and of course adjusted the scores to this game. Have fun!

(Note: I changed the looks of the Boss Robot to look more like a robot on the code after this on the forum page. )

Code: QB64: [Select]
  1. 'This version has 5 different colored robots with a Boss Robot after that.
  2. 'Each robot flies a different pattern.
  3. 'Game made on July 22, 2019
  4. 'By Ken G.
  5. 'Freeware
  6. 'I have put some descriptions in the code below to make it easier to learn from.
  7. begin:
  8. DIM name$(50), nm$(50), score(50), sccc(50)
  9. _TITLE "Tech Invaders"
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. PRINT "                                 T E C H      I N V A D E R S"
  12. PRINT "                                        by Ken G."
  13. PRINT "                       Use left and right arrow keys to move back and forth."
  14. PRINT "                            Use up or down arrow keys to stop moving."
  15. PRINT "                                    Use space bar to fire."
  16. PRINT "                                      Esc to end anytime."
  17. INPUT "                                   Press Enter to start.", start$
  18. lives = 5
  19. points = 0
  20. ushoot = 0
  21. shooting = 0
  22. level = 1
  23. level2 = 1
  24. start = 0
  25. s = 0
  26. xt = 400: yt = 550
  27.  
  28. 'Draw your shooter.
  29. LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  30. LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  31.  
  32.  
  33. 'This is the start of the main loop.
  34. go:
  35. 'Choose a random place for the enemy.
  36. xx = INT(RND * 200) + 100
  37. yy = INT(RND * 100) + 40
  38.  
  39. 'Each level has its own loop so it can set a different equation and speed of the enemy.
  40.  
  41. IF level = 1 THEN
  42.     cl = 128: c2 = 127: c3 = 255
  43.     one:
  44.     'sec is not time, it's related to the coordinate of the enemy and speed it goes related to the loop speed.
  45.     sec = sec + .01
  46.     s = (60 - sec) * 6 + 180
  47.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  48.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  49.  
  50.     'GOSUB to drawing draws the enemy robot.
  51.     GOSUB drawing:
  52.     IF sec > 180 THEN
  53.         sec = 0
  54.         GOTO onedone:
  55.     END IF
  56.  
  57.     'GOSUB's go to keyboard control and enemy shooting.
  58.     GOSUB keyboard:
  59.     GOSUB shoot:
  60.     GOSUB youshoot2:
  61.     GOTO one:
  62.     onedone:
  63.  
  64. 'This level uses the spiral equation so it's a bit different than the others.
  65. IF level = 2 THEN
  66.     c1 = 127: c2 = 216: c3 = 127
  67.     FOR d = 160 TO 0 STEP -.125
  68.         _LIMIT 1000
  69.         s = s + .2
  70.         x = COS(s * 3.141592 / 180) * d
  71.         y = SIN(s * 3.151492 / 180) * d
  72.         GOSUB drawing:
  73.         GOSUB keyboard:
  74.         GOSUB shoot:
  75.         GOSUB youshoot2:
  76.     NEXT d
  77.     FOR d = 0 TO 160 STEP .125
  78.         _LIMIT 1000
  79.         s = s - .2
  80.         x = COS(s * 3.141592 / 180) * d
  81.         y = SIN(s * 3.151492 / 180) * d
  82.         GOSUB drawing:
  83.         GOSUB keyboard:
  84.         GOSUB shoot:
  85.         GOSUB youshoot2:
  86.     NEXT d
  87.  
  88. IF level = 3 THEN
  89.     c1 = 255: c2 = 0: c3 = 0
  90.     three:
  91.     sec = sec + .01
  92.     s = (60 - sec) * 6 + 180
  93.     x = INT(SIN(s / 90 * 3.141592) * 180) + 325
  94.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  95.     GOSUB drawing:
  96.     IF sec > 60 THEN
  97.         sec = 0
  98.         GOTO threedone:
  99.     END IF
  100.     GOSUB keyboard:
  101.     GOSUB shoot:
  102.     GOSUB youshoot2:
  103.     GOTO three:
  104.     threedone:
  105.  
  106. IF level = 4 THEN
  107.     c1 = 255: c2 = 255: c3 = 127
  108.     four:
  109.     sec = sec + .01
  110.     s = (60 - sec) * 6 + 180
  111.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  112.     y = INT(COS(s / 90 * 3.141592) * 180) + 225
  113.     GOSUB drawing:
  114.     IF sec > 60 THEN
  115.         sec = 0
  116.         GOTO fourdone:
  117.     END IF
  118.     GOSUB keyboard:
  119.     GOSUB shoot:
  120.     GOSUB youshoot2:
  121.     GOTO four:
  122.     fourdone:
  123. IF level = 5 THEN
  124.     c1 = 133: c2 = 28: c3 = 255
  125.     five:
  126.     sec = sec + .01
  127.     s = (60 - sec) * 6 + 180
  128.     x = INT(SIN(s / 135 * 3.141592) * 180) + 325
  129.     y = INT(COS(s / 33.75 * 3.141592) * 180) + 225
  130.     GOSUB drawing:
  131.     IF sec > 60 THEN
  132.         sec = 0
  133.         GOTO fivedone:
  134.     END IF
  135.     GOSUB keyboard:
  136.     GOSUB shoot:
  137.     GOSUB youshoot2:
  138.     GOTO five:
  139.     fivedone:
  140.  
  141. IF level = 6 THEN
  142.     c1 = 255: c2 = 0: c3 = 0
  143.     six:
  144.     sec = sec + .02
  145.     s = (60 - sec) * 6 + 180
  146.     x = INT(SIN(s / 45 * 3.141592) * 180) + 325
  147.     y = INT(COS(s / 360 * 3.141592) * 180) + 225
  148.     GOSUB drawing2:
  149.     IF sec > 120 THEN
  150.         sec = 0
  151.         GOTO sixdone:
  152.     END IF
  153.     GOSUB keyboard:
  154.     GOSUB shoot:
  155.     GOSUB youshoot2:
  156.     GOTO six:
  157.     sixdone:
  158.  
  159. IF level = 7 THEN level = 1
  160.  
  161. GOTO go:
  162. 'GOTO goes back to the start of the main loop.
  163.  
  164. 'Draws the enemy tank and erases it for animation.
  165. drawing:
  166. x2 = x + xx: y2 = y + yy
  167. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(c1, c2, c3)
  168. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(c1, c2, c3)
  169. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(c1, c2, c3)
  170. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(c1, c2, c3)
  171. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(c1, c2, c3), BF
  172. LINE (x2 + 5, y2 + 5)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  173. LINE (x2 + 12, y2 + 5)-(x2 + 15, y2 + 8), _RGB32(0, 0, 0), BF
  174. LINE (x2 + 5, y2 + 13)-(x2 + 15, y2 + 16), _RGB32(0, 0, 0), BF
  175. _DELAY .004
  176. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(0, 0, 0), BF
  177. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(0, 0, 0)
  178. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(0, 0, 0)
  179. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(0, 0, 0)
  180. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(0, 0, 0)
  181.  
  182.  
  183. 'Draws the Boss Robot.
  184. drawing2:
  185. x2 = x + xx: y2 = y + yy
  186. CIRCLE (x2, y2), 10, _RGB32(c1, c2, c3)
  187. LINE (x2 - 5, y2 - 5)-(x2 - 3, y2 - 2), _RGB32(c1, c2, c3), BF
  188. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(c1, c2, c3), BF
  189. LINE (x2 - 4, y2 + 7)-(x2 + 4, y2 + 8), _RGB32(c1, c2, c3), BF
  190. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(c1, c2, c3)
  191. CIRCLE (x2, y2 - 24), 4, _RGB32(c1, c2, c3)
  192. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(c1, c2, c3)
  193. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(c1, c2, c3)
  194. _DELAY .004
  195. CIRCLE (x2, y2), 10, _RGB32(0, 0, 0)
  196. LINE (x2 - 5, y2 - 5)-(x2 - 3, y2 - 2), _RGB32(0, 0, 0), BF
  197. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(0, 0, 0), BF
  198. LINE (x2 - 7, y2 + 7)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  199. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(0, 0, 0)
  200. CIRCLE (x2, y2 - 24), 4, _RGB32(0, 0, 0)
  201. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(0, 0, 0)
  202. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(0, 0, 0)
  203.  
  204. 'Keyboard control for your movement and shooting.
  205. keyboard:
  206. _LIMIT 1000
  207. a$ = INKEY$
  208. IF a$ = CHR$(27) THEN END
  209. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: l = 0
  210. IF r = 1 THEN
  211.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  212.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  213.     xt = xt + 1
  214.     IF xt > 780 THEN xt = 780
  215.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  216.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  217. IF a$ = CHR$(0) + CHR$(75) THEN l = 1: r = 0
  218. IF l = 1 THEN
  219.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  220.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  221.     xt = xt - 1
  222.     IF xt < 0 THEN xt = 0
  223.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  224.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  225. IF a$ = CHR$(0) + CHR$(72) OR a$ = CHR$(0) + CHR$(80) THEN
  226.     r = 0: l = 0
  227.  
  228. IF a$ = " " THEN GOSUB youshoot:
  229.  
  230. 'The start of your shot.
  231. youshoot:
  232. _LIMIT 1000
  233. IF ushoot = 0 THEN
  234.     sx2 = xt + 10
  235.     sy2 = yt - 11
  236.     ushoot = 1
  237.     SOUND 400, .5
  238.  
  239. 'The drawing and movement of your shot and if it reaches the enemy.
  240. youshoot2:
  241. _LIMIT 1000
  242. IF ushoot = 1 THEN
  243.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  244.     sy2 = sy2 - 3
  245.     IF sy2 < 0 THEN ushoot = 0: RETURN
  246.     CIRCLE (sx2, sy2), 5, _RGB32(255, 0, 0)
  247.     IF sx2 > x2 - 21 AND sx2 < x2 + 41 AND sy2 > y2 - 11 AND sy2 < y2 + 21 THEN
  248.         CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  249.         SOUND 200, 1
  250.         SOUND 100, 1
  251.         FOR explosion = 1 TO 30
  252.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(255, 0, 0)
  253.             _DELAY .02
  254.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(0, 0, 0)
  255.         NEXT explosion
  256.         LINE (x2 - 21, y2 - 21)-(x2 + 41, y2 + 41), _RGB32(0, 0, 0), BF
  257.         points = points + 100
  258.         IF points / 500 = INT(points / 500) THEN level = level + 1: level2 = level2 + 1
  259.         lives$ = STR$(lives)
  260.         points$ = STR$(points)
  261.         level$ = STR$(level2)
  262.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  263.         ushoot = 0
  264.         GOTO go:
  265.     END IF
  266.  
  267. 'The enemy's shot and if it reaches you.
  268. shoot:
  269. _LIMIT 1000
  270. IF shooting = 0 THEN
  271.     IF level2 = 1 THEN shh = 9970
  272.     IF level2 = 2 THEN shh = 9968
  273.     IF level2 = 3 THEN shh = 9966
  274.     IF level2 = 4 THEN shh = 9964
  275.     IF level2 = 5 THEN shh = 9962
  276.     IF level2 = 6 THEN shh = 9940
  277.     IF level2 > 6 THEN shh = 9930
  278.     sh = INT(RND * 10000) + 1
  279.     IF sh < shh THEN RETURN
  280.     sx = x2 + 10
  281.     sy = y2 + 10
  282.     shooting = 1
  283.     SOUND 300, .5
  284. IF shooting = 1 THEN
  285.     CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  286.     sy = sy + 3
  287.     IF sy > 620 THEN shooting = 0: RETURN
  288.     CIRCLE (sx, sy), 5, _RGB32(255, 0, 0)
  289.     IF sx > xt - 1 AND sx < xt + 21 AND sy > yt - 1 AND sy < yt + 21 THEN
  290.         CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  291.         SOUND 200, 1
  292.         SOUND 100, 1
  293.         FOR explosion2 = 1 TO 30
  294.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(255, 0, 0)
  295.             _DELAY .02
  296.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(0, 0, 0)
  297.         NEXT explosion2
  298.         lives = lives - 1
  299.         lives$ = STR$(lives)
  300.         points$ = STR$(points)
  301.         level$ = STR$(level2)
  302.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  303.         LINE (xt - 22, yt - 42)-(xt + 42, yt + 42), _RGB32(0, 0, 0), BF
  304.         IF lives = 0 THEN
  305.             LOCATE 20, 40: PRINT "G A M E   O V E R"
  306.             LOCATE 22, 40: PRINT "Score: "; points
  307.             LOCATE 23, 40: PRINT "Level: "; level2
  308.             LOCATE 25, 40: INPUT "Press Enter to go to Top Ten Scores.", tt$
  309.  
  310.             'Top Ten Scores
  311.             scc = points
  312.             IF _FILEEXISTS("toptentech.txt") THEN
  313.             ELSE
  314.                 OPEN "toptentech.txt" FOR OUTPUT AS #1
  315.                 RESTORE originaltopten
  316.                 DO
  317.                     READ toptenname$, toptenscore!
  318.                     IF toptenname$ = "EOF" THEN EXIT DO
  319.                     PRINT #1, toptenname$
  320.                     PRINT #1, toptenscore!
  321.                 LOOP
  322.                 CLOSE #1
  323.             END IF
  324.  
  325.             OPEN "toptentech.txt" FOR INPUT AS #1
  326.             FOR n = 1 TO 10
  327.                 INPUT #1, name$(n)
  328.                 INPUT #1, score(n)
  329.                 IF scc > score(n) AND sct = 0 THEN
  330.                     nn = n
  331.                     PRINT "You have made the Top Ten!"
  332.                     typename:
  333.                     INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  334.                     IF LEN(nm$(nn)) > 25 THEN
  335.                         PRINT "Name too long, try again."
  336.                         GOTO typename:
  337.                     END IF
  338.                     sccc(nn) = scc
  339.                     sct = 1
  340.                 END IF
  341.                 IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  342.             NEXT n
  343.             CLOSE #1
  344.             nex5:
  345.             CLOSE #1
  346.             OPEN "toptentech.txt" FOR OUTPUT AS #1
  347.             FOR n = 1 TO nn
  348.                 IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  349.                 IF n = nn THEN
  350.                     PRINT #1, nm$(n)
  351.                     PRINT #1, sccc(n)
  352.                 END IF
  353.             NEXT n
  354.             nex6:
  355.             FOR n = nn TO 10
  356.                 PRINT #1, name$(n): PRINT #1, score(n)
  357.             NEXT n
  358.  
  359.             CLOSE #1
  360.             nex7:
  361.             CLS
  362.             PRINT: PRINT: PRINT
  363.             PRINT "                                 T O P    T E N "
  364.             PRINT: PRINT: PRINT
  365.             OPEN "toptentech.txt" FOR INPUT AS #1
  366.             FOR n = 1 TO 10
  367.                 IF EOF(1) THEN GOTO nex8:
  368.                 INPUT #1, name$(n)
  369.                 INPUT #1, score(n)
  370.                 PRINT "             "; n; ". "; name$(n); score(n)
  371.             NEXT n
  372.             nex8:
  373.             CLOSE #1
  374.             FOR n = 1 TO 10
  375.                 nm$(n) = ""
  376.                 score(n) = 0
  377.                 name$(n) = ""
  378.                 sccc(n) = 0
  379.             NEXT n
  380.             nn = 0
  381.             n = 0
  382.             sct = 0
  383.             scc = 0
  384.             LOCATE 23, 1
  385.             INPUT "Would you like to play again? (Yes/No)", ag$
  386.             IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" OR ag$ = "YEs" THEN GOTO begin:
  387.             END
  388.         END IF
  389.         shooting = 0
  390.         RETURN
  391.     END IF
  392.  
  393. originaltopten:
  394. DATA Space Ace,7000
  395. DATA Suzy Swift,6000
  396. DATA Speedy Spencer,5000
  397. DATA Super Sam,4000
  398. DATA Battery Bob,3000
  399. DATA Karen Kryptonite,2750
  400. DATA Quick Ken,2500
  401. DATA Tiger Tessa,2250
  402. DATA Arcade Joe,2000
  403. DATA How Do U Play,1750
  404.  
« Last Edit: July 24, 2019, 01:10:06 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #18 on: July 24, 2019, 01:09:04 am »
Lastly (I hope), I decided to change the looks of the Boss Robot to make him look more like a robot. Here is the code again, sorry for so many of them.

(Note: Woops, I have a slight color variable problem on one line on this, will post the fix after this posting.)

Code: QB64: [Select]
  1. 'This version has 5 different colored robots with a Boss Robot after that.
  2. 'Each robot flies a different pattern.
  3. 'Game made on July 22, 2019
  4. 'By Ken G.
  5. 'Freeware
  6. 'I have put some descriptions in the code below to make it easier to learn from.
  7. begin:
  8. DIM name$(50), nm$(50), score(50), sccc(50)
  9. _TITLE "Tech Invaders"
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. PRINT "                                 T E C H      I N V A D E R S"
  12. PRINT "                                        by Ken G."
  13. PRINT "                       Use left and right arrow keys to move back and forth."
  14. PRINT "                            Use up or down arrow keys to stop moving."
  15. PRINT "                                    Use space bar to fire."
  16. PRINT "                                      Esc to end anytime."
  17. INPUT "                                   Press Enter to start.", start$
  18. lives = 5
  19. points = 0
  20. ushoot = 0
  21. shooting = 0
  22. level = 1
  23. level2 = 1
  24. start = 0
  25. s = 0
  26. xt = 400: yt = 550
  27.  
  28. 'Draw your shooter.
  29. LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  30. LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  31.  
  32.  
  33. 'This is the start of the main loop.
  34. go:
  35. 'Choose a random place for the enemy.
  36. xx = INT(RND * 200) + 100
  37. yy = INT(RND * 100) + 40
  38.  
  39. 'Each level has its own loop so it can set a different equation and speed of the enemy.
  40.  
  41. IF level = 1 THEN
  42.     cl = 128: c2 = 127: c3 = 255
  43.     one:
  44.     'sec is not time, it's related to the coordinate of the enemy and speed it goes related to the loop speed.
  45.     sec = sec + .01
  46.     s = (60 - sec) * 6 + 180
  47.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  48.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  49.  
  50.     'GOSUB to drawing draws the enemy robot.
  51.     GOSUB drawing:
  52.     IF sec > 180 THEN
  53.         sec = 0
  54.         GOTO onedone:
  55.     END IF
  56.  
  57.     'GOSUB's go to keyboard control and enemy shooting.
  58.     GOSUB keyboard:
  59.     GOSUB shoot:
  60.     GOSUB youshoot2:
  61.     GOTO one:
  62.     onedone:
  63.  
  64. 'This level uses the spiral equation so it's a bit different than the others.
  65. IF level = 2 THEN
  66.     c1 = 127: c2 = 216: c3 = 127
  67.     FOR d = 160 TO 0 STEP -.125
  68.         _LIMIT 1000
  69.         s = s + .2
  70.         x = COS(s * 3.141592 / 180) * d
  71.         y = SIN(s * 3.151492 / 180) * d
  72.         GOSUB drawing:
  73.         GOSUB keyboard:
  74.         GOSUB shoot:
  75.         GOSUB youshoot2:
  76.     NEXT d
  77.     FOR d = 0 TO 160 STEP .125
  78.         _LIMIT 1000
  79.         s = s - .2
  80.         x = COS(s * 3.141592 / 180) * d
  81.         y = SIN(s * 3.151492 / 180) * d
  82.         GOSUB drawing:
  83.         GOSUB keyboard:
  84.         GOSUB shoot:
  85.         GOSUB youshoot2:
  86.     NEXT d
  87.  
  88. IF level = 3 THEN
  89.     c1 = 255: c2 = 0: c3 = 0
  90.     three:
  91.     sec = sec + .01
  92.     s = (60 - sec) * 6 + 180
  93.     x = INT(SIN(s / 90 * 3.141592) * 180) + 325
  94.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  95.     GOSUB drawing:
  96.     IF sec > 60 THEN
  97.         sec = 0
  98.         GOTO threedone:
  99.     END IF
  100.     GOSUB keyboard:
  101.     GOSUB shoot:
  102.     GOSUB youshoot2:
  103.     GOTO three:
  104.     threedone:
  105.  
  106. IF level = 4 THEN
  107.     c1 = 255: c2 = 255: c3 = 127
  108.     four:
  109.     sec = sec + .01
  110.     s = (60 - sec) * 6 + 180
  111.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  112.     y = INT(COS(s / 90 * 3.141592) * 180) + 225
  113.     GOSUB drawing:
  114.     IF sec > 60 THEN
  115.         sec = 0
  116.         GOTO fourdone:
  117.     END IF
  118.     GOSUB keyboard:
  119.     GOSUB shoot:
  120.     GOSUB youshoot2:
  121.     GOTO four:
  122.     fourdone:
  123. IF level = 5 THEN
  124.     c1 = 133: c2 = 28: c3 = 255
  125.     five:
  126.     sec = sec + .01
  127.     s = (60 - sec) * 6 + 180
  128.     x = INT(SIN(s / 135 * 3.141592) * 180) + 325
  129.     y = INT(COS(s / 33.75 * 3.141592) * 180) + 225
  130.     GOSUB drawing:
  131.     IF sec > 60 THEN
  132.         sec = 0
  133.         GOTO fivedone:
  134.     END IF
  135.     GOSUB keyboard:
  136.     GOSUB shoot:
  137.     GOSUB youshoot2:
  138.     GOTO five:
  139.     fivedone:
  140.  
  141. IF level = 6 THEN
  142.     c1 = 255: c2 = 0: c3 = 0
  143.     six:
  144.     sec = sec + .02
  145.     s = (60 - sec) * 6 + 180
  146.     x = INT(SIN(s / 45 * 3.141592) * 180) + 325
  147.     y = INT(COS(s / 360 * 3.141592) * 180) + 225
  148.     GOSUB drawing2:
  149.     IF sec > 120 THEN
  150.         sec = 0
  151.         GOTO sixdone:
  152.     END IF
  153.     GOSUB keyboard:
  154.     GOSUB shoot:
  155.     GOSUB youshoot2:
  156.     GOTO six:
  157.     sixdone:
  158.  
  159. IF level = 7 THEN level = 1
  160.  
  161. GOTO go:
  162. 'GOTO goes back to the start of the main loop.
  163.  
  164. 'Draws the enemy tank and erases it for animation.
  165. drawing:
  166. x2 = x + xx: y2 = y + yy
  167. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(c1, c2, c3)
  168. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(c1, c2, c3)
  169. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(c1, c2, c3)
  170. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(c1, c2, c3)
  171. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(c1, c2, c3), BF
  172. LINE (x2 + 5, y2 + 5)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  173. LINE (x2 + 12, y2 + 5)-(x2 + 15, y2 + 8), _RGB32(0, 0, 0), BF
  174. LINE (x2 + 5, y2 + 13)-(x2 + 15, y2 + 16), _RGB32(0, 0, 0), BF
  175. _DELAY .004
  176. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(0, 0, 0), BF
  177. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(0, 0, 0)
  178. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(0, 0, 0)
  179. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(0, 0, 0)
  180. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(0, 0, 0)
  181.  
  182.  
  183. 'Draws the Boss Robot.
  184. drawing2:
  185. x2 = x + xx: y2 = y + yy
  186. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(c1, c2, c3), BF
  187. LINE (x2 - 4, y2 - 5)-(x2 - 2, y2 - 2), _RGB32(0, 0, 0), BF
  188. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(0, 0, 0), BF
  189. LINE (x2 - 4, y2 + 7)-(x2 + 4, y2 + 8), _RGB32(0, 0, 0), BF
  190. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(c1, c2, c3)
  191. CIRCLE (x2, y2 - 24), 4, _RGB32(c1, c2, c3)
  192. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(c1, c2, c3)
  193. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(c1, c2, c3)
  194. _DELAY .004
  195. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(0, 0, 0), BF
  196. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(0, 0, 0)
  197. CIRCLE (x2, y2 - 24), 4, _RGB32(0, 0, 0)
  198. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(0, 0, 0)
  199. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(0, 0, 0)
  200.  
  201. 'Keyboard control for your movement and shooting.
  202. keyboard:
  203. _LIMIT 1000
  204. a$ = INKEY$
  205. IF a$ = CHR$(27) THEN END
  206. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: l = 0
  207. IF r = 1 THEN
  208.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  209.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  210.     xt = xt + 1
  211.     IF xt > 780 THEN xt = 780
  212.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  213.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  214. IF a$ = CHR$(0) + CHR$(75) THEN l = 1: r = 0
  215. IF l = 1 THEN
  216.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  217.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  218.     xt = xt - 1
  219.     IF xt < 0 THEN xt = 0
  220.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  221.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  222. IF a$ = CHR$(0) + CHR$(72) OR a$ = CHR$(0) + CHR$(80) THEN
  223.     r = 0: l = 0
  224.  
  225. IF a$ = " " THEN GOSUB youshoot:
  226.  
  227. 'The start of your shot.
  228. youshoot:
  229. _LIMIT 1000
  230. IF ushoot = 0 THEN
  231.     sx2 = xt + 10
  232.     sy2 = yt - 11
  233.     ushoot = 1
  234.     SOUND 400, .5
  235.  
  236. 'The drawing and movement of your shot and if it reaches the enemy.
  237. youshoot2:
  238. _LIMIT 1000
  239. IF ushoot = 1 THEN
  240.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  241.     sy2 = sy2 - 3
  242.     IF sy2 < 0 THEN ushoot = 0: RETURN
  243.     CIRCLE (sx2, sy2), 5, _RGB32(255, 0, 0)
  244.     IF sx2 > x2 - 21 AND sx2 < x2 + 41 AND sy2 > y2 - 11 AND sy2 < y2 + 21 THEN
  245.         CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  246.         SOUND 200, 1
  247.         SOUND 100, 1
  248.         FOR explosion = 1 TO 30
  249.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(255, 0, 0)
  250.             _DELAY .02
  251.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(0, 0, 0)
  252.         NEXT explosion
  253.         LINE (x2 - 21, y2 - 21)-(x2 + 41, y2 + 41), _RGB32(0, 0, 0), BF
  254.         points = points + 100
  255.         IF points / 500 = INT(points / 500) THEN level = level + 1: level2 = level2 + 1
  256.         lives$ = STR$(lives)
  257.         points$ = STR$(points)
  258.         level$ = STR$(level2)
  259.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  260.         ushoot = 0
  261.         GOTO go:
  262.     END IF
  263.  
  264. 'The enemy's shot and if it reaches you.
  265. shoot:
  266. _LIMIT 1000
  267. IF shooting = 0 THEN
  268.     IF level2 = 1 THEN shh = 9970
  269.     IF level2 = 2 THEN shh = 9968
  270.     IF level2 = 3 THEN shh = 9966
  271.     IF level2 = 4 THEN shh = 9964
  272.     IF level2 = 5 THEN shh = 9962
  273.     IF level2 = 6 THEN shh = 9940
  274.     IF level2 > 6 THEN shh = 9930
  275.     sh = INT(RND * 10000) + 1
  276.     IF sh < shh THEN RETURN
  277.     sx = x2 + 10
  278.     sy = y2 + 10
  279.     shooting = 1
  280.     SOUND 300, .5
  281. IF shooting = 1 THEN
  282.     CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  283.     sy = sy + 3
  284.     IF sy > 620 THEN shooting = 0: RETURN
  285.     CIRCLE (sx, sy), 5, _RGB32(255, 0, 0)
  286.     IF sx > xt - 1 AND sx < xt + 21 AND sy > yt - 1 AND sy < yt + 21 THEN
  287.         CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  288.         SOUND 200, 1
  289.         SOUND 100, 1
  290.         FOR explosion2 = 1 TO 30
  291.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(255, 0, 0)
  292.             _DELAY .02
  293.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(0, 0, 0)
  294.         NEXT explosion2
  295.         lives = lives - 1
  296.         lives$ = STR$(lives)
  297.         points$ = STR$(points)
  298.         level$ = STR$(level2)
  299.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  300.         LINE (xt - 22, yt - 42)-(xt + 42, yt + 42), _RGB32(0, 0, 0), BF
  301.         IF lives = 0 THEN
  302.             LOCATE 20, 40: PRINT "G A M E   O V E R"
  303.             LOCATE 22, 40: PRINT "Score: "; points
  304.             LOCATE 23, 40: PRINT "Level: "; level2
  305.             LOCATE 25, 40: INPUT "Press Enter to go to Top Ten Scores.", tt$
  306.  
  307.             'Top Ten Scores
  308.             scc = points
  309.             IF _FILEEXISTS("toptentech.txt") THEN
  310.             ELSE
  311.                 OPEN "toptentech.txt" FOR OUTPUT AS #1
  312.                 RESTORE originaltopten
  313.                 DO
  314.                     READ toptenname$, toptenscore!
  315.                     IF toptenname$ = "EOF" THEN EXIT DO
  316.                     PRINT #1, toptenname$
  317.                     PRINT #1, toptenscore!
  318.                 LOOP
  319.                 CLOSE #1
  320.             END IF
  321.  
  322.             OPEN "toptentech.txt" FOR INPUT AS #1
  323.             FOR n = 1 TO 10
  324.                 INPUT #1, name$(n)
  325.                 INPUT #1, score(n)
  326.                 IF scc > score(n) AND sct = 0 THEN
  327.                     nn = n
  328.                     PRINT "You have made the Top Ten!"
  329.                     typename:
  330.                     INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  331.                     IF LEN(nm$(nn)) > 25 THEN
  332.                         PRINT "Name too long, try again."
  333.                         GOTO typename:
  334.                     END IF
  335.                     sccc(nn) = scc
  336.                     sct = 1
  337.                 END IF
  338.                 IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  339.             NEXT n
  340.             CLOSE #1
  341.             nex5:
  342.             CLOSE #1
  343.             OPEN "toptentech.txt" FOR OUTPUT AS #1
  344.             FOR n = 1 TO nn
  345.                 IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  346.                 IF n = nn THEN
  347.                     PRINT #1, nm$(n)
  348.                     PRINT #1, sccc(n)
  349.                 END IF
  350.             NEXT n
  351.             nex6:
  352.             FOR n = nn TO 10
  353.                 PRINT #1, name$(n): PRINT #1, score(n)
  354.             NEXT n
  355.  
  356.             CLOSE #1
  357.             nex7:
  358.             CLS
  359.             PRINT: PRINT: PRINT
  360.             PRINT "                                 T O P    T E N "
  361.             PRINT: PRINT: PRINT
  362.             OPEN "toptentech.txt" FOR INPUT AS #1
  363.             FOR n = 1 TO 10
  364.                 IF EOF(1) THEN GOTO nex8:
  365.                 INPUT #1, name$(n)
  366.                 INPUT #1, score(n)
  367.                 PRINT "             "; n; ". "; name$(n); score(n)
  368.             NEXT n
  369.             nex8:
  370.             CLOSE #1
  371.             FOR n = 1 TO 10
  372.                 nm$(n) = ""
  373.                 score(n) = 0
  374.                 name$(n) = ""
  375.                 sccc(n) = 0
  376.             NEXT n
  377.             nn = 0
  378.             n = 0
  379.             sct = 0
  380.             scc = 0
  381.             LOCATE 23, 1
  382.             INPUT "Would you like to play again? (Yes/No)", ag$
  383.             IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" OR ag$ = "YEs" THEN GOTO begin:
  384.             END
  385.         END IF
  386.         shooting = 0
  387.         RETURN
  388.     END IF
  389.  
  390. originaltopten:
  391. DATA Space Ace,7000
  392. DATA Suzy Swift,6000
  393. DATA Speedy Spencer,5000
  394. DATA Super Sam,4000
  395. DATA Battery Bob,3000
  396. DATA Karen Kryptonite,2750
  397. DATA Quick Ken,2500
  398. DATA Tiger Tessa,2250
  399. DATA Arcade Joe,2000
  400. DATA How Do U Play,1750
  401.  
« Last Edit: July 24, 2019, 01:16:56 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #19 on: July 24, 2019, 01:19:35 pm »
Here is the one line color variable problem fix. After you take care of the Boss and it goes back to the first one, it was making the next robot pink instead of blue. lol I accidentally typed cl instead of c1. Here is the fix, I also added _SCREENMOVE _MIDDLE at the top.

(Note: A faster version with some more sound effects is below on the same forum page as this post.)

Code: QB64: [Select]
  1. 'This version has 5 different colored robots with a Boss Robot after that.
  2. 'Each robot flies a different pattern.
  3. 'Game made on July 22, 2019
  4. 'By Ken G.
  5. 'Freeware
  6. 'I have put some descriptions in the code below to make it easier to learn from.
  7. begin:
  8. DIM name$(50), nm$(50), score(50), sccc(50)
  9. _TITLE "Tech Invaders"
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. PRINT "                                 T E C H      I N V A D E R S"
  12. PRINT "                                        by Ken G."
  13. PRINT "                       Use left and right arrow keys to move back and forth."
  14. PRINT "                            Use up or down arrow keys to stop moving."
  15. PRINT "                                    Use space bar to fire."
  16. PRINT "                                      Esc to end anytime."
  17. INPUT "                                   Press Enter to start.", start$
  18. lives = 5
  19. points = 0
  20. ushoot = 0
  21. shooting = 0
  22. level = 1
  23. level2 = 1
  24. start = 0
  25. s = 0
  26. xt = 400: yt = 550
  27.  
  28. 'Draw your shooter.
  29. LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  30. LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  31.  
  32.  
  33. 'This is the start of the main loop.
  34. go:
  35. 'Choose a random place for the enemy.
  36. xx = INT(RND * 200) + 100
  37. yy = INT(RND * 100) + 40
  38.  
  39. 'Each level has its own loop so it can set a different equation and speed of the enemy.
  40.  
  41. IF level = 1 THEN
  42.     c1 = 128: c2 = 127: c3 = 255
  43.     one:
  44.     'sec is not time, it's related to the coordinate of the enemy and speed it goes related to the loop speed.
  45.     sec = sec + .01
  46.     s = (60 - sec) * 6 + 180
  47.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  48.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  49.  
  50.     'GOSUB to drawing draws the enemy robot.
  51.     GOSUB drawing:
  52.     IF sec > 180 THEN
  53.         sec = 0
  54.         GOTO onedone:
  55.     END IF
  56.  
  57.     'GOSUB's go to keyboard control and enemy shooting.
  58.     GOSUB keyboard:
  59.     GOSUB shoot:
  60.     GOSUB youshoot2:
  61.     GOTO one:
  62.     onedone:
  63.  
  64. 'This level uses the spiral equation so it's a bit different than the others.
  65. IF level = 2 THEN
  66.     c1 = 127: c2 = 216: c3 = 127
  67.     FOR d = 160 TO 0 STEP -.125
  68.         _LIMIT 1000
  69.         s = s + .2
  70.         x = COS(s * 3.141592 / 180) * d
  71.         y = SIN(s * 3.151492 / 180) * d
  72.         GOSUB drawing:
  73.         GOSUB keyboard:
  74.         GOSUB shoot:
  75.         GOSUB youshoot2:
  76.     NEXT d
  77.     FOR d = 0 TO 160 STEP .125
  78.         _LIMIT 1000
  79.         s = s - .2
  80.         x = COS(s * 3.141592 / 180) * d
  81.         y = SIN(s * 3.151492 / 180) * d
  82.         GOSUB drawing:
  83.         GOSUB keyboard:
  84.         GOSUB shoot:
  85.         GOSUB youshoot2:
  86.     NEXT d
  87.  
  88. IF level = 3 THEN
  89.     c1 = 255: c2 = 0: c3 = 0
  90.     three:
  91.     sec = sec + .01
  92.     s = (60 - sec) * 6 + 180
  93.     x = INT(SIN(s / 90 * 3.141592) * 180) + 325
  94.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  95.     GOSUB drawing:
  96.     IF sec > 60 THEN
  97.         sec = 0
  98.         GOTO threedone:
  99.     END IF
  100.     GOSUB keyboard:
  101.     GOSUB shoot:
  102.     GOSUB youshoot2:
  103.     GOTO three:
  104.     threedone:
  105.  
  106. IF level = 4 THEN
  107.     c1 = 255: c2 = 255: c3 = 127
  108.     four:
  109.     sec = sec + .01
  110.     s = (60 - sec) * 6 + 180
  111.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  112.     y = INT(COS(s / 90 * 3.141592) * 180) + 225
  113.     GOSUB drawing:
  114.     IF sec > 60 THEN
  115.         sec = 0
  116.         GOTO fourdone:
  117.     END IF
  118.     GOSUB keyboard:
  119.     GOSUB shoot:
  120.     GOSUB youshoot2:
  121.     GOTO four:
  122.     fourdone:
  123. IF level = 5 THEN
  124.     c1 = 133: c2 = 28: c3 = 255
  125.     five:
  126.     sec = sec + .01
  127.     s = (60 - sec) * 6 + 180
  128.     x = INT(SIN(s / 135 * 3.141592) * 180) + 325
  129.     y = INT(COS(s / 33.75 * 3.141592) * 180) + 225
  130.     GOSUB drawing:
  131.     IF sec > 60 THEN
  132.         sec = 0
  133.         GOTO fivedone:
  134.     END IF
  135.     GOSUB keyboard:
  136.     GOSUB shoot:
  137.     GOSUB youshoot2:
  138.     GOTO five:
  139.     fivedone:
  140.  
  141. IF level = 6 THEN
  142.     c1 = 255: c2 = 0: c3 = 0
  143.     six:
  144.     sec = sec + .02
  145.     s = (60 - sec) * 6 + 180
  146.     x = INT(SIN(s / 45 * 3.141592) * 180) + 325
  147.     y = INT(COS(s / 360 * 3.141592) * 180) + 225
  148.     GOSUB drawing2:
  149.     IF sec > 120 THEN
  150.         sec = 0
  151.         GOTO sixdone:
  152.     END IF
  153.     GOSUB keyboard:
  154.     GOSUB shoot:
  155.     GOSUB youshoot2:
  156.     GOTO six:
  157.     sixdone:
  158.  
  159. IF level = 7 THEN level = 1
  160.  
  161. GOTO go:
  162. 'GOTO goes back to the start of the main loop.
  163.  
  164. 'Draws the enemy tank and erases it for animation.
  165. drawing:
  166. x2 = x + xx: y2 = y + yy
  167. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(c1, c2, c3)
  168. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(c1, c2, c3)
  169. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(c1, c2, c3)
  170. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(c1, c2, c3)
  171. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(c1, c2, c3), BF
  172. LINE (x2 + 5, y2 + 5)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  173. LINE (x2 + 12, y2 + 5)-(x2 + 15, y2 + 8), _RGB32(0, 0, 0), BF
  174. LINE (x2 + 5, y2 + 13)-(x2 + 15, y2 + 16), _RGB32(0, 0, 0), BF
  175. _DELAY .004
  176. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(0, 0, 0), BF
  177. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(0, 0, 0)
  178. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(0, 0, 0)
  179. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(0, 0, 0)
  180. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(0, 0, 0)
  181.  
  182.  
  183. 'Draws the Boss Robot.
  184. drawing2:
  185. x2 = x + xx: y2 = y + yy
  186. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(c1, c2, c3), BF
  187. LINE (x2 - 4, y2 - 5)-(x2 - 2, y2 - 2), _RGB32(0, 0, 0), BF
  188. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(0, 0, 0), BF
  189. LINE (x2 - 4, y2 + 7)-(x2 + 4, y2 + 8), _RGB32(0, 0, 0), BF
  190. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(c1, c2, c3)
  191. CIRCLE (x2, y2 - 24), 4, _RGB32(c1, c2, c3)
  192. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(c1, c2, c3)
  193. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(c1, c2, c3)
  194. _DELAY .004
  195. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(0, 0, 0), BF
  196. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(0, 0, 0)
  197. CIRCLE (x2, y2 - 24), 4, _RGB32(0, 0, 0)
  198. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(0, 0, 0)
  199. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(0, 0, 0)
  200.  
  201. 'Keyboard control for your movement and shooting.
  202. keyboard:
  203. _LIMIT 1000
  204. a$ = INKEY$
  205. IF a$ = CHR$(27) THEN END
  206. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: l = 0
  207. IF r = 1 THEN
  208.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  209.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  210.     xt = xt + 1
  211.     IF xt > 780 THEN xt = 780
  212.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  213.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  214. IF a$ = CHR$(0) + CHR$(75) THEN l = 1: r = 0
  215. IF l = 1 THEN
  216.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  217.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  218.     xt = xt - 1
  219.     IF xt < 0 THEN xt = 0
  220.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  221.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  222. IF a$ = CHR$(0) + CHR$(72) OR a$ = CHR$(0) + CHR$(80) THEN
  223.     r = 0: l = 0
  224.  
  225. IF a$ = " " THEN GOSUB youshoot:
  226.  
  227. 'The start of your shot.
  228. youshoot:
  229. _LIMIT 1000
  230. IF ushoot = 0 THEN
  231.     sx2 = xt + 10
  232.     sy2 = yt - 11
  233.     ushoot = 1
  234.     SOUND 400, .5
  235.  
  236. 'The drawing and movement of your shot and if it reaches the enemy.
  237. youshoot2:
  238. _LIMIT 1000
  239. IF ushoot = 1 THEN
  240.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  241.     sy2 = sy2 - 3
  242.     IF sy2 < 0 THEN ushoot = 0: RETURN
  243.     CIRCLE (sx2, sy2), 5, _RGB32(255, 0, 0)
  244.     IF sx2 > x2 - 21 AND sx2 < x2 + 41 AND sy2 > y2 - 11 AND sy2 < y2 + 21 THEN
  245.         CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  246.         SOUND 200, 1
  247.         SOUND 100, 1
  248.         FOR explosion = 1 TO 30
  249.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(255, 0, 0)
  250.             _DELAY .02
  251.             CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(0, 0, 0)
  252.         NEXT explosion
  253.         LINE (x2 - 21, y2 - 21)-(x2 + 41, y2 + 41), _RGB32(0, 0, 0), BF
  254.         points = points + 100
  255.         IF points / 500 = INT(points / 500) THEN level = level + 1: level2 = level2 + 1
  256.         lives$ = STR$(lives)
  257.         points$ = STR$(points)
  258.         level$ = STR$(level2)
  259.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  260.         ushoot = 0
  261.         GOTO go:
  262.     END IF
  263.  
  264. 'The enemy's shot and if it reaches you.
  265. shoot:
  266. _LIMIT 1000
  267. IF shooting = 0 THEN
  268.     IF level2 = 1 THEN shh = 9970
  269.     IF level2 = 2 THEN shh = 9968
  270.     IF level2 = 3 THEN shh = 9966
  271.     IF level2 = 4 THEN shh = 9964
  272.     IF level2 = 5 THEN shh = 9962
  273.     IF level2 = 6 THEN shh = 9940
  274.     IF level2 > 6 THEN shh = 9930
  275.     sh = INT(RND * 10000) + 1
  276.     IF sh < shh THEN RETURN
  277.     sx = x2 + 10
  278.     sy = y2 + 10
  279.     shooting = 1
  280.     SOUND 300, .5
  281. IF shooting = 1 THEN
  282.     CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  283.     sy = sy + 3
  284.     IF sy > 620 THEN shooting = 0: RETURN
  285.     CIRCLE (sx, sy), 5, _RGB32(255, 0, 0)
  286.     IF sx > xt - 1 AND sx < xt + 21 AND sy > yt - 1 AND sy < yt + 21 THEN
  287.         CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  288.         SOUND 200, 1
  289.         SOUND 100, 1
  290.         FOR explosion2 = 1 TO 30
  291.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(255, 0, 0)
  292.             _DELAY .02
  293.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(0, 0, 0)
  294.         NEXT explosion2
  295.         lives = lives - 1
  296.         lives$ = STR$(lives)
  297.         points$ = STR$(points)
  298.         level$ = STR$(level2)
  299.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  300.         LINE (xt - 22, yt - 42)-(xt + 42, yt + 42), _RGB32(0, 0, 0), BF
  301.         IF lives = 0 THEN
  302.             LOCATE 20, 40: PRINT "G A M E   O V E R"
  303.             LOCATE 22, 40: PRINT "Score: "; points
  304.             LOCATE 23, 40: PRINT "Level: "; level2
  305.             LOCATE 25, 40: INPUT "Press Enter to go to Top Ten Scores.", tt$
  306.  
  307.             'Top Ten Scores
  308.             scc = points
  309.             IF _FILEEXISTS("toptentech.txt") THEN
  310.             ELSE
  311.                 OPEN "toptentech.txt" FOR OUTPUT AS #1
  312.                 RESTORE originaltopten
  313.                 DO
  314.                     READ toptenname$, toptenscore!
  315.                     IF toptenname$ = "EOF" THEN EXIT DO
  316.                     PRINT #1, toptenname$
  317.                     PRINT #1, toptenscore!
  318.                 LOOP
  319.                 CLOSE #1
  320.             END IF
  321.  
  322.             OPEN "toptentech.txt" FOR INPUT AS #1
  323.             FOR n = 1 TO 10
  324.                 INPUT #1, name$(n)
  325.                 INPUT #1, score(n)
  326.                 IF scc > score(n) AND sct = 0 THEN
  327.                     nn = n
  328.                     PRINT "You have made the Top Ten!"
  329.                     typename:
  330.                     INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  331.                     IF LEN(nm$(nn)) > 25 THEN
  332.                         PRINT "Name too long, try again."
  333.                         GOTO typename:
  334.                     END IF
  335.                     sccc(nn) = scc
  336.                     sct = 1
  337.                 END IF
  338.                 IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  339.             NEXT n
  340.             CLOSE #1
  341.             nex5:
  342.             CLOSE #1
  343.             OPEN "toptentech.txt" FOR OUTPUT AS #1
  344.             FOR n = 1 TO nn
  345.                 IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  346.                 IF n = nn THEN
  347.                     PRINT #1, nm$(n)
  348.                     PRINT #1, sccc(n)
  349.                 END IF
  350.             NEXT n
  351.             nex6:
  352.             FOR n = nn TO 10
  353.                 PRINT #1, name$(n): PRINT #1, score(n)
  354.             NEXT n
  355.  
  356.             CLOSE #1
  357.             nex7:
  358.             CLS
  359.             PRINT: PRINT: PRINT
  360.             PRINT "                                 T O P    T E N "
  361.             PRINT: PRINT: PRINT
  362.             OPEN "toptentech.txt" FOR INPUT AS #1
  363.             FOR n = 1 TO 10
  364.                 IF EOF(1) THEN GOTO nex8:
  365.                 INPUT #1, name$(n)
  366.                 INPUT #1, score(n)
  367.                 PRINT "             "; n; ". "; name$(n); score(n)
  368.             NEXT n
  369.             nex8:
  370.             CLOSE #1
  371.             FOR n = 1 TO 10
  372.                 nm$(n) = ""
  373.                 score(n) = 0
  374.                 name$(n) = ""
  375.                 sccc(n) = 0
  376.             NEXT n
  377.             nn = 0
  378.             n = 0
  379.             sct = 0
  380.             scc = 0
  381.             LOCATE 23, 1
  382.             INPUT "Would you like to play again? (Yes/No)", ag$
  383.             IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" OR ag$ = "YEs" THEN GOTO begin:
  384.             END
  385.         END IF
  386.         shooting = 0
  387.         RETURN
  388.     END IF
  389.  
  390. originaltopten:
  391. DATA Space Ace,7000
  392. DATA Suzy Swift,6000
  393. DATA Speedy Spencer,5000
  394. DATA Super Sam,4000
  395. DATA Battery Bob,3000
  396. DATA Karen Kryptonite,2750
  397. DATA Quick Ken,2500
  398. DATA Tiger Tessa,2250
  399. DATA Arcade Joe,2000
  400. DATA How Do U Play,1750
  401.  
« Last Edit: July 25, 2019, 11:19:20 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #20 on: July 24, 2019, 06:44:18 pm »
I made a video of myself playing this game, showing the code first, and put it on YouTube. If anyone is interested. It's a bit blurry but someone says that YouTube fixes the blurriness eventually, but we'll see. 


&feature=youtu.be

« Last Edit: July 24, 2019, 06:48:47 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #21 on: July 25, 2019, 11:18:27 pm »
Well, I decided to do some more experimenting lol, and you know when that happens I find something really cool usually lol.
For the first time I tried some SUB's and tried them in my Robot Invaders game. I first found out that if you use a FOR/NEXT loop in a SUB, you can play that SOUND effect while the main program is still running! That is, until that loop is over with, which is WAY cool. But I also found out that you can't make a forever loop for Sound in a SUB or it will stop your main program for some reason. So after messing with it a bit I just made a quick sound for when you start with a new guy in the game. I also made the enemy explosions a LOT faster with no _DELAY's anymore. Which makes the game even more fun because it moves much faster. So, here is the game again, I hope you all aren't tired of it yet. :) Thank you to the people in my Math Graphics thread for pushing me to learn more about SUB's, I feel like I just jumped ahead big time. :) Subs were like another language to me in the 90's, I feel so relieved now that I finally know a lot more now. Of course I will still keep learning more about them.

This will be the last one for this Version of the game. I'm working on Version 2 and I already got filled in bullets :))). I didn't need that circle fill-in code in the Toolbox of this forum, just loops of different sized circles every .25 size. :) I'll start a new thread for the next version because I want to add a lot of different things.


Code: QB64: [Select]
  1. 'This version has 5 different colored robots with a Boss Robot after that.
  2. 'Each robot flies a different pattern.
  3. 'Game made on July 22, 2019
  4. 'By Ken G.
  5. 'Freeware
  6. 'I have put some descriptions in the code below to make it easier to learn from.
  7. begin:
  8. DIM name$(50), nm$(50), score(50), sccc(50)
  9. _TITLE "Tech Invaders"
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11. PRINT "                                 T E C H      I N V A D E R S"
  12. PRINT "                                        by Ken G."
  13. PRINT "                       Use left and right arrow keys to move back and forth."
  14. PRINT "                            Use up or down arrow keys to stop moving."
  15. PRINT "                                    Use space bar to fire."
  16. PRINT "                                      Esc to end anytime."
  17. INPUT "                                   Press Enter to start.", start$
  18. lives = 5
  19. points = 0
  20. ushoot = 0
  21. shooting = 0
  22. level = 1
  23. level2 = 1
  24. start = 0
  25. s = 0
  26. xt = 400: yt = 550
  27.  
  28. 'Draw your shooter.
  29. LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  30. LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  31.  
  32. OPENINGSOUND
  33.  
  34. 'This is the start of the main loop.
  35. go:
  36. 'Choose a random place for the enemy.
  37. xx = INT(RND * 200) + 100
  38. yy = INT(RND * 100) + 40
  39.  
  40. 'Each level has its own loop so it can set a different equation and speed of the enemy.
  41.  
  42. IF level = 1 THEN
  43.     c1 = 128: c2 = 127: c3 = 255
  44.     one:
  45.     'sec is not time, it's related to the coordinate of the enemy and speed it goes related to the loop speed.
  46.     sec = sec + .01
  47.     s = (60 - sec) * 6 + 180
  48.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  49.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  50.  
  51.     'GOSUB to drawing draws the enemy robot.
  52.     GOSUB drawing:
  53.     IF sec > 180 THEN
  54.         sec = 0
  55.         GOTO onedone:
  56.     END IF
  57.  
  58.     'GOSUB's go to keyboard control and enemy shooting.
  59.     GOSUB keyboard:
  60.     GOSUB shoot:
  61.     GOSUB youshoot2:
  62.     GOTO one:
  63.     onedone:
  64.  
  65. 'This level uses the spiral equation so it's a bit different than the others.
  66. IF level = 2 THEN
  67.     c1 = 127: c2 = 216: c3 = 127
  68.     FOR d = 160 TO 0 STEP -.125
  69.         _LIMIT 1000
  70.         s = s + .2
  71.         x = COS(s * 3.141592 / 180) * d
  72.         y = SIN(s * 3.151492 / 180) * d
  73.         GOSUB drawing:
  74.         GOSUB keyboard:
  75.         GOSUB shoot:
  76.         GOSUB youshoot2:
  77.     NEXT d
  78.     FOR d = 0 TO 160 STEP .125
  79.         _LIMIT 1000
  80.         s = s - .2
  81.         x = COS(s * 3.141592 / 180) * d
  82.         y = SIN(s * 3.151492 / 180) * d
  83.         GOSUB drawing:
  84.         GOSUB keyboard:
  85.         GOSUB shoot:
  86.         GOSUB youshoot2:
  87.     NEXT d
  88.  
  89. IF level = 3 THEN
  90.     c1 = 255: c2 = 0: c3 = 0
  91.     three:
  92.     sec = sec + .01
  93.     s = (60 - sec) * 6 + 180
  94.     x = INT(SIN(s / 90 * 3.141592) * 180) + 325
  95.     y = INT(COS(s / 180 * 3.141592) * 180) + 225
  96.     GOSUB drawing:
  97.     IF sec > 60 THEN
  98.         sec = 0
  99.         GOTO threedone:
  100.     END IF
  101.     GOSUB keyboard:
  102.     GOSUB shoot:
  103.     GOSUB youshoot2:
  104.     GOTO three:
  105.     threedone:
  106.  
  107. IF level = 4 THEN
  108.     c1 = 255: c2 = 255: c3 = 127
  109.     four:
  110.     sec = sec + .01
  111.     s = (60 - sec) * 6 + 180
  112.     x = INT(SIN(s / 180 * 3.141592) * 180) + 325
  113.     y = INT(COS(s / 90 * 3.141592) * 180) + 225
  114.     GOSUB drawing:
  115.     IF sec > 60 THEN
  116.         sec = 0
  117.         GOTO fourdone:
  118.     END IF
  119.     GOSUB keyboard:
  120.     GOSUB shoot:
  121.     GOSUB youshoot2:
  122.     GOTO four:
  123.     fourdone:
  124. IF level = 5 THEN
  125.     c1 = 133: c2 = 28: c3 = 255
  126.     five:
  127.     sec = sec + .01
  128.     s = (60 - sec) * 6 + 180
  129.     x = INT(SIN(s / 135 * 3.141592) * 180) + 325
  130.     y = INT(COS(s / 33.75 * 3.141592) * 180) + 225
  131.     GOSUB drawing:
  132.     IF sec > 60 THEN
  133.         sec = 0
  134.         GOTO fivedone:
  135.     END IF
  136.     GOSUB keyboard:
  137.     GOSUB shoot:
  138.     GOSUB youshoot2:
  139.     GOTO five:
  140.     fivedone:
  141.  
  142. IF level = 6 THEN
  143.     c1 = 255: c2 = 0: c3 = 0
  144.     six:
  145.     sec = sec + .02
  146.     s = (60 - sec) * 6 + 180
  147.     x = INT(SIN(s / 45 * 3.141592) * 180) + 325
  148.     y = INT(COS(s / 360 * 3.141592) * 180) + 225
  149.     GOSUB drawing2:
  150.     IF sec > 120 THEN
  151.         sec = 0
  152.         GOTO sixdone:
  153.     END IF
  154.     GOSUB keyboard:
  155.     GOSUB shoot:
  156.     GOSUB youshoot2:
  157.     GOTO six:
  158.     sixdone:
  159.  
  160. IF level = 7 THEN level = 1
  161.  
  162. GOTO go:
  163. 'GOTO goes back to the start of the main loop.
  164.  
  165. 'Draws the enemy tank and erases it for animation.
  166. drawing:
  167. x2 = x + xx: y2 = y + yy
  168. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(c1, c2, c3)
  169. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(c1, c2, c3)
  170. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(c1, c2, c3)
  171. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(c1, c2, c3)
  172. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(c1, c2, c3), BF
  173. LINE (x2 + 5, y2 + 5)-(x2 + 8, y2 + 8), _RGB32(0, 0, 0), BF
  174. LINE (x2 + 12, y2 + 5)-(x2 + 15, y2 + 8), _RGB32(0, 0, 0), BF
  175. LINE (x2 + 5, y2 + 13)-(x2 + 15, y2 + 16), _RGB32(0, 0, 0), BF
  176. _DELAY .004
  177. LINE (x2, y2)-(x2 + 20, y2 + 20), _RGB32(0, 0, 0), BF
  178. LINE (x2, y2)-(x2 - 10, y2 - 10), _RGB32(0, 0, 0)
  179. LINE (x2 + 20, y2)-(x2 + 30, y2 - 10), _RGB32(0, 0, 0)
  180. CIRCLE (x2 - 15, y2 - 15), 5, _RGB32(0, 0, 0)
  181. CIRCLE (x2 + 35, y2 - 15), 5, _RGB32(0, 0, 0)
  182.  
  183.  
  184. 'Draws the Boss Robot.
  185. drawing2:
  186. x2 = x + xx: y2 = y + yy
  187. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(c1, c2, c3), BF
  188. LINE (x2 - 4, y2 - 5)-(x2 - 2, y2 - 2), _RGB32(0, 0, 0), BF
  189. LINE (x2 + 6, y2 - 5)-(x2 + 8, y2 - 2), _RGB32(0, 0, 0), BF
  190. LINE (x2 - 4, y2 + 7)-(x2 + 4, y2 + 8), _RGB32(0, 0, 0), BF
  191. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(c1, c2, c3)
  192. CIRCLE (x2, y2 - 24), 4, _RGB32(c1, c2, c3)
  193. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(c1, c2, c3)
  194. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(c1, c2, c3)
  195. _DELAY .004
  196. LINE (x2 - 10, y2 - 10)-(x2 + 10, y2 + 10), _RGB32(0, 0, 0), BF
  197. LINE (x2, y2 - 10)-(x2, y2 - 20), _RGB32(0, 0, 0)
  198. CIRCLE (x2, y2 - 24), 4, _RGB32(0, 0, 0)
  199. LINE (x2, y2 - 20)-(x2 - 10, y2 - 30), _RGB32(0, 0, 0)
  200. LINE (x2, y2 - 20)-(x2 + 10, y2 - 30), _RGB32(0, 0, 0)
  201.  
  202. 'Keyboard control for your movement and shooting.
  203. keyboard:
  204. _LIMIT 1000
  205. a$ = INKEY$
  206. IF a$ = CHR$(27) THEN END
  207. IF a$ = CHR$(0) + CHR$(77) THEN r = 1: l = 0
  208. IF r = 1 THEN
  209.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  210.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  211.     xt = xt + 1
  212.     IF xt > 780 THEN xt = 780
  213.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  214.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  215. IF a$ = CHR$(0) + CHR$(75) THEN l = 1: r = 0
  216. IF l = 1 THEN
  217.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(0, 0, 0), BF
  218.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(0, 0, 0)
  219.     xt = xt - 1
  220.     IF xt < 0 THEN xt = 0
  221.     LINE (xt, yt)-(xt + 20, yt + 20), _RGB32(128, 139, 255), BF
  222.     LINE (xt + 10, yt)-(xt + 10, yt - 10), _RGB32(128, 139, 255)
  223. IF a$ = CHR$(0) + CHR$(72) OR a$ = CHR$(0) + CHR$(80) THEN
  224.     r = 0: l = 0
  225.  
  226. IF a$ = " " THEN GOSUB youshoot:
  227.  
  228. 'The start of your shot.
  229. youshoot:
  230. _LIMIT 1000
  231. IF ushoot = 0 THEN
  232.     sx2 = xt + 10
  233.     sy2 = yt - 11
  234.     ushoot = 1
  235.     SOUND 400, .5
  236.  
  237. 'The drawing and movement of your shot and if it reaches the enemy.
  238. youshoot2:
  239. _LIMIT 1000
  240. IF ushoot = 1 THEN
  241.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  242.     sy2 = sy2 - 3
  243.     IF sy2 < 0 THEN ushoot = 0: RETURN
  244.     CIRCLE (sx2, sy2), 5, _RGB32(255, 0, 0)
  245.     IF sx2 > x2 - 21 AND sx2 < x2 + 41 AND sy2 > y2 - 11 AND sy2 < y2 + 21 THEN
  246.         ENEMYEXPLOSION sx2, sy2, x2, y2
  247.         points = points + 100
  248.         IF points / 500 = INT(points / 500) THEN level = level + 1: level2 = level2 + 1
  249.         lives$ = STR$(lives)
  250.         points$ = STR$(points)
  251.         level$ = STR$(level2)
  252.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  253.         ushoot = 0
  254.         GOTO go:
  255.     END IF
  256.  
  257. 'The enemy's shot and if it reaches you.
  258. shoot:
  259. _LIMIT 1000
  260. IF shooting = 0 THEN
  261.     IF level2 = 1 THEN shh = 9970
  262.     IF level2 = 2 THEN shh = 9968
  263.     IF level2 = 3 THEN shh = 9966
  264.     IF level2 = 4 THEN shh = 9964
  265.     IF level2 = 5 THEN shh = 9962
  266.     IF level2 = 6 THEN shh = 9940
  267.     IF level2 > 6 THEN shh = 9930
  268.     sh = INT(RND * 10000) + 1
  269.     IF sh < shh THEN RETURN
  270.     sx = x2 + 10
  271.     sy = y2 + 10
  272.     shooting = 1
  273.     SOUND 300, .5
  274. IF shooting = 1 THEN
  275.     CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  276.     sy = sy + 3
  277.     IF sy > 620 THEN shooting = 0: RETURN
  278.     CIRCLE (sx, sy), 5, _RGB32(255, 0, 0)
  279.     IF sx > xt - 1 AND sx < xt + 21 AND sy > yt - 1 AND sy < yt + 21 THEN
  280.         CIRCLE (sx, sy), 5, _RGB32(0, 0, 0)
  281.         SOUND 200, 1
  282.         SOUND 100, 1
  283.         FOR explosion2 = 1 TO 30
  284.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(255, 0, 0)
  285.             _DELAY .02
  286.             CIRCLE (xt + 10, yt + 10), explosion2, _RGB32(0, 0, 0)
  287.         NEXT explosion2
  288.         lives = lives - 1
  289.         lives$ = STR$(lives)
  290.         points$ = STR$(points)
  291.         level$ = STR$(level2)
  292.         _TITLE "Tech Invaders      Lives: " + lives$ + "     Level: " + level$ + "      Score: " + points$
  293.         LINE (xt - 22, yt - 42)-(xt + 42, yt + 42), _RGB32(0, 0, 0), BF
  294.         IF lives = 0 THEN
  295.             LOCATE 20, 40: PRINT "G A M E   O V E R"
  296.             LOCATE 22, 40: PRINT "Score: "; points
  297.             LOCATE 23, 40: PRINT "Level: "; level2
  298.             LOCATE 25, 40: INPUT "Press Enter to go to Top Ten Scores.", tt$
  299.  
  300.             'Top Ten Scores
  301.             scc = points
  302.             IF _FILEEXISTS("toptentech.txt") THEN
  303.             ELSE
  304.                 OPEN "toptentech.txt" FOR OUTPUT AS #1
  305.                 RESTORE originaltopten
  306.                 DO
  307.                     READ toptenname$, toptenscore!
  308.                     IF toptenname$ = "EOF" THEN EXIT DO
  309.                     PRINT #1, toptenname$
  310.                     PRINT #1, toptenscore!
  311.                 LOOP
  312.                 CLOSE #1
  313.             END IF
  314.  
  315.             OPEN "toptentech.txt" FOR INPUT AS #1
  316.             FOR n = 1 TO 10
  317.                 INPUT #1, name$(n)
  318.                 INPUT #1, score(n)
  319.                 IF scc > score(n) AND sct = 0 THEN
  320.                     nn = n
  321.                     PRINT "You have made the Top Ten!"
  322.                     typename:
  323.                     INPUT "Type your name here (25 letters and spaces maximum.):", nm$(nn)
  324.                     IF LEN(nm$(nn)) > 25 THEN
  325.                         PRINT "Name too long, try again."
  326.                         GOTO typename:
  327.                     END IF
  328.                     sccc(nn) = scc
  329.                     sct = 1
  330.                 END IF
  331.                 IF n = 10 AND sct = 0 THEN CLOSE #1: GOTO nex7:
  332.             NEXT n
  333.             CLOSE #1
  334.             nex5:
  335.             CLOSE #1
  336.             OPEN "toptentech.txt" FOR OUTPUT AS #1
  337.             FOR n = 1 TO nn
  338.                 IF n <> nn THEN PRINT #1, name$(n): PRINT #1, score(n)
  339.                 IF n = nn THEN
  340.                     PRINT #1, nm$(n)
  341.                     PRINT #1, sccc(n)
  342.                 END IF
  343.             NEXT n
  344.             nex6:
  345.             FOR n = nn TO 10
  346.                 PRINT #1, name$(n): PRINT #1, score(n)
  347.             NEXT n
  348.  
  349.             CLOSE #1
  350.             nex7:
  351.             CLS
  352.             PRINT: PRINT: PRINT
  353.             PRINT "                                 T O P    T E N "
  354.             PRINT: PRINT: PRINT
  355.             OPEN "toptentech.txt" FOR INPUT AS #1
  356.             FOR n = 1 TO 10
  357.                 IF EOF(1) THEN GOTO nex8:
  358.                 INPUT #1, name$(n)
  359.                 INPUT #1, score(n)
  360.                 PRINT "             "; n; ". "; name$(n); score(n)
  361.             NEXT n
  362.             nex8:
  363.             CLOSE #1
  364.             FOR n = 1 TO 10
  365.                 nm$(n) = ""
  366.                 score(n) = 0
  367.                 name$(n) = ""
  368.                 sccc(n) = 0
  369.             NEXT n
  370.             nn = 0
  371.             n = 0
  372.             sct = 0
  373.             scc = 0
  374.             LOCATE 23, 1
  375.             INPUT "Would you like to play again? (Yes/No)", ag$
  376.             IF ag$ = "y" OR ag$ = "Y" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "yeS" OR ag$ = "YEs" THEN GOTO begin:
  377.             END
  378.         END IF
  379.         shooting = 0
  380.         OPENINGSOUND
  381.         RETURN
  382.     END IF
  383.  
  384. originaltopten:
  385. DATA Space Ace,7000
  386. DATA Suzy Swift,6000
  387. DATA Speedy Spencer,5000
  388. DATA Super Sam,4000
  389. DATA Battery Bob,3000
  390. DATA Karen Kryptonite,2750
  391. DATA Quick Ken,2500
  392. DATA Tiger Tessa,2250
  393. DATA Arcade Joe,2000
  394. DATA How Do U Play,1750
  395.  
  396. SUB OPENINGSOUND
  397.     snd = 300
  398.     snd2 = 800
  399.     FOR t = 1 TO 50
  400.         IF snd > 800 THEN snd = 300
  401.         IF snd2 < 300 THEN snd2 = 800
  402.         snd = snd + 10
  403.         SOUND snd, .25
  404.     NEXT t
  405.  
  406. SUB ENEMYEXPLOSION (sx2, sy2, x2, y2)
  407.     SOUND 200, 1
  408.     SOUND 100, 1
  409.     CIRCLE (sx2, sy2), 5, _RGB32(0, 0, 0)
  410.     FOR explosion = 1 TO 30
  411.         CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(255, 0, 0)
  412.         _LIMIT 200
  413.         CIRCLE (x2 + 10, y2 + 10), explosion, _RGB32(0, 0, 0)
  414.     NEXT explosion
  415.     LINE (x2 - 21, y2 - 21)-(x2 + 41, y2 + 41), _RGB32(0, 0, 0), BF
  416.  
  417.  
« Last Edit: July 26, 2019, 12:25:18 am by SierraKen »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Robot Invaders
« Reply #22 on: July 26, 2019, 07:12:13 am »
That was really cool. Trying to predict where the alien was going to move was a challenge.

On the code end of things, I think you'll find that SUBing out will work well where ever you use a GOTO or GOSUB.

SUBs and FUNCTIONs, when well designed, will become standard library routines that you can cut and paste into other code. That way it's not necessary to "reinvent the wheel". There are times that I just load a "template" of routines, then when I'm done, I just delete the ones I didn't use.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #23 on: July 26, 2019, 12:49:04 pm »
That's really cool, thanks OldMoses, I'll remember that.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Robot Invaders
« Reply #24 on: July 27, 2019, 12:43:53 am »
Well, I made it to level 7 in the first game. I liked the initial alien design the best.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline pforpond

  • Newbie
  • Posts: 76
  • I am me
    • View Profile
Re: Robot Invaders
« Reply #25 on: July 27, 2019, 02:35:11 am »
I made it to the red ones that fly side to side... this is a fun game, quite addictive and I love the fast paced nature it seems to be taking and pattern learning involved. One thing I did notice is that sometimes the enemy seems to jolt from one place to another... I think it only happened twice, I don't know if it's intended or not :)

Would be great to see multiple enemies on screen at once :) Loving you game so far!
Loading Signature...

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #26 on: July 27, 2019, 12:37:00 pm »
Thanks Pforpond. Yes, they are intended to disappear and appear somewhere else. It makes the game a bit harder and more random. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Robot Invaders
« Reply #27 on: July 27, 2019, 12:37:53 pm »
Cool Pete, thanks. Try out my Tech Invaders 2. It's a lot better than this one. :)