Author Topic: Artillery Wanted  (Read 11190 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #30 on: June 25, 2019, 11:14:32 pm »
Fun stuff B+, but the way I do it with my random mountain is just 1 half of a big circle using Paint. Then using the POINT command it knows exactly what color to look for. Your colors blend together so it would be pretty difficult using yours. But those are pretty neat mountains. :) I'm going to look over my code 1 more time and post the finished product here (hopefully).

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #31 on: June 25, 2019, 11:48:02 pm »
Cool... Two things missing.... Snow and a set of skis... lol
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #32 on: June 26, 2019, 12:23:52 am »
Ken,

This is the section, converted from the Applesoft Artillery game, that draws a simple "hill".
Sorry about the screen size... But that's Apple of the 80's... lol

SCREEN _NEWIMAGE(280, 200, 32)

DIM YY(280)

P1 = 99
PI = 3.141592654 / 180

P = RND(1) * 20 + 139
FOR I = 1 TO 112
    LINE (I, P)-(I, 159), _RGB32(0, 255, 0)
    YY(I) = P
NEXT
HG = RND(1) * 50 + 25
FOR I = 113 TO 152
    HX = SIN(((I - 112) * 4.5 + 180) * PI) * HG
    YY(I) = HX + P
    LINE (I, HX + P)-(I, 159), _RGB32(0, 255, 0)
NEXT
FOR I = 153 TO 279
    LINE (I, P)-(I, 159), _RGB32(0, 255, 0)
    YY(I) = P
NEXT

J
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #33 on: June 26, 2019, 12:31:57 am »
LOL Johno, the old CGA graphics :). I'm using a half-circle for a mountain, but the random function seems to get sticky sometimes. It will have a random number for a few turns, then stay at the same number for the rest of the game... not sure what's going on yet.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Artillery Wanted
« Reply #34 on: June 26, 2019, 12:48:18 am »
Hi Ken,

You might be overusing RANDOMIZE, (you are using it before every call to RND which is not necessary) you deleted the code post so I don't remember if you also used TIMER for seed. If not, you could be resetting random number sequence back to start of sequence and run same numbers over and over.

I don't need to know all the POINT values of mountains, just the sky, and the bases and to watch out for the black print in the sky. If it's not the sky, the bases, or the black print and the point is on screen then it must be a mountain or the ground.

Here is a screen test:
 
Ken's Artillery.PNG


I am going to see if I can improve on AI, seems to me it worked better before the overhaul, you deleted the code so I can't check back to see if I changed something I shouldn't had. You weren't using the green hill color for gaging shots? ;-))
« Last Edit: June 26, 2019, 01:00:11 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #35 on: June 26, 2019, 01:04:32 am »
That looks really nice B+. But the cannonball always hits the text in the sky so I couldn't put a <> blue on the POINT value, but that's OK, I like my rolling mountain. :) I'm going to stop here and post my code and let you all look at it. You can do what you wish to it of course. Wow yeah I think my _DELAY command as well as possibly averaging out random lines on accident (possibly) was causing it. lol Thanks for the help you 2. Well, here is the game. It's not the hardest game LOL but the computer can still win (once in a great while). I tried to make it a bit harder but it was like pulling teeth on random variables lol. So.... once and for all... here it is.... :) (And of course any more suggestions would be appreciated lol).  Edit: I could put a if POINT <> black or Point <> blue for the text in the sky, but nahh, I like some originality of my own in this. :) 

Edit: Program deleted again because it was too easy, the better one is in the next post.
« Last Edit: June 26, 2019, 01:17:44 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #36 on: June 26, 2019, 01:19:40 pm »
Well, since it was too easy, I made it so the computer uses the same angle as you do, just their power will be different. It's still pretty easy if you get the hang of it. But here's the program, enjoy!
I also just added it to my website here: http://ken.x10host.com/qb64/


Code: QB64: [Select]
  1. 'I've always wanted to make this game ever since I started programming in the 80's.
  2. 'This was made using the BASIC and compile language QB64 from QB64.org
  3. 'This was created by Ken G. with much help from others below.
  4. 'Thank you to B+ for posting much of this math code on the QB64.org forum!
  5. 'It takes the computer a little time to learn how to hit your base.
  6. 'Created on June 25, 2019.
  7.  
  8.  
  9. _TITLE "Ken's Artillery"
  10. start:
  11. compoints = 0
  12. points = 0
  13. c = 0
  14. mountain = 0
  15. SCREEN _NEWIMAGE(1200, 700, 32)
  16. PRINT "                                               Ken's Artillery"
  17. PRINT "                           By Ken G. with math help from B+ from QB64.org Forum."
  18. PRINT "                         Instructions: You play against the computer by shooting a cannonball"
  19. PRINT "                         from your cannon at your base on the left side of the screen"
  20. PRINT "                         to the computer's base on the right side of the screen."
  21. PRINT "                         To do this, you type a power number between 0 and 80 and press Enter."
  22. PRINT "                         Then you type an angle that the cannonball will travel at,"
  23. PRINT "                         between 0 and 90 and press Enter."
  24. PRINT "                         You get a point every time you hit the other base."
  25. PRINT "                         The first to get 5 points wins the game."
  26. PRINT "                         Watch the wind speed indicator up on top to see the direction and"
  27. PRINT "                         speed of the wind, which makes a big difference on where your"
  28. PRINT "                         cannonball will land. Also, there will be a random sized mountain"
  29. PRINT "                         for every game."
  30. INPUT "                         Press Enter to begin.", start$
  31.  
  32. ground = 590 'up is negative in direction
  33.  
  34. 'Your Cannon
  35.  
  36. cbx = 10 '              cannon butt end x, y
  37. cby = ground - 20
  38. cmx = 50 '              cannon mouth end
  39. cmy = ground - 70
  40.  
  41. 'Computer's Cannon
  42.  
  43. cbx2 = 1190
  44. cby2 = cby
  45. cmx2 = 1150
  46. cmy2 = cmy
  47.  
  48.  
  49. g = .15 '       with air resistance
  50. air = INT(RND * 20)
  51. air2 = air / 1000
  52. air3 = INT(RND * 100)
  53. IF air3 > 50 THEN air2 = -air2
  54. airX = air2
  55. COLOR , _RGB32(156, 210, 237)
  56. LINE (0, ground)-(1200, 700), _RGB32(74, 86, 58), BF 'ground
  57. 'Bases
  58. LINE (cbx, ground)-(cbx + 100, ground - 20), _RGB32(4, 4, 4), BF
  59. LINE (cbx2, ground)-(cbx2 - 100, ground - 20), _RGB32(4, 4, 4), BF
  60. 'Mountain
  61. sz = INT(RND * 300) + 100
  62. circx = 595
  63. CIRCLE (circx, ground), sz, _RGB32(74, 86, 58)
  64. PAINT (circx, ground - 2), _RGB32(74, 86, 58)
  65.  
  66. again:
  67. COLOR _RGB(0, 0, 0)
  68. LOCATE 10, 120: PRINT "               "
  69. LOCATE 10, 1: PRINT "Your Turn     "
  70. air = INT(RND * 20)
  71. air2 = air / 1000
  72. air3 = INT(RND * 100)
  73. IF air3 > 50 THEN air2 = -air2
  74. airX = air2
  75. airx2 = airX * 1000
  76. IF airx2 < -1 THEN winddir$ = "West"
  77. IF airx2 > 1 THEN winddir$ = "East"
  78. IF airx2 > -1 AND airx2 < 1 THEN winddir$ = "Sunny"
  79. IF airx2 < 0 THEN airx2 = airx2 * -1
  80.  
  81. GOSUB Wind:
  82. COLOR _RGB(0, 0, 0)
  83. LOCATE 1, 1: INPUT "Power (0-80):", vel
  84. LOCATE 2, 1: INPUT "Angle (0-90): ", a
  85. LOCATE 1, 1: PRINT "                            "
  86. LOCATE 2, 1: PRINT "                            "
  87. going:
  88. IF a > 90 THEN a = 90
  89. IF a < 0 THEN a = 0
  90. IF vel < 0 THEN vel = 0
  91. IF vel > 80 THEN vel = 80
  92. vel = INT(vel / 4)
  93. a = 360 - a
  94. ca = _D2R(a)
  95. cmx = cbx + (100 * COS(_D2R(a)))
  96. cmy = cby + (100 * SIN(_D2R(a)))
  97.  
  98. 'initialize
  99. bx = cmx 'ball x, y same as cannon mouth at start of shot
  100. by = cmy
  101.  
  102.  
  103. dx = vel * COS(ca) 'start at cannon mouth
  104. dy = vel * SIN(ca)
  105.  
  106. 'shot
  107.  
  108.     GOSUB Wind:
  109.  
  110.     a$ = INKEY$
  111.     IF a$ = CHR$(27) THEN END
  112.     CIRCLE (bx, by), 5, _RGB32(0, 0, 0)
  113.     PAINT (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  114.     LINE (cbx, cby)-(cmx, cmy), _RGB32(150, 50, 0) 'cannon line
  115.     oldbx = bx: oldby = by
  116.     dx = dx + airX
  117.     dy = dy + g
  118.     bx = bx + dx
  119.     by = by + dy
  120.     _DISPLAY
  121.     _LIMIT 30
  122.     CIRCLE (oldbx, oldby), 5, _RGB(156, 210, 237)
  123.     PAINT (oldbx, oldby), _RGB(156, 210, 237)
  124.     IF POINT(bx, by) = _RGB32(74, 86, 58) THEN
  125.         mountain = 1
  126.         FOR explosion = 0 TO 20 STEP .5
  127.             CIRCLE (bx, by), explosion, _RGB32(156, 210, 237)
  128.             SOUND 100 + explosion, .25
  129.         NEXT explosion
  130.     END IF
  131.     IF bx > cbx2 - 120 AND bx < cbx2 + 20 AND by >= ground THEN
  132.         points = points + 1
  133.         LOCATE 3, 69: PRINT "You: "; points; " Computer: "; compoints
  134.         FOR explosion = 0 TO 20 STEP .5
  135.             CIRCLE (bx, by), explosion, _RGB32(156, 210, 237)
  136.             SOUND 100 + explosion, .25
  137.         NEXT explosion
  138.         FOR sndd = 500 TO 700 STEP 50
  139.             SOUND sndd, 1
  140.         NEXT sndd
  141.         mountain = 1
  142.         IF points = 5 THEN COLOR _RGB(0, 0, 0): LOCATE 20, 65: PRINT "YOU WIN!": GOTO asking:
  143.     END IF
  144. LOOP UNTIL mountain = 1 OR by > 700
  145. LINE (cbx, cby)-(cmx, cmy), _RGB32(156, 210, 237) 'delete cannon line
  146. mountain = 0
  147. 'The Computer's Turn
  148.  
  149. comp:
  150.  
  151. COLOR _RGB(0, 0, 0)
  152. LOCATE 10, 1: PRINT "             "
  153. LOCATE 10, 120: PRINT "Computer Turn"
  154. GOSUB Wind:
  155.  
  156. 'Computer learns as it goes but is not perfect, like a human.  ;-)
  157. IF c = 0 THEN GOTO compstuff:
  158. oldvel2 = vel2
  159.  
  160. compstuff:
  161. vel2 = INT(RND * 35) + 30
  162.  
  163. a2 = a
  164.  
  165. vel2 = INT(vel2 / 4)
  166.  
  167. IF c = 0 THEN GOTO nex:
  168. 'Last shot was too far away.
  169. IF oldbx2 < cbx THEN
  170.     vel2 = oldvel2 - 1
  171.     IF vel2 < 8 THEN vel2 = 8
  172. 'Last shot wasn't far enough.
  173. IF oldbx2 > cbx THEN
  174.     vel2 = oldvel2 + 1
  175.     IF vel2 > 15 THEN vel2 = 15
  176. nex:
  177. c = 1
  178. ca2 = _D2R(a2)
  179. cmx2 = cbx2 - (100 * COS(_D2R(a2)))
  180. cmy2 = cby2 + (100 * SIN(_D2R(a2)))
  181.  
  182. 'initialize
  183. bx2 = cmx2 'ball x, y same as cannon mouth at start of shot
  184. by2 = cmy2
  185. dx2 = vel2 * COS(ca2) 'start at cannon mouth
  186. dy2 = vel2 * SIN(ca2)
  187.  
  188. 'shot
  189.  
  190.     a$ = INKEY$
  191.     IF a$ = CHR$(27) THEN END
  192.     CIRCLE (bx2, by2), 5, _RGB32(0, 0, 0)
  193.     PAINT (bx2, by2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  194.     LINE (cbx2, cby2)-(cmx2, cmy2), _RGB32(150, 50, 0) 'cannon line
  195.     oldbx2 = bx2: oldby2 = by2
  196.     dx2 = dx2 + airX
  197.     dy2 = dy2 + g
  198.     bx2 = bx2 - dx2
  199.     by2 = by2 + dy2
  200.     _DISPLAY
  201.     _LIMIT 30
  202.     CIRCLE (oldbx2, oldby2), 5, _RGB(156, 210, 237)
  203.     PAINT (oldbx2, oldby2), _RGB(156, 210, 237)
  204.     IF POINT(bx2, by2) = _RGB32(74, 86, 58) THEN
  205.         mountain = 1
  206.         FOR explosion = 0 TO 20 STEP .5
  207.             CIRCLE (bx2, by2), explosion, _RGB32(156, 210, 237)
  208.             SOUND 100 + explosion, .25
  209.         NEXT explosion
  210.     END IF
  211.     IF bx2 > cbx - 20 AND bx2 < cbx + 120 AND by2 >= ground THEN
  212.         compoints = compoints + 1
  213.         LOCATE 3, 69: PRINT "You: "; points; " Computer: "; compoints
  214.         FOR explosion = 0 TO 20 STEP .5
  215.             CIRCLE (bx2, by2), explosion, _RGB32(156, 210, 237)
  216.             SOUND 100 + explosion, .25
  217.         NEXT explosion
  218.         FOR sndd = 500 TO 700 STEP 50
  219.             SOUND sndd, 1
  220.         NEXT sndd
  221.         mountain = 1
  222.         IF compoints = 5 THEN COLOR _RGB(0, 0, 0): LOCATE 20, 65: PRINT "COMPUTER WINS!": GOTO asking:
  223.     END IF
  224. LOOP UNTIL mountain = 1 OR by2 > 700
  225.  
  226. LINE (cbx2, cby2)-(cmx2, cmy2), _RGB32(156, 210, 237) 'delete cannon line
  227. mountain = 0
  228. GOTO again:
  229.  
  230. 'This code is used in a few different places in the program.
  231. Wind:
  232. COLOR _RGB(0, 0, 0)
  233. LOCATE 1, 73: PRINT "Wind"
  234. IF winddir$ = "West" THEN
  235.     LOCATE 2, 83: PRINT "                               "
  236.     LOCATE 2, 56: PRINT airx2; " mph   "
  237. IF winddir$ = "East" THEN
  238.     LOCATE 2, 56: PRINT "               "
  239.     LOCATE 2, 83: PRINT airx2; " mph   "
  240. LOCATE 2, 69: PRINT "West <-> East"
  241. LOCATE 3, 69: PRINT "You: "; points; " Computer: "; compoints
  242.  
  243. asking:
  244. LOCATE 22, 65: INPUT "Again? (Yes/No):", ag$
  245. IF ag$ = "y" OR ag$ = "Y" OR ag$ = "yes" OR ag$ = "Yes" OR ag$ = "YES" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO start:
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
« Last Edit: June 26, 2019, 02:01:23 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #37 on: June 26, 2019, 05:57:14 pm »
This game is coming along quite nicely!  I found a small wrinkle... actually a glaring problem.... I keep getting hit by the computer!  There is a 'real' chance that I could be killed off...  I think you should seriously include a "God Mode" and only tell 'me' what the code is.... Nah... I'm kidding. You don't need to include a 'God Mode'... Just don't allow the enemy to fire... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #38 on: June 26, 2019, 06:00:03 pm »
LOL John! Wow, you got kinda unlucky on that game. hehe. Thanks for checking it out!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #39 on: June 26, 2019, 08:49:13 pm »
Oh, don't get me wrong, I didn't say that I 'lost'.... I'm being shot at... I prefer a 'one-sided' game, but that's me, everyone else enjoys a challenge... lol

Good game. Apart from being shot at, I enjoyed playing it... Well done!
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #40 on: June 26, 2019, 10:57:19 pm »
Thanks!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Artillery Wanted
« Reply #41 on: June 27, 2019, 01:49:16 am »
Nice game!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


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

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #42 on: June 28, 2019, 11:34:10 am »
Thanks Ashish! :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Artillery Wanted
« Reply #43 on: June 28, 2019, 11:54:49 am »
Hey Ken,

This is a nice game with the computer as opponent!

While reworking the code to more my style to use mountains and play with AI for computer, I ran into a problem I will call "tunneling". This happens when you use the sky color over last cannon ball location to erase it and then using POINT to detect objects not the sky color.

If the new ball location is less than it's radius in distance, POINT will detect sky color from last erase and keep the ball going because no object hit was detected.

Even if you don't erase the ball, POINT will detect the ball color (Black) if the new location is still less than a radius away from last. I'm not sure your version has completely overcome "tunneling" but it sure works better than my early remake version! I don't know how you managed to avoid more blatant "tunneling" with your version.

Have you noticed this phenomena?
 

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #44 on: June 28, 2019, 02:31:49 pm »
Wow that is interesting. Mine uses POINT to only detect the brown dirt, nothing else. Like if it hits the text in the sky, it just goes through it. And since the sky is blue, it won't detect that either. This is what I have on mine:
Code: QB64: [Select]
  1. IF POINT(bx, by) = _RGB32(74, 86, 58) THEN
  2.  

I'm not sure what else would help you, I am very, very new on POINT. This is probably the very first time I ever used it.