Author Topic: Tank Walls  (Read 7122 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Tank Walls
« Reply #15 on: July 01, 2019, 05:59:01 pm »
Just tried your new level...  Wow that enemy has some serious speed.... Cool...
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tank Walls
« Reply #16 on: July 01, 2019, 07:34:35 pm »
Thanks Johno. Yeah I'm pretty much done making this game. I did kinda make a bounce-back system but instead of moving him back, I just changed his direction. This way he doesn't always come back to the same location all the time toward where I am on the entire map. Thanks for the suggestion though. But I think I'm finished, for now anyway. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tank Walls
« Reply #17 on: July 01, 2019, 11:12:23 pm »
In reference to wall collision. Bplus has a good idea to check to see if a wall exists in the direction of movement. I used to get "stuck" in walls as well. Using bplus's idea of detection, when you hit the wall, simply 'bounce' back at the same velocity as the collision. Voila! No more partial 'Caspers'. Just a thought...

Ha! Actually I think it smarter to check if wall is there before going in that direction.
« Last Edit: July 01, 2019, 11:14:41 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Tank Walls
« Reply #18 on: July 01, 2019, 11:42:22 pm »
That's what I meant by, "to check to see if a wall exists 'in the direction' of movement". My fault for not expressing the idea in a clear and concise method.

Oh. Just thought of a slight modification Correct me if I am wrong, but as the game stands, when a tank is destroyed the player and enemy are randomly placed within the scene and the 'dance' continues. How about making it a little harder to play with each victory?  What about setting the players 'shooting range" slightly shorter with each win or perhaps multiple hits on the enemy to destroy it? Just some thoughts... Then there are 'power ups'... Speed. Firing distance. Invulnerability. Casper (move through walls)... But only have them appear for a short time... Sometimes, and that's pretty rare, I think of weird stuff like that... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tank Walls
« Reply #19 on: July 02, 2019, 01:18:52 pm »
Johno, that's a good idea about limiting the shot range. I never thought of that. Because as it is now, if someone knows how to control the shot by using your arrow keys really well, the person will win every time. I'll check that out and see what I can do. Thanks! The other stuff, maybe someday :). Someday I also might make a package of like 20 maps and make it go from 1 to the other after a certain amount of points are reached. After like 20 maps the game is over, or it's like Pac-Man and goes back to the first but a lot faster. lol Great ideas.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tank Walls
« Reply #20 on: July 02, 2019, 03:46:29 pm »
OK here we go, I made the shots go almost the length of the width of the window. This still lets people control the direction of the shot with the arrow keys but not too much.
I also spruced up the program a bit more and fixed a couple variables and deleted 2 variables not needed. I also sectioned off the enemy tank as the last half of the program completely and your tank as the first half of the program. So here it is :) Have fun!

Code: QB64: [Select]
  1. 'This game has been made from my Walls Detector Example program.
  2. 'You are the blue tank and you move with the arrow keys and shoot the red tank with the space bar.
  3. 'You can control the direction of your shot by using the arrow keys as it flies.
  4. 'But first you have to make a walls layout picture using my 'Ken's Plotter' program which can be found on my website here: http://ken.x10host.com/qb64/
  5. 'Which is very simple, you just plot using the arrow keys and space bar. All instructions are on that program.
  6. 'Make many layout pictures and have a BLAST!
  7. 'I call the enemy a 'monster' in my code because at first this was going to be just shooting monsters but it turned out to be more like tanks.
  8. 'This game was made on June 30, 2019 by Ken G.
  9. 'Feel free to edit this code how you wish but do not sell it. This game took a couple weeks to make both programs and is something I've wanted to make for a very long time.
  10.  
  11. start:
  12. 'You will need to DIM these strings and variables first to make memory.
  13. DIM x$(10000), y$(10000), x(10000), y(10000)
  14. _TITLE "Tank Walls     Score: 0     Lives: 5"
  15. points = 0
  16. lives = 5
  17. mshot = 0
  18. shot = 0
  19. ds = 1
  20. dd = 1
  21. sht = 0
  22. sht2 = 0
  23. 'xx and yy are the coordinates to your blue tank and others are the turrent locations of the tank.
  24. xx = 320: yy = 240
  25. leftxt = xx - 4: leftyt = yy + 2: leftxxt = xx: leftyyt = yy + 3
  26. rightxt = xx + 5: rightyt = yy + 2: rightxxt = xx + 9: rightyyt = yy + 3
  27. upxt = xx + 2: upyt = yy - 4: upxxt = xx + 3: upyyt = yy
  28. downxt = xx + 2: downyt = yy + 5: downxxt = xx + 3: downyyt = yy + 9
  29. GOSUB oldtank:
  30. _SCREENMOVE 300, 200
  31. SCREEN _NEWIMAGE(640, 480, 32)
  32. PRINT "                     Tank Walls"
  33. PRINT "                     By Ken G."
  34. PRINT "This is an example game on how to use any picture you make"
  35. PRINT "to turn into a game that shoots a computer tank."
  36. PRINT "First you need to create a picture or maze using 'Ken's Plotter'."
  37. PRINT "Make many layout pictures to use with this game and have a BLAST!"
  38. PRINT "Use your arrow keys to move the little blue square tank around and it will"
  39. PRINT "stop at every wall. You start out in the very center"
  40. PRINT "of the window. The enemy tank is the red square and it will be"
  41. PRINT "randomly placed within the walls."
  42. PRINT "When you are in line with the green square tank,"
  43. PRINT "press the Space Bar to fire a shot at him."
  44. PRINT "Notice how your shot stops at every wall it hits and if you hit"
  45. PRINT "the enemy, it will make a small explosion."
  46. PRINT "You start off with 5 lives, when all 5 are gone, the game is over."
  47. PRINT "You get 10 points for every Enemy Tank you hit."
  48. PRINT "You can control the direction of your shot by using the arrow"
  49. PRINT "keys as it flies."
  50. again:
  51. INPUT "Type file name of picture to load (without the .txt ending):", nm$
  52. IF nm$ = "" THEN GOTO again:
  53. nm$ = nm$ + ".txt"
  54. theFileExists = _FILEEXISTS(nm$)
  55. IF theFileExists = 0 THEN
  56.     PRINT "File does not exist, try again."
  57.     GOTO again:
  58. 'First you load the picture and put every coordinate into memory.
  59. OPEN nm$ FOR INPUT AS #1
  60. ggo:
  61. _LIMIT 1000
  62. p = p + 1
  63. INPUT #1, x$(p), y$(p)
  64. x(p) = VAL(x$(p)): y(p) = VAL(y$(p))
  65. LINE (x(p), y(p))-(x(p) + 10, y(p) + 10), _RGB32(255, 255, 255), BF
  66.     CLOSE #1
  67.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  68.     LINE (upxt, upyt)-(upxxt, upyyt), _RGB32(127, 127, 255), BF
  69.     'Start monster location
  70.     place:
  71.     xxx = INT(RND * 630) + 5
  72.     yyy = INT(RND * 470) + 5
  73.     IF xxx - xx < 150 AND xxx - xx > -150 THEN
  74.         IF yyy - yy < 150 AND yyy - yy > -150 THEN
  75.             GOTO place:
  76.         END IF
  77.     END IF
  78.     FOR tt = 1 TO p
  79.         IF xxx > x(tt) - 15 AND xxx < x(tt) + 15 AND yyy > y(tt) - 15 AND yyy < y(tt) + 15 THEN GOTO place:
  80.     NEXT tt
  81.     LINE (xxx, yyy)-(xxx + 5, yyy + 5), _RGB32(255, 0, 0), BF
  82.     leftxt2 = xxx - 4: leftyt2 = yyy + 2: leftxxt2 = xxx: leftyyt2 = yyy + 3
  83.     rightxt2 = xxx + 5: rightyt2 = yyy + 2: rightxxt2 = xxx + 9: rightyyt2 = yyy + 3
  84.     upxt2 = xxx + 2: upyt2 = yyy - 4: upxxt2 = xxx + 3: upyyt2 = yyy
  85.     downxt2 = xxx + 2: downyt2 = yyy + 5: downxxt2 = xxx + 3: downyyt2 = yyy + 9
  86.     ds = 2
  87.     LINE (downxt2, downyt2)-(downxxt2, downyyt2), _RGB32(255, 0, 0), BF
  88.     GOTO go:
  89. GOTO ggo:
  90.  
  91. 'Here is the main loop of the program where you move the square around.
  92. go:
  93. _LIMIT 100
  94. a$ = INKEY$
  95. IF a$ = CHR$(27) THEN END
  96. IF a$ = " " GOTO shoot:
  97. IF a$ = CHR$(0) + CHR$(72) THEN
  98.     ds = 1
  99.     GOSUB oldtank:
  100.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  101.     GOSUB oldtank2:
  102.     yy = yy - 5
  103.     GOSUB check:
  104.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  105.     upxt = xx + 2: upyt = yy - 4: upxxt = xx + 3: upyyt = yy
  106.     LINE (upxt, upyt)-(upxxt, upyyt), _RGB32(127, 127, 255), BF
  107.  
  108. IF a$ = CHR$(0) + CHR$(80) THEN
  109.     ds = 2
  110.     GOSUB oldtank:
  111.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  112.     GOSUB oldtank2:
  113.     yy = yy + 5
  114.     GOSUB check:
  115.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  116.     downxt = xx + 2: downyt = yy + 5: downxxt = xx + 3: downyyt = yy + 9
  117.     LINE (downxt, downyt)-(downxxt, downyyt), _RGB32(127, 127, 255), BF
  118.  
  119. IF a$ = CHR$(0) + CHR$(75) THEN
  120.     ds = 3
  121.     GOSUB oldtank:
  122.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  123.     GOSUB oldtank2:
  124.     xx = xx - 5
  125.     GOSUB check:
  126.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  127.     leftxt = xx - 4: leftyt = yy + 2: leftxxt = xx: leftyyt = yy + 3
  128.     LINE (leftxt, leftyt)-(leftxxt, leftyyt), _RGB32(127, 127, 255), BF
  129.  
  130. IF a$ = CHR$(0) + CHR$(77) THEN
  131.     ds = 4
  132.     GOSUB oldtank:
  133.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(0, 0, 0), BF
  134.     GOSUB oldtank2:
  135.     xx = xx + 5
  136.     GOSUB check:
  137.     LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  138.     rightxt = xx + 5: rightyt = yy + 2: rightxxt = xx + 9: rightyyt = yy + 3
  139.     LINE (rightxt, rightyt)-(rightxxt, rightyyt), _RGB32(127, 127, 255), BF
  140. IF shot = 1 AND ds = 1 THEN GOTO shoot1:
  141. IF shot = 1 AND ds = 2 THEN GOTO shoot2:
  142. IF shot = 1 AND ds = 3 THEN GOTO shoot3:
  143. IF shot = 1 AND ds = 4 THEN GOTO shoot4:
  144. GOTO monster:
  145.  
  146. 'Here is where the computer checks to see if your tank hits a wall.
  147. check:
  148. IF yy < 0 THEN yy = 0
  149. IF xx < 0 THEN xx = 0
  150. IF yy > 475 THEN yy = 475
  151. IF xx > 635 THEN xx = 635
  152.  
  153. FOR t = 1 TO p
  154.     IF xx > x(t) - 10 AND xx < x(t) + 15 AND yy > y(t) - 10 AND yy < y(t) + 15 THEN xx = oldxx: yy = oldyy
  155.  
  156. oldtank:
  157. oldyy = yy
  158. oldxx = xx
  159. oldleftxt = leftxt: oldleftyt = leftyt: oldleftxxt = leftxxt: oldleftyyt = leftyyt
  160. oldrightxt = rightxt: oldrightyt = rightyt: oldrightxxt = rightxxt: oldrightyyt = rightyyt
  161. oldupxt = upxt: oldupyt = upyt: oldupxxt = upxxt: oldupyyt = upyyt
  162. olddownxt = downxt: olddownyt = downyt: olddownxxt = downxxt: olddownyyt = downyyt
  163.  
  164. oldtank2:
  165. LINE (oldleftxt, oldleftyt)-(oldleftxxt, oldleftyyt), _RGB32(0, 0, 0), BF
  166. LINE (oldrightxt, oldrightyt)-(oldrightxxt, oldrightyyt), _RGB32(0, 0, 0), BF
  167. LINE (oldupxt, oldupyt)-(oldupxxt, oldupyyt), _RGB(0, 0, 0), BF
  168. LINE (olddownxt, olddownyt)-(olddownxxt, olddownyyt), _RGB(0, 0, 0), BF
  169.  
  170. shoot:
  171. shot = 1
  172. IF ds = 1 THEN
  173.     sx = xx + 3: sy = yy - 4
  174. IF ds = 2 THEN
  175.     sx = xx + 3: sy = yy + 10
  176. IF ds = 3 THEN
  177.     sx = xx - 4: sy = yy + 3
  178. IF ds = 4 THEN
  179.     sx = xx + 10: sy = yy + 4
  180.  
  181. SOUND 700, .5
  182. 'Up
  183. IF ds = 1 THEN
  184.     sy = sy - 10
  185.     shoot1:
  186.     _LIMIT 100
  187.     LINE (oldsx + 3, oldsy + 3)-(oldsx - 3, oldsy - 3), _RGB32(0, 0, 0), BF
  188.     sy = sy - 3
  189.     LINE (sx, sy)-(sx, sy - 3), _RGB32(255, 0, 0)
  190.     oldsx = sx: oldsy = sy
  191.     GOSUB checkshot:
  192.     GOTO go:
  193. 'Down
  194. IF ds = 2 THEN
  195.     sy = sy + 10
  196.     shoot2:
  197.     _LIMIT 100
  198.     LINE (oldsx - 3, oldsy - 3)-(oldsx + 3, oldsy + 3), _RGB32(0, 0, 0), BF
  199.     sy = sy + 3
  200.     LINE (sx, sy)-(sx, sy + 3), _RGB32(255, 0, 0)
  201.     oldsx = sx: oldsy = sy
  202.     GOSUB checkshot:
  203.     GOTO go:
  204. 'Left
  205. IF ds = 3 THEN
  206.     sx = sx - 10
  207.     shoot3:
  208.     _LIMIT 100
  209.     LINE (oldsx + 3, oldsy + 3)-(oldsx - 3, oldsy - 3), _RGB32(0, 0, 0), BF
  210.     sx = sx - 3
  211.     LINE (sx, sy)-(sx - 3, sy), _RGB32(255, 0, 0)
  212.     oldsx = sx: oldsy = sy
  213.     GOSUB checkshot:
  214.     GOTO go:
  215. 'Right
  216. IF ds = 4 THEN
  217.     sx = sx + 10
  218.     shoot4:
  219.     _LIMIT 100
  220.     LINE (oldsx - 3, oldsy - 3)-(oldsx + 3, oldsy + 3), _RGB32(0, 0, 0), BF
  221.     sx = sx + 3
  222.     LINE (sx, sy)-(sx + 3, sy), _RGB32(255, 0, 0)
  223.     oldsx = sx: oldsy = sy
  224.     GOSUB checkshot:
  225.     GOTO go:
  226.  
  227.  
  228. checkshot:
  229. 'Check your shot distance.
  230. sht = sht + 1
  231. IF sht > 150 THEN
  232.     sht = 0
  233.     GOSUB dscheck:
  234.     shot = 0
  235.     GOTO go:
  236.  
  237. 'Check walls and enemy.
  238. FOR tt = 1 TO p
  239.     IF sx > x(tt) - 10 AND sx < x(tt) + 10 AND sy > y(tt) - 10 AND sy < y(tt) + 10 THEN
  240.         GOSUB dscheck:
  241.         shot = 0
  242.         sht = 0
  243.         GOTO go:
  244.     END IF
  245.     IF sx > xxx - 10 AND sx < xxx + 10 AND sy > yyy - 10 AND sy < yyy + 10 THEN
  246.         FOR tttt = 1 TO 10
  247.             _LIMIT 50
  248.             CIRCLE (sx, sy), tttt, _RGB32(255, 0, 127)
  249.             CIRCLE (sx, sy), tttt + 5, _RGB32(255, 0, 127)
  250.             SOUND 100, .5
  251.             _DELAY .05
  252.             CIRCLE (sx, sy), tttt, _RGB32(0, 0, 0)
  253.             CIRCLE (sx, sy), tttt + 5, _RGB32(0, 0, 0)
  254.         NEXT tttt
  255.         CIRCLE (sx, sy), 7, _RGB32(0, 0, 0), BF
  256.         points = points + 10
  257.         points$ = STR$(points)
  258.         lives$ = STR$(lives)
  259.         titl$ = "Tank Walls     Score:" + points$ + "     Lives:" + lives$
  260.         _TITLE titl$
  261.         LINE (sx - 4, sy - 4)-(sx + 4, sy + 4), _RGB32(0, 0, 0), BF
  262.         GOSUB dscheck:
  263.         LINE (xxx - 5, yyy - 5)-(xxx + 6, yyy + 6), _RGB32(0, 0, 0), BF
  264.         shot = 0
  265.         mshot = 0
  266.         sht = 0
  267.         GOTO place:
  268.     END IF
  269. NEXT tt
  270.  
  271.  
  272. 'Your direction check to erase your old shot.
  273. dscheck:
  274. IF ds = 1 THEN LINE (sx, sy)-(sx, sy - 3), _RGB32(0, 0, 0)
  275. IF ds = 2 THEN LINE (sx, sy)-(sx, sy + 3), _RGB32(0, 0, 0)
  276. IF ds = 3 THEN LINE (sx, sy)-(sx - 3, sy), _RGB32(0, 0, 0)
  277. IF ds = 4 THEN LINE (sx, sy)-(sx + 3, sy), _RGB32(0, 0, 0)
  278.  
  279. '--------------------------------------------------------------------------------------------
  280. 'The last half of this program is what the enemy tank does.
  281. '--------------------------------------------------------------------------------------------
  282.  
  283. monster:
  284. GOSUB oldmonster:
  285.  
  286. IF xxx > xx AND yyy > yy - 10 AND yyy < yy + 10 THEN
  287.     dd = 1
  288.     GOTO monsters:
  289. IF xxx < xx AND yyy > yy - 10 AND yyy < yy + 10 THEN
  290.     dd = 2
  291.     GOTO monsters:
  292. IF yyy > yy AND xxx > xx - 10 AND xxx < xx + 10 THEN
  293.     dd = 3
  294.     GOTO monsters:
  295. IF yyy < yy AND xxx > xx - 10 AND xxx < xx + 10 THEN
  296.     dd = 4
  297.  
  298.  
  299. monsters:
  300. IF dd = 1 THEN
  301.     IF xxx > xx - 50 AND xxx < xx + 50 THEN
  302.         IF yyy > yy - 50 AND yyy < yy + 50 THEN
  303.             GOTO notcloser1:
  304.         END IF
  305.     END IF
  306.     GOSUB oldmonster:
  307.     xxx = xxx - 5
  308.     notcloser1:
  309.     GOSUB checkmonster:
  310.     LINE (oldxxx, oldyyy)-(oldxxx + 5, oldyyy + 5), _RGB(0, 0, 0), BF
  311.     GOSUB oldmonster2:
  312.     LINE (xxx, yyy)-(xxx + 5, yyy + 5), _RGB32(255, 0, 0), BF
  313.     leftxt2 = xxx - 4: leftyt2 = yyy + 2: leftxxt2 = xxx: leftyyt2 = yyy + 3
  314.     LINE (leftxt2, leftyt2)-(leftxxt2, leftyyt2), _RGB32(255, 0, 0), BF
  315. IF dd = 2 THEN
  316.     IF xxx > xx - 50 AND xxx < xx + 50 THEN
  317.         IF yyy > yy - 50 AND yyy < yy + 50 THEN
  318.             GOTO notcloser2:
  319.         END IF
  320.     END IF
  321.     GOSUB oldmonster:
  322.     xxx = xxx + 5
  323.     notcloser2:
  324.     GOSUB checkmonster:
  325.     LINE (oldxxx, oldyyy)-(oldxxx + 5, oldyyy + 5), _RGB(0, 0, 0), BF
  326.     GOSUB oldmonster2:
  327.     LINE (xxx, yyy)-(xxx + 5, yyy + 5), _RGB32(255, 0, 0), BF
  328.     rightxt2 = xxx + 5: rightyt2 = yyy + 2: rightxxt2 = xxx + 9: rightyyt2 = yyy + 3
  329.     LINE (rightxt2, rightyt2)-(rightxxt2, rightyyt2), _RGB32(255, 0, 0)
  330.  
  331. IF dd = 3 THEN
  332.     IF xxx > xx - 50 AND xxx < xx + 50 THEN
  333.         IF yyy > yy - 50 AND yyy < yy + 50 THEN
  334.             GOTO notcloser3:
  335.         END IF
  336.     END IF
  337.     GOSUB oldmonster:
  338.     yyy = yyy - 5
  339.     notcloser3:
  340.     GOSUB checkmonster:
  341.     LINE (oldxxx, oldyyy)-(oldxxx + 5, oldyyy + 5), _RGB(0, 0, 0), BF
  342.     GOSUB oldmonster2:
  343.     LINE (xxx, yyy)-(xxx + 5, yyy + 5), _RGB32(255, 0, 0), BF
  344.     upxt2 = xxx + 2: upyt2 = yyy - 4: upxxt2 = xxx + 3: upyyt2 = yyy
  345.     LINE (upxt2, upyt2)-(upxxt2, upyyt2), _RGB32(255, 0, 0), BF
  346.  
  347. IF dd = 4 THEN
  348.     IF xxx > xx - 50 AND xxx < xx + 50 THEN
  349.         IF yyy > yy - 50 AND yyy < yy + 50 THEN
  350.             GOTO notcloser4:
  351.         END IF
  352.     END IF
  353.     GOSUB oldmonster:
  354.     yyy = yyy + 5
  355.     notcloser4:
  356.     GOSUB checkmonster:
  357.     LINE (oldxxx, oldyyy)-(oldxxx + 5, oldyyy + 5), _RGB(0, 0, 0), BF
  358.     GOSUB oldmonster2:
  359.     LINE (xxx, yyy)-(xxx + 5, yyy + 5), _RGB32(255, 0, 0), BF
  360.     downxt2 = xxx + 2: downyt2 = yyy + 5: downxxt2 = xxx + 3: downyyt2 = yyy + 9
  361.     LINE (downxt2, downyt2)-(downxxt2, downyyt2), _RGB32(255, 0, 0), BF
  362.  
  363. IF mshot = 1 THEN GOTO monstershot2:
  364. rms = INT(RND * 1000) + 1
  365. IF rms > 988 THEN
  366.     mshot = 1
  367.     GOTO monstershot:
  368. GOTO go:
  369.  
  370. oldmonster:
  371. oldxxx = xxx
  372. oldyyy = yyy
  373. oldleftxt2 = leftxt2: oldleftyt2 = leftyt2: oldleftxxt2 = leftxxt2: oldleftyyt2 = leftyyt2
  374. oldrightxt2 = rightxt2: oldrightyt2 = rightyt2: oldrightxxt2 = rightxxt2: oldrightyyt2 = rightyyt2
  375. oldupxt2 = upxt2: oldupyt2 = upyt2: oldupxxt2 = upxxt2: oldupyyt2 = upyyt2
  376. olddownxt2 = downxt2: olddownyt2 = downyt2: olddownxxt2 = downxxt2: olddownyyt2 = downyyt2
  377.  
  378. oldmonster2:
  379. LINE (oldleftxt2, oldleftyt2)-(oldleftxxt2, oldleftyyt2), _RGB32(0, 0, 0), BF
  380. LINE (oldrightxt2, oldrightyt2)-(oldrightxxt2, oldrightyyt2), _RGB32(0, 0, 0), BF
  381. LINE (oldupxt2, oldupyt2)-(oldupxxt2, oldupyyt2), _RGB(0, 0, 0), BF
  382. LINE (olddownxt2, olddownyt2)-(olddownxxt2, olddownyyt2), _RGB(0, 0, 0), BF
  383.  
  384.  
  385. checkmonster:
  386. FOR tt = 1 TO p
  387.     IF xxx > x(tt) - 10 AND xxx < x(tt) + 15 AND yyy > y(tt) - 10 AND yyy < y(tt) + 15 THEN
  388.         xxx = oldxxx: yyy = oldyyy
  389.         GOSUB ddcheck:
  390.         RANDOMIZE TIMER
  391.         dd = INT(RND * 4) + 1
  392.         GOTO checkdone:
  393.     END IF
  394. NEXT tt
  395. checkdone:
  396.  
  397.  
  398. monstershot:
  399. SOUND 300, .5
  400.  
  401. IF dd = 1 THEN
  402.     mx = xxx - 4: my = yyy + 3
  403. IF dd = 2 THEN
  404.     mx = xxx + 10: my = yyy + 4
  405. IF dd = 3 THEN
  406.     mx = xxx + 3: my = yyy - 4
  407. IF dd = 4 THEN
  408.     mx = xxx + 3: my = yyy + 10
  409.  
  410. oldmx = mx
  411. oldmy = my
  412.  
  413. monstershot2:
  414. _LIMIT 500
  415. 'Left
  416. IF dd = 1 THEN
  417.     mshot1:
  418.     LINE (oldmx - 3, oldmy - 3)-(oldmx + 3, oldmy + 3), _RGB32(0, 0, 0), BF
  419.     mx = mx - 3
  420.     LINE (mx, my)-(mx - 3, my), _RGB32(255, 0, 0)
  421.     oldmx = mx: oldmy = my
  422.     GOSUB mcheckshot:
  423. 'Right
  424. IF dd = 2 THEN
  425.     mshot2:
  426.     LINE (oldmx - 3, oldmy - 3)-(oldmx + 3, oldmy + 3), _RGB32(0, 0, 0), BF
  427.     mx = mx + 3
  428.     LINE (mx, my)-(mx + 3, my), _RGB32(255, 0, 0)
  429.     oldmx = mx: oldmy = my
  430.     GOSUB mcheckshot:
  431. 'Up
  432. IF dd = 3 THEN
  433.     mshot3:
  434.     LINE (oldmx - 3, oldmy - 3)-(oldmx + 3, oldmy + 3), _RGB32(0, 0, 0), BF
  435.     my = my - 3
  436.     LINE (mx, my)-(mx, my - 3), _RGB32(255, 0, 0)
  437.     oldmx = mx: oldmy = my
  438.     GOSUB mcheckshot:
  439. 'Down
  440. IF dd = 4 THEN
  441.     mshot4:
  442.     LINE (oldmx - 3, oldmy - 3)-(oldmx + 3, oldmy + 3), _RGB32(0, 0, 0), BF
  443.     my = my + 3
  444.     LINE (mx, my)-(mx, my + 3), _RGB32(255, 0, 0)
  445.     oldmx = mx: oldmy = my
  446.     GOSUB mcheckshot:
  447.  
  448. GOTO go:
  449.  
  450. mcheckshot:
  451. 'Check his shot distance.
  452. sht2 = sht2 + 1
  453. IF sht2 > 150 THEN
  454.     sht2 = 0
  455.     GOSUB ddcheck:
  456.     mshot = 0
  457.     GOTO go:
  458. 'Check walls and if it hit your tank for his shot.
  459. FOR tt = 1 TO p
  460.     IF mx > x(tt) - 10 AND mx < x(tt) + 10 AND my > y(tt) - 10 AND my < y(tt) + 10 THEN
  461.         GOSUB ddcheck:
  462.         mshot = 0
  463.         sht2 = 0
  464.         GOTO go:
  465.     END IF
  466.     IF mx > xx - 10 AND mx < xx + 10 AND my > yy - 10 AND my < yy + 10 THEN
  467.         FOR tttt = 1 TO 10
  468.             _LIMIT 200
  469.             CIRCLE (mx, my), tttt, _RGB32(255, 0, 127)
  470.             CIRCLE (mx, my), tttt + 5, _RGB(255, 0, 127)
  471.             SOUND 100, .5
  472.             _DELAY .05
  473.             CIRCLE (mx, my), tttt, _RGB32(0, 0, 0)
  474.             CIRCLE (mx, my), tttt + 5, _RGB32(0, 0, 0)
  475.         NEXT tttt
  476.         LINE (mx - 4, my - 4)-(mx + 4, my + 4), _RGB32(0, 0, 0), BF
  477.         GOSUB ddcheck:
  478.         sht2 = 0
  479.         mshot = 0
  480.         lives = lives - 1
  481.         lives$ = STR$(lives)
  482.         titl$ = "Tank Walls     Score:" + points$ + "     Lives:" + lives$
  483.         _TITLE titl$
  484.         LINE (xx - 5, yy - 5)-(xx + 6, yy + 6), _RGB32(0, 0, 0), BF
  485.         LINE (xxx - 5, yyy - 5)-(xxx + 6, yyy + 6), _RGB32(0, 0, 0), BF
  486.         xx = 320: yy = 240
  487.         LINE (xx, yy)-(xx + 5, yy + 5), _RGB32(127, 127, 255), BF
  488.         a$ = ""
  489.         IF lives = 0 THEN
  490.             LOCATE 1, 35
  491.             PRINT "GAME OVER"
  492.             LOCATE 5, 35
  493.             INPUT "Play Again (Yes/No)"; ag$
  494.             IF ag$ = "yes" OR ag$ = "YES" OR ag$ = "Yes" OR ag$ = "yES" OR ag$ = "YEs" OR ag$ = "Y" OR ag$ = "y" THEN GOTO start:
  495.             END
  496.         END IF
  497.         GOTO place:
  498.     END IF
  499. NEXT tt
  500.  
  501.  
  502. 'His direction check to erase his old shot.
  503. ddcheck:
  504. IF dd = 1 THEN LINE (mx, my)-(mx - 3, my), _RGB32(0, 0, 0)
  505. IF dd = 2 THEN LINE (mx, my)-(mx + 3, my), _RGB32(0, 0, 0)
  506. IF dd = 3 THEN LINE (mx, my)-(mx, my - 3), _RGB32(0, 0, 0)
  507. IF dd = 4 THEN LINE (mx, my)-(mx, my + 3), _RGB32(0, 0, 0)
  508.  
  509.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Tank Walls
« Reply #21 on: July 02, 2019, 05:17:01 pm »
I like the "guided" shots... Shooting around corners was a brilliant addition... I now have the chance to survive!! YES!!  Unless... It was not your intention to add the feature... and now that you know... Lovely weather today... (My feeble attempt to distract... Did it work?)
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tank Walls
« Reply #22 on: July 02, 2019, 07:27:34 pm »
LOL Johno, funny you say that because when I was working on it at first, it was actually not my intention for the shots to change direction as they do. But then I quickly remembered that on the Atari 2600 game Combat, there was a selection that let you do the same exact thing, so I kept it. :) I liked that feature on the game Combat the best. lol

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tank Walls
« Reply #23 on: July 02, 2019, 09:59:56 pm »
I am working on Tank Walls 2. This will be more game oriented than an example program. It will have 20 maps (levels). Every 100 points you go to another level. I'm about done with the code part, I just have to make 18 more maps. :) After the player has made it past level 20, it goes back to 1. The speed or difficulty won't change per level since it's pretty fast already. But this will be the first time I've ever made a game with so many different maps. Might take a few days or more to make the maps, we'll see. But I'll post the zip of all the maps and the code to the forum when I'm done, and also my website.
« Last Edit: July 02, 2019, 10:01:21 pm by SierraKen »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Tank Walls
« Reply #24 on: July 03, 2019, 03:58:27 pm »
Neat, but it could use a flow through coding method so that when you fire the blue tank, the red tank keeps moving. Just cut the delay in half, and poll the red tank every time the blue tank bullet moves one space. Restore the original delay when the bullet is terminated.

Pete
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: Tank Walls
« Reply #25 on: July 03, 2019, 06:50:22 pm »
Wow thanks Pete! All I had to do is delete the Return of the first half's part of your tank. So now the program flows straight through to the other tank in the same loop as your tank. I also had to add a "GOTO monster:" so it would skip the last little gosub section of your tank's code. I also changed the _LIMIT command on a few of them, but I might change it again later on. I don't have a _DELAY on the movement of the tanks, just on the explosions, but _LIMIT changes the speed when I make it smaller than 200 usually. All of this will be on Tank Walls 2. I've made 10 maps so far, 10 more to go and then I will release it here. :) Thanks again.
« Last Edit: July 03, 2019, 07:02:02 pm by SierraKen »