QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on June 22, 2019, 10:43:28 pm

Title: Artillery Wanted
Post by: SierraKen on June 22, 2019, 10:43:28 pm
Does anyone remember some of the very first PC games from the 70's and early 80's? One really popular one was called Artillery. You shot over a mountain to try and hit your opponents cannon. You first set your angle and velocity. It was a 2 or 3 player game, depending on which version. Looking at some websites about it, there was one made in Turbo Basic back in the day but nothing else I can find so far. Would love to try and make it. I might someday. I guess it wouldn't be too hard to make the holes if you use the PAINT fill-in after you draw the land and wherever your cannonball hits, it makes a big hole. Was a really fun game. I might even try to make it a 1 player game. :)
Title: Re: Artillery Wanted
Post by: bplus on June 22, 2019, 10:53:41 pm
Here is something I did with tanks:
https://www.qb64.org/forum/index.php?topic=1130.msg103232#msg103232

I started a projectile study in that thread too.

The Gorilla that throws exploding banana's is a classic, Nibbles? was it?

Nibbles was the snake game, Gor64 in programs of QB64 samples is the Gorillas Game.

BTW have you looked through the sample programs?
Title: Re: Artillery Wanted
Post by: SierraKen on June 22, 2019, 11:06:13 pm
Wow now I haven't, they are a bit buried in the folders so I'll copy them and put them with the rest of mine. :) Awesome stuff!
Title: Re: Artillery Wanted
Post by: SierraKen on June 22, 2019, 11:13:18 pm
ROFL I totally forgot about Gorilla. I love it! LOL
Title: Re: Artillery Wanted
Post by: johnno56 on June 23, 2019, 08:54:54 am
Tektronix 4051 computer of the mid 70's had a demo program 'Artillery'. In 1980, 'Artillery' and 'Super Artillery', were released on the Apple2.

I believe that this is the game you are referring to?

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

I may have the listing somewhere buried amongst my files... Do not hold your breath waiting... lol

J
Title: Re: Artillery Wanted
Post by: bplus on June 23, 2019, 09:07:19 am
Oh Johnno, that reminds me of something I saw in JB, maybe I can find it and translate...

It also reminds me of something we (you?) started on at SdlBasic... maybe I can did that up too? (or better left buried   ;-)  )
Title: Re: Artillery Wanted
Post by: johnno56 on June 23, 2019, 09:08:14 am
Found it!

J
Title: Re: Artillery Wanted
Post by: johnno56 on June 23, 2019, 09:09:40 am
Dig away... Your memory is obviously better than mine... lol
Title: Re: Artillery Wanted
Post by: bplus on June 23, 2019, 09:28:58 am
Found JB game, looks familiar supposedly copyright by Carl but obviously this game comes from Johnno's.

Oh and look, it's GUI, great minds think alike! (or just copy one another without realizing)

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Title: Re: Artillery Wanted
Post by: johnno56 on June 23, 2019, 09:45:24 am
Did you spot the technical glitch with the image? The wind is travelling from right to left at a velocity of 19, right? Then why is the flag of the right hand tank fluttering in the opposite direction? Ka-ching! Ding. Ding. Ding. And the prize goes to.....

Basic's with GUI libraries... Not all have them but I think they should....  I miss the old Scorched Earth.... I have the latest '3D' version but it doesn't have the same 'feel' as the old version...
Title: Re: Artillery Wanted
Post by: bplus on June 23, 2019, 10:22:29 am
Hi Johnno,

I found the folder, I don't have SdlBasic running on this computer, is there anything worth translating to QB64?
BTW my first version of Tanks Battle was born from this study and at Naalaa for a Gorilla clone.

BTW if anyone needs a Gorilla... ;-))

PS nothing wrong with your eyesight! ;-)

Title: Re: Artillery Wanted
Post by: SierraKen on June 23, 2019, 12:23:34 pm
WOW Thanks guys! I'll take a look at those 2 later today!
Title: Re: Artillery Wanted
Post by: SierraKen on June 23, 2019, 04:41:54 pm
Looks like that was made with an Apple computer or something similar. I tried converting it but it looks pretty difficult without messing anything up. I'm still going to see if I can find the math for my own game though on this. Thanks.
Title: Re: Artillery Wanted
Post by: SierraKen on June 23, 2019, 08:07:50 pm
B+ I used your "Projectile Study" code to make a similar game. Here is what I have so far. I hope it's OK with you that I use this code. If I make a game good enough, I'll add the program to my website with your name as well as mine. Of course I will never sell anything I put on my website or with code that anyone people posts. I am still am amateur programmer and probably always will be. Anyway, here is the code I have so far. I figured out how to ask the user for degrees and power. I also changed the colors a tiny bit on the sky and land and made the window much larger. Plus I made a sound and funky explosion lol. Feel free to use my code too of course. This isn't really a game so far but more of a simulator but later on I will probably see if I can make you go against the computer, kinda like I did with Ping Pong lol (but not impossible LOL). Thank you tons for posting that code. Here is what I did with it so far:
Code: QB64: [Select]
  1. 'Thank you to B+ for posting much of this code on the QB64.org Forum!
  2.  
  3. _TITLE "Ken's Artillery"
  4. SCREEN _NEWIMAGE(1600, 800, 32)
  5. ground = 590 'up is negative in direction
  6.  
  7. cbx = 10 '              cannon butt end x, y
  8. cby = ground - 10
  9. cmx = 50 '              cannon mouth end
  10. cmy = ground - 70
  11.  
  12.  
  13. g = .15 '       with air resistance
  14. airX = -.005 '         wind blows against direction of shot
  15. COLOR , _RGB32(156, 210, 237)
  16. LINE (0, ground)-(1600, 800), _RGB32(74, 86, 58), BF 'ground
  17. LINE (cbx, cby)-(cmx, cmy), _RGB32(150, 50, 0) 'cannon line
  18.  
  19. GOSUB coords:
  20.  
  21. again:
  22. 'initialize
  23. bx = cmx 'ball x, y same as cannon mouth at start of shot
  24. by = cmy
  25.  
  26.  
  27. dx = vel * COS(ca) 'start at cannon mouth
  28. dy = vel * SIN(ca)
  29.  
  30. 'shot
  31.     CLS 'sky
  32.     a$ = INKEY$
  33.     IF a$ = CHR$(27) THEN END
  34.     LINE (0, ground)-(1600, 800), _RGB32(74, 86, 58), BF 'ground
  35.     LINE (cbx, cby)-(cmx, cmy), _RGB32(150, 50, 0) 'cannon line
  36.     CIRCLE (bx, by), 5, _RGB32(0, 0, 0)
  37.     PAINT (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  38.     dx = dx + airX
  39.     dy = dy + g
  40.     bx = bx + dx
  41.     by = by + dy
  42.     _DISPLAY
  43.     _LIMIT 30
  44.     IF by > ground THEN
  45.         FOR explosion = 10 TO 50 STEP 5
  46.             CIRCLE (bx, by), explosion, _RGB32(4, 4, 4)
  47.             SOUND 150 + (explosion * 5), 1
  48.         NEXT explosion
  49.     END IF
  50. LOOP UNTIL bx > 1600 OR by > ground OR bx < 0
  51. GOSUB coords:
  52. GOTO again:
  53. coords:
  54. COLOR _RGB(0, 0, 0)
  55. LOCATE 1, 1: INPUT "Power (0-80):", vel
  56. LOCATE 2, 1: INPUT "Angle (0-360): ", a
  57. going:
  58. vel = INT(vel / 4)
  59. IF a > 360 THEN a = 360
  60. IF a < 0 THEN a = 0
  61. IF vel < 0 THEN vel = 0
  62. IF vel > 80 THEN vel = 80
  63. a = 360 - a
  64. ca = _D2R(a)
  65.  

Title: Re: Artillery Wanted
Post by: bplus on June 23, 2019, 09:01:07 pm
Hi SierraKen,

For angle, I'd make the allowable range between 0 and 90 degrees. Nice that you figured to subtract the input angle from 360 degrees.

I have worked out a way to set angle with mouse and to use up and down arrow keys to change speed so there is no input for extra enter key press.

The cannon should adjust it's angle to the input angle before firing in my opinion.

The math for that:
If the angle input is 20 degrees then subtract from 360 = 340 as you have done for firing the projectile.
Convert 340 degrees to radians: use _D2R(340) or 340 * _PI / 180, now you have a number SIN and COS can use.

Say the cannon length is 100 then the X coordinate will be ( with butt end coord's (bx, by) )
exit end = bx + 100 * COS(_D2R(340))
exit end = by - 100 * SIN(_D2R(340))   because raising the cannon mouth is decreasing the y coordinate value.

BTW you must have a giant screen, on my laptop I reduce x to 1200 and y to 700. :)
Title: Re: Artillery Wanted
Post by: SierraKen on June 23, 2019, 09:59:32 pm
Awesome thanks again! I used your suggestions and added what you said about the cannon angle. I also changed the window size to 1200 x 700. Plus I changed the sound to a bit deeper sound so it's not an irritating one lol. But it took about an hour to figure out what variables to use and how to do the equations you told me about. It's just 2 lines I needed, which are these, which are down below as the last lines before "RETURN".
Code: QB64: [Select]
  1. cmx = cbx + (100 * COS(_D2R(a)))
  2. cmy = cby + (100 * SIN(_D2R(a)))
  3.  
That wraps it up for tonight on my programming, I never program late anymore like I did in the 90's. I hope to work on it more this coming week and will post my progress. :)
Title: Re: Artillery Wanted
Post by: johnno56 on June 24, 2019, 12:06:39 am
I couldn't resist... Sorry.  A few minor tweaks. May not be the right way to do it but it seems to work.

J

Code: QB64: [Select]
  1. 'Thank you to B+ for posting much of this code on the QB64.org Forum!
  2.  
  3. _TITLE "Ken's Artillery"
  4. SCREEN _NEWIMAGE(1600, 800, 32)
  5. ground = 590 'up is negative in direction
  6.  
  7. cbx = 10 '              cannon butt end x, y
  8. cby = ground - 10
  9. cmx = 50 '              cannon mouth end
  10. cmy = ground - 70
  11.  
  12.  
  13. g = .15 '       with air resistance
  14. airX = -.005 '         wind blows against direction of shot
  15. COLOR , _RGB32(156, 210, 237)
  16. CLS ' sky
  17. LINE (0, ground)-(1600, 800), _RGB32(74, 86, 58), BF 'ground
  18. LINE (cbx, cby)-(cmx, cmy), _RGB32(150, 50, 0) 'cannon line
  19.  
  20. GOSUB coords:
  21.  
  22. again:
  23. 'initialize
  24. bx = cmx 'ball x, y same as cannon mouth at start of shot
  25. by = cmy
  26.  
  27.  
  28. dx = vel * COS(ca) 'start at cannon mouth
  29. dy = vel * SIN(ca)
  30.  
  31. 'shot
  32.     CLS
  33.     a$ = INKEY$
  34.     IF a$ = CHR$(27) THEN END
  35.     LINE (0, ground)-(1600, 800), _RGB32(74, 86, 58), BF 'ground
  36.     LINE (cbx, cby)-(cmx, cmy), _RGB32(150, 50, 0) 'cannon line
  37.     CIRCLE (bx, by), 5, _RGB32(0, 0, 0)
  38.     PAINT (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  39.     dx = dx + airX
  40.     dy = dy + g
  41.     bx = bx + dx
  42.     by = by + dy
  43.     _DISPLAY
  44.     _LIMIT 30
  45.     IF by > ground THEN
  46.         FOR explosion = 10 TO 50 STEP 0.5
  47.             CIRCLE (bx, by), explosion, _RGB32(156, 210, 237)
  48.             SOUND 150 + (explosion * 5), 0.07
  49.         NEXT explosion
  50.         FOR i = 0 TO 10 STEP 0.5
  51.             CIRCLE (bx, by), i, _RGB(156, 210, 237)
  52.         NEXT
  53.     END IF
  54. LOOP UNTIL bx > 1600 OR by > ground OR bx < 0
  55. GOSUB coords:
  56. GOTO again:
  57. coords:
  58. COLOR _RGB(0, 0, 0)
  59. LOCATE 1, 1: INPUT "Power (0-80):", vel
  60. LOCATE 2, 1: INPUT "Angle (0-360): ", a
  61. going:
  62. vel = INT(vel / 4)
  63. IF a > 360 THEN a = 360
  64. IF a < 0 THEN a = 0
  65. IF vel < 0 THEN vel = 0
  66. IF vel > 80 THEN vel = 80
  67. a = 360 - a
  68. ca = _D2R(a)
  69.  
Title: Re: Artillery Wanted
Post by: bplus on June 24, 2019, 12:40:25 am
Here is what I came up with after stuck with messing around with moving target in afternoon.

I went with number key press for speed setting.

So look at the Moon, set your speed number, move mouse so arrow is the angle you want to try and click the mouse to shoot.

Here is "Shoot'n for the Moon":
Code: QB64: [Select]
  1. _TITLE "Shoot'n for the Moon" 'B+ started 2019-06-23
  2. CONST xmax = 1200, ymax = 700, pi = 3.14159265
  3.  
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 100, 20
  6.  
  7. CONST gravity = .035
  8. CONST airResistance = .01
  9. CONST nStars = 127
  10. CONST lnth = 100
  11. CONST wallx1 = .5 * xmax - 20
  12. CONST wallx2 = .5 * xmax
  13.  
  14. TYPE XYR
  15.     x AS INTEGER
  16.     y AS INTEGER
  17.     r AS INTEGER
  18.  
  19. TYPE projectile
  20.     x AS INTEGER
  21.     y AS INTEGER
  22.     dx AS SINGLE
  23.     dy AS SINGLE
  24.     a AS SINGLE 'radian angle
  25.     speed AS SINGLE
  26.     active AS INTEGER
  27. DIM SHARED level, p AS projectile, t AS XYR, wallY, stars(1 TO nStars) AS XYR
  28.  
  29. 'set up stars
  30. DIM i, r
  31. FOR i = 1 TO 127
  32.     stars(i).x = xmax * RND
  33.     stars(i).y = ymax * RND
  34.     r = RND
  35.     SELECT CASE r
  36.         CASE IS < .5: stars(i).r = 0
  37.         CASE IS < .75: stars(i).r = 1
  38.         CASE IS < .875: stars(i).r = 2
  39.         CASE IS < .9375: stars(i).r = 3
  40.         CASE ELSE: stars(i).r = 1
  41.     END SELECT
  42.  
  43. level = 1
  44. COLOR , &H0 'clear background for printing on various shades of blue
  45.     DrawSpace
  46.     InitTarget
  47.     Target
  48.     InitProjectile
  49.     WHILE p.active
  50.         DrawSpace 'cls
  51.         Arrow
  52.         Target
  53.         p.dy = p.dy + gravity
  54.         p.dx = p.dx + airResistance
  55.         p.x = p.x + p.dx
  56.         p.y = p.y + p.dy
  57.         p.a = _ATAN2(p.dy, p.dx) 'reset arrow angle
  58.         'IF p.a < 0 THEN p.a = p.a + 2 * pi
  59.         IF ((p.x - t.x) ^ 2 + (p.y - t.y) ^ 2) ^ .5 < t.r THEN
  60.             p.active = 0: BEEP ' here a beep is a good thing!
  61.         ELSEIF p.x < 0 OR p.x > xmax OR p.y > ymax THEN
  62.             p.active = 0
  63.         ELSEIF p.x > wallx1 AND p.x < wallx2 AND p.y > wallY THEN
  64.             p.active = 0
  65.         END IF
  66.         LOCATE 1, 1: PRINT "("; _TRIM$(STR$(p.x)); ", "; _TRIM$(STR$(p.y)); ")";
  67.         _DISPLAY
  68.         _LIMIT 60
  69.     WEND
  70.     _DELAY 3
  71.  
  72. SUB InitProjectile
  73.     DIM kh&, mx, my, mb
  74.     _TITLE "Use numbers 1 to 9, 0 for 10 for speed, click mouse when arrow at fire angle to fire."
  75.     p.x = 100
  76.     p.y = ymax - 100
  77.     p.active = 0
  78.     p.speed = 0
  79.     WHILE p.active = 0
  80.         DrawSpace 'CLS
  81.         Target
  82.         Arrow
  83.         kh& = _KEYHIT
  84.         IF kh& >= 48 AND kh& <= 57 THEN
  85.             IF kh& = 48 THEN p.speed = 10 ELSE p.speed = kh& - 48
  86.         END IF
  87.         WHILE _MOUSEINPUT: WEND
  88.         mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  89.         p.a = _ATAN2(my - p.y, mx - p.x)
  90.         IF p.a < 0 THEN p.a = p.a + 2 * pi
  91.         p.dx = p.speed * COS(p.a): p.dy = p.speed * SIN(p.a)
  92.         IF mb THEN
  93.             IF p.speed THEN p.active = -1 ELSE BEEP ' <<< you forgot to set a speed!
  94.         END IF
  95.         LOCATE 1, 1: PRINT "Angle:"; INT(360 - _R2D(p.a));
  96.         LOCATE 2, 1: PRINT "Speed:"; p.speed
  97.         _DISPLAY
  98.         _LIMIT 60
  99.     WEND
  100.  
  101. SUB InitTarget
  102.     t.r = 55 - 5 * level
  103.     wallY = RND * ymax * .5 + .25 * ymax
  104.     t.x = RND * (.25 * xmax - t.r) + .75 * xmax: t.y = RND * (ymax - 2 * t.r) + t.r
  105.  
  106. SUB DrawSpace
  107.     DIM y AS INTEGER
  108.     FOR y = 0 TO ymax
  109.         LINE (0, y)-STEP(xmax, 0), _RGB32(35, 0, 55 * y / ymax + 10), BF
  110.     NEXT
  111.     FOR y = 1 TO nStars
  112.         fcirc stars(y).x, stars(y).y, stars(y).r, &HFFDDEEFF
  113.     NEXT
  114.  
  115. SUB Target
  116.     fcirc t.x, t.y, t.r, &HFFCFCEA3
  117.     'draw wall blocking
  118.     LINE (wallx1, wallY)-(wallx2, ymax), &HFFAA6600, BF
  119.  
  120. SUB Arrow '  save these for other (x0, y0, rAngle, lngth)
  121.     DIM x0, y0, x1, y1, x2, y2, rAngle, lngth, i AS INTEGER
  122.     x0 = p.x: y0 = p.y: rAngle = p.a: lngth = lnth
  123.     x2 = x0 - lngth * COS(rAngle)
  124.     y2 = y0 - lngth * SIN(rAngle)
  125.     drawLink x0, y0, .001 * lngth, x2, y2, .01 * lngth, &HFFFFFFFF
  126.     LINE (x0, y0)-(x2, y2), &HFFFFFFFF
  127.     x2 = x0 - .1 * lngth * COS(rAngle - .2 * pi)
  128.     y2 = y0 - .1 * lngth * SIN(rAngle - .2 * pi)
  129.     x1 = x0 - .1 * lngth * COS(rAngle + .2 * pi)
  130.     y1 = y0 - .1 * lngth * SIN(rAngle + .2 * pi)
  131.     ftri x0, y0, x1, y1, x2, y2, &HFFFF0000
  132.     FOR i = .8 * lngth TO lngth STEP 3
  133.         x1 = x0 - i * COS(rAngle)
  134.         y1 = y0 - i * SIN(rAngle)
  135.         x2 = x1 - .1 * lngth * COS(rAngle - .25 * pi)
  136.         y2 = y1 - .1 * lngth * SIN(rAngle - .25 * pi)
  137.         LINE (x1, y1)-(x2, y2), &HFF0000FF
  138.         x2 = x1 - .1 * lngth * COS(rAngle + .25 * pi)
  139.         y2 = y1 - .1 * lngth * SIN(rAngle + .25 * pi)
  140.         LINE (x1, y1)-(x2, y2), &HFF0000FF
  141.     NEXT
  142.  
  143. SUB drawLink (x1, y1, r1, x2, y2, r2, c AS _UNSIGNED LONG)
  144.     DIM a, a1, a2, x3, x4, x5, x6, y3, y4, y5, y6
  145.     a = _ATAN2(y2 - y1, x2 - x1)
  146.     a1 = a + _PI(1 / 2)
  147.     a2 = a - _PI(1 / 2)
  148.     x3 = x1 + r1 * COS(a1): y3 = y1 + r1 * SIN(a1)
  149.     x4 = x1 + r1 * COS(a2): y4 = y1 + r1 * SIN(a2)
  150.     x5 = x2 + r2 * COS(a1): y5 = y2 + r2 * SIN(a1)
  151.     x6 = x2 + r2 * COS(a2): y6 = y2 + r2 * SIN(a2)
  152.     fquad x3, y3, x4, y4, x5, y5, x6, y6, c
  153.  
  154. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  155. SUB fquad (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER, x3 AS INTEGER, y3 AS INTEGER, x4 AS INTEGER, y4 AS INTEGER, c AS _UNSIGNED LONG)
  156.     ftri x1, y1, x2, y2, x4, y4, c
  157.     ftri x3, y3, x4, y4, x1, y1, c
  158.  
  159. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  160.     DIM a&
  161.     a& = _NEWIMAGE(1, 1, 32)
  162.     _DEST a&
  163.     PSET (0, 0), K
  164.     _DEST 0
  165.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  166.     _FREEIMAGE a& '<<< this is important!
  167.  
  168. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  169.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  170.     DIM X AS INTEGER, Y AS INTEGER
  171.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  172.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  173.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  174.     WHILE X > Y
  175.         RadiusError = RadiusError + Y * 2 + 1
  176.         IF RadiusError >= 0 THEN
  177.             IF X <> Y + 1 THEN
  178.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  179.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  180.             END IF
  181.             X = X - 1
  182.             RadiusError = RadiusError - X * 2
  183.         END IF
  184.         Y = Y + 1
  185.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  186.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  187.     WEND
  188.  
Title: Re: Artillery Wanted
Post by: johnno56 on June 24, 2019, 04:15:03 am
More misses than hits... But that's normal for me... lol

But, I did notice the subtle absence of aliens and or asteroids....
Title: Re: Artillery Wanted
Post by: SierraKen on June 24, 2019, 12:08:41 pm
Thanks for the idea Johno56. I added that to mine and also made it so the holes stay as you keep firing. Also last night I added random wind speed and it displays the amount up on top of the screen so you can try to calculate how to go with or against the wind.
Title: Re: Artillery Wanted
Post by: SierraKen on June 24, 2019, 12:12:16 pm
LOL B+ that kicks butt! That's professional right there. :) I got the Moon once. :) Good job!
Title: Re: Artillery Wanted
Post by: bplus on June 24, 2019, 12:24:04 pm
Thanks Ken, Johnno I find it more difficult than expected myself, the aliens are coming soon enough ;-))

Keep the holes! Great idea! Now maybe the moon wont be so full :D

I am working on a slider for speed settings so it's all mouse work: click, spin, click and we're off to the moon.

Maybe a cartoon rocket and moon would be good images. What should it sound like when you hit..., wait.. let's plant flags on the moon, wait... no wind ;-))
Title: Re: Artillery Wanted
Post by: SierraKen on June 24, 2019, 08:24:26 pm
I'm getting closer and closer to finishing it. :) You can play the computer now and the wind speed and direction shows up on top. Plus I made a little base on each side so you can see what you are actually blowing up. lol You win or the computer wins when you blow up the other person 5 times. Am still tweaking it some so it might be a couple days until I release it. Tomorrow I will be busy all day doing other things.
Title: Re: Artillery Wanted
Post by: SierraKen on June 25, 2019, 12:09:49 pm
I'm done with version 1. But first I'm trying to see if I can make a mountain or not, might take awhile if I can do it. lol
Title: Re: Artillery Wanted
Post by: SierraKen on June 25, 2019, 01:15:13 pm
Post erased by original poster.
Title: Re: Artillery Wanted
Post by: johnno56 on June 25, 2019, 05:28:51 pm
Cool...  I particularly like the way the wind speed and direction changes for each shot... Do you have any plans for further development?
Title: Re: Artillery Wanted
Post by: SierraKen on June 25, 2019, 08:08:10 pm
Thanks Johno56. At this moment I don't although later on I might think of something to add to it. I will post this to my website after B+ checks it out and I will put both names on the site. Actually 1 thing I will add is saying "5 Points Wins" somewhere so people know how long the game is. I think I'm going to make a splash screen (welcome screen) with the basic instructions with B+ and your name on it. I'll add the code in a few minutes to this forum.
Title: Re: Artillery Wanted
Post by: johnno56 on June 25, 2019, 09:21:39 pm
Thank you. But credit is not necessary. In the meantime, I will keep my eye open for upgrades... lol (No pressure, right?)
Title: Re: Artillery Wanted
Post by: SierraKen on June 25, 2019, 09:27:13 pm
LOL thanks Johnno56. Well, I did find some problems with the last one, for example, there wasn't explosions on the normal ground below older explosions, so I fixed that and a couple other things. I also added the welcome screen. Here is (possibly) the final version. I'll erase the code on my last post.
B+ what do you think of it? :) You helped me with most of the math code so I put your name on it.

Edit: Finding more problems.. will look this over more and then post. Sorry for any problems this caused.
Title: Re: Artillery Wanted
Post by: bplus on June 25, 2019, 10:19:08 pm
Hi Ken,

I wrote some code for making very very simple mountains:
Code: QB64: [Select]
  1. _TITLE " by bplus"
  2. 'QB64 v1.3
  3. CONST xmax = 1200
  4. CONST ymax = 700
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE (1280 - xmax) / 2 + 30, (760 - ymax) / 2
  7. COLOR , _RGB32(110, 110, 255)
  8.     CLS
  9.     MakeMountain xmax / 2, (ymax - 100) * .8, ymax - 100
  10.     _DELAY 2
  11.  
  12. SUB MakeMountain (xcenter, maxHeight, mountainbaseY)
  13.     centerDist = 15 * RND + 15
  14.     FOR i = 1 TO 5
  15.         IF RND < .5 THEN dir = -1 ELSE dir = 1
  16.         xc = xcenter + dir * centerDist
  17.         yc = maxHeight - centerDist - RND * 25
  18.         xl = xc - rrnd(1.25 * yc, yc)
  19.         xr = xc + rrnd(1.25 * yc, yc)
  20.         IF mountainbaseY - yc < mountainbaseY THEN
  21.             ftri xl, mountainbaseY, xc, mountainbaseY - yc, xr, mountainbaseY, _RGB32(110 - i * 4, RND * 20 + 100 - i * 2, 100 - i * 8)
  22.         ELSE
  23.             EXIT FOR
  24.         END IF
  25.         centerDist = centerDist + 40 * RND + 30
  26.     NEXT
  27.  
  28. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  29.     a& = _NEWIMAGE(1, 1, 32)
  30.     _DEST a&
  31.     PSET (0, 0), K
  32.     _DEST 0
  33.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  34.     _FREEIMAGE a& '<<< this is important!
  35. FUNCTION rrnd (n1, n2) 'return real number (_single, double, _float depending on default / define setup)
  36.     rrnd = (n2 - n1) * RND + n1
  37.  

I tried to install it into your game and ran into one thing after another so I am trying to overhaul it so I can understand it and not ruin that great AI shooter you have going!
Title: Re: Artillery Wanted
Post by: SierraKen 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).
Title: Re: Artillery Wanted
Post by: johnno56 on June 25, 2019, 11:48:02 pm
Cool... Two things missing.... Snow and a set of skis... lol
Title: Re: Artillery Wanted
Post by: johnno56 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
Title: Re: Artillery Wanted
Post by: SierraKen 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.
Title: Re: Artillery Wanted
Post by: bplus 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:
 


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? ;-))
Title: Re: Artillery Wanted
Post by: SierraKen 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.
Title: Re: Artillery Wanted
Post by: SierraKen 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.  
Title: Re: Artillery Wanted
Post by: johnno56 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
Title: Re: Artillery Wanted
Post by: SierraKen on June 26, 2019, 06:00:03 pm
LOL John! Wow, you got kinda unlucky on that game. hehe. Thanks for checking it out!
Title: Re: Artillery Wanted
Post by: johnno56 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!
Title: Re: Artillery Wanted
Post by: SierraKen on June 26, 2019, 10:57:19 pm
Thanks!
Title: Re: Artillery Wanted
Post by: Ashish on June 27, 2019, 01:49:16 am
Nice game!
Title: Re: Artillery Wanted
Post by: SierraKen on June 28, 2019, 11:34:10 am
Thanks Ashish! :)
Title: Re: Artillery Wanted
Post by: bplus 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?
 
Title: Re: Artillery Wanted
Post by: SierraKen 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.
Title: Re: Artillery Wanted
Post by: bplus on June 28, 2019, 03:15:43 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.

Ah! only for dirt? not the bases? not the hill? wait the hill is same as dirt for yours... OK. Come to think of it, I did see some tunneling through the bases. What stops tunneling is gravity's effect of pulling down harder making ball go farther that it's radius.

For help, I probably need some but not for the "tunneling" problem. :-))
I will just take a snap shot of screen before showing the new ball and clear screen between each loop with it.
OR do it like Tanks Battle, take a snapshot at start and then record all holes made by explosions, redraw screen at each loop and redraw all the holes in it. But it was really cool, to me, to see the ball cleared without having to clear the screen each loop.
Title: Re: Artillery Wanted
Post by: SierraKen on June 28, 2019, 08:54:45 pm
Yeah, only for dirt. The bases I use coordinate variables, just like my Wall Detection Example, only variables. I thought about it later how I could have used POINT instead but that's OK.
Title: Re: Artillery Wanted
Post by: johnno56 on June 29, 2019, 05:44:36 am
If memory serves correctly, in the original dos version of Scorched Earth, 'tunnelling'  was an 'option'... Tunnelling or not, I just enjoy blowing stuff up... Now, a nice addition, would be 'collapsible' landscape.... You know, blast a crater in the ground, then watch the sides of the crater slide towards the bottom of the crater... Just a though...

J
Title: Re: Artillery Wanted
Post by: bplus on July 02, 2019, 12:05:18 am
Well after one goofy setback after another, I finally got my MOD worked out. Computer is playing decent game.

Code: QB64: [Select]
  1.  
  2. 'Ken:
  3. 'I've always wanted to make this game ever since I started programming in the 80's.
  4. 'This was made using the BASIC and compile language QB64 from QB64.org
  5. 'This was created by Ken G. with much help from others below.
  6. 'Thank you to B+ for posting much of this math code on the QB64.org forum!
  7. 'Also thank you to johnno56 for a little help on the explosions, from the QB64.org forum.
  8. 'It takes the computer a little time to learn how to hit your base.
  9. 'Created on June 25, 2019.
  10.  
  11. 'Hi Ken, I made a couple of changes to the game. Do you recognize it :D  MOD 2019-07-01 B+
  12.  
  13. CONST xmax = 1200, ymax = 740
  14. _TITLE "Ken's Artillery MOD B+  Hey! They only have one cannon ball between the two of them :D" 'mod B+ makeover started 2019-06-25
  15. SCREEN _NEWIMAGE(xmax, ymax, 32)
  16.  
  17. TYPE ball
  18.     x AS SINGLE
  19.     y AS SINGLE
  20.     dx AS SINGLE
  21.     dy AS SINGLE
  22.  
  23. TYPE Contestent
  24.     baseX AS INTEGER 'butt end of cannon
  25.     baseY AS INTEGER
  26.     baseC AS _UNSIGNED LONG
  27.     cannonAngle AS SINGLE
  28.     velocity AS SINGLE
  29.     points AS INTEGER
  30.  
  31. CONST skyC = &HFF9988FF
  32. CONST ballC = &HFF000000
  33. CONST groundC = &HFF405020
  34. CONST cannonC = &HFF884422
  35. CONST printC = &HFFEEDDCC
  36. CONST groundY = 680
  37. CONST gravity = .05
  38. CONST cannonLength = 100
  39. CONST baseLength = 100
  40. CONST baseHeight = 30
  41. CONST ballRadius = 5
  42. DIM SHARED bg AS LONG, c AS Contestent, p AS Contestent, b AS ball, airX, turn, lastWind
  43.  
  44. bg = _NEWIMAGE(xmax, ymax, 32) 'get bg snap shot area ready
  45. COLOR printC, groundC
  46. setPlayerConstants
  47.     initGame
  48.     WHILE _KEYHIT <> 27 AND p.points <> 5 AND c.points <> 5
  49.         turn = (turn + 1) MOD 2
  50.         IF turn THEN PlayerFire ELSE ComputerFire
  51.     WEND
  52.     _DELAY 3
  53.  
  54. SUB setPlayerConstants
  55.     p.baseX = 10: c.baseX = xmax - 10
  56.     p.baseY = groundY - baseHeight: c.baseY = groundY - baseHeight
  57.     p.baseC = &HFF880000: c.baseC = &HFF000088
  58.     p.cannonAngle = _D2R(360 - 45)
  59.     p.velocity = 7
  60.  
  61. SUB initGame
  62.     p.points = 0: c.points = 0
  63.     MakeMountain xmax / 2, rrnd(200, (xmax - 220) / 2.3), ymax
  64.     LINE (0, groundY)-(xmax, ymax), groundC, BF 'ground
  65.     LINE (p.baseX, p.baseY)-STEP(baseLength, baseHeight), p.baseC, BF
  66.     LINE (c.baseX, c.baseY)-STEP(-baseLength, baseHeight), c.baseC, BF
  67.     SetDisplayWind
  68.     showScore
  69.  
  70. SUB PlayerFire
  71.     DIM kh AS LONG
  72.     p.cannonAngle = 360 - _R2D(p.cannonAngle)
  73.     'IF p.cannonAngle = 360 THEN p.cannonAngle = 0
  74.     LOCATE 44, 1: PRINT "Power: Left/Right   Angle: Up/Down   Fire: Spacebar";
  75.     LOCATE 45, 1: PRINT "Power (0-10): " + TS$(p.velocity);
  76.     LOCATE 46, 1: PRINT "Angle (0-90): " + TS$(p.cannonAngle);
  77.     _DISPLAY
  78.     WHILE kh <> 32
  79.         kh = _KEYHIT
  80.         IF kh = 18432 AND p.cannonAngle + 1 < 90 THEN p.cannonAngle = p.cannonAngle + 1
  81.         IF kh = 20480 AND p.cannonAngle - 1 > 0 THEN p.cannonAngle = p.cannonAngle - 1
  82.         IF kh = 19712 AND (p.velocity + .2 <= 10) THEN p.velocity = p.velocity + .2
  83.         IF kh = 19200 AND (p.velocity - .2 >= .2) THEN p.velocity = p.velocity - .2
  84.         LOCATE 45, 1: PRINT SPACE$(50);
  85.         LOCATE 46, 1: PRINT SPACE$(50);
  86.         LOCATE 45, 1: PRINT "Power (0-10): " + TS$(p.velocity);
  87.         LOCATE 46, 1: PRINT "Angle (0-90): " + TS$(p.cannonAngle);
  88.         _DISPLAY
  89.         _LIMIT 200
  90.     WEND
  91.     LOCATE 44, 1: PRINT SPACE$(60);
  92.     LOCATE 45, 1: PRINT SPACE$(50);
  93.     LOCATE 46, 1: PRINT SPACE$(50);
  94.     p.cannonAngle = _D2R(360 - p.cannonAngle)
  95.     drawCannon cannonC
  96.     b.x = p.baseX + baseLength * COS(p.cannonAngle)
  97.     b.y = p.baseY + baseLength * SIN(p.cannonAngle)
  98.     b.dx = p.velocity * COS(p.cannonAngle)
  99.     b.dy = p.velocity * SIN(p.cannonAngle)
  100.     _DISPLAY
  101.     _PUTIMAGE , 0, bg
  102.     playBall
  103.  
  104. SUB ComputerFire
  105.     IF airX <> lastWind THEN 'new wind blowing make adjustments
  106.         c.cannonAngle = _D2R(180 + 50 - 1000 * airX / 15)
  107.         c.velocity = 7 + 1000 * airX / 9
  108.         lastWind = airX
  109.     END IF
  110.     drawCannon cannonC
  111.     b.x = c.baseX + baseLength * COS(c.cannonAngle)
  112.     b.y = c.baseY + baseLength * SIN(c.cannonAngle)
  113.     b.dx = c.velocity * COS(c.cannonAngle)
  114.     b.dy = c.velocity * SIN(c.cannonAngle)
  115.     LOCATE 45, xmax / 8 - 10: PRINT TS$(c.velocity);
  116.     LOCATE 46, xmax / 8 - 10: PRINT TS$(_R2D(c.cannonAngle) - 180);
  117.     _DISPLAY
  118.     _PUTIMAGE , 0, bg
  119.     playBall
  120.     IF b.x - (p.baseX + .5 * baseLength) > 0 THEN
  121.         c.velocity = c.velocity + (b.x - p.baseX + .5 * baseLength) / 1000
  122.     ELSE
  123.         c.velocity = c.velocity - ((groundY - b.y) + (p.baseX + .5 * baseLength - b.x)) / 1000
  124.     END IF
  125.     LOCATE 45, xmax / 8 - 10: PRINT SPACE$(10);
  126.     LOCATE 46, xmax / 8 - 10: PRINT SPACE$(10);
  127.     _DISPLAY
  128.  
  129. SUB drawCannon (K AS _UNSIGNED LONG)
  130.     IF turn THEN 'players
  131.         LINE (p.baseX, p.baseY)-STEP(baseLength * COS(p.cannonAngle), baseLength * SIN(p.cannonAngle)), K
  132.     ELSE
  133.         LINE (c.baseX, c.baseY)-STEP(baseLength * COS(c.cannonAngle), baseLength * SIN(c.cannonAngle)), K
  134.     END IF
  135.  
  136. SUB playBall
  137.     DIM explosion
  138.     WHILE _KEYHIT <> 27
  139.         _PUTIMAGE , bg, 0 'clear last
  140.         b.dx = b.dx + airX
  141.         b.dy = b.dy + gravity
  142.         b.x = b.x + b.dx
  143.         b.y = b.y + b.dy
  144.         fcirc b.x, b.y, ballRadius, ballC 'draw new
  145.         CenterPrint 45, "                      "
  146.         CenterPrint 45, TS$(b.x) + ", " + TS$(b.y)
  147.         IF b.y >= 0 THEN
  148.             _SOURCE bg 'oh! need this to read point(x, y) off bg !!!!!!!!!1
  149.             IF POINT(b.x, b.y) <> skyC THEN 'explosions
  150.                 FOR explosion = 0 TO 14.5 STEP .25
  151.                     fcirc b.x, b.y, explosion, _RGB32(RND * 255, RND * 255, 0)
  152.                     SOUND 100 + explosion, .25
  153.                     _DISPLAY
  154.                     _DELAY .01
  155.                 NEXT
  156.                 IF POINT(b.x, b.y) = c.baseC THEN ' computer base hit
  157.                     p.points = p.points + 1
  158.                     showScore
  159.                     SOUND 500, 1: SOUND 550, 1: SOUND 600, 1: SOUND 650, 1: SOUND 700, 1
  160.                 ELSEIF POINT(b.x, b.y) = p.baseC THEN ' player base hit
  161.                     c.points = c.points + 1
  162.                     showScore
  163.                     SOUND 700, 1: SOUND 650, 1: SOUND 600, 1: SOUND 550, 1: SOUND 500, 1
  164.                 END IF
  165.                 fcirc b.x, b.y, 3 * ballRadius, skyC
  166.                 'take a snap of new background when ever we blow up
  167.                 CenterPrint 45, "                      "
  168.                 _DISPLAY
  169.                 _PUTIMAGE , 0, bg '<<<< use this after debug
  170.                 EXIT WHILE
  171.             END IF
  172.         END IF
  173.         _DISPLAY
  174.         _LIMIT 30
  175.     WEND
  176.     CenterPrint 45, "                      "
  177.     drawCannon skyC
  178.     _PUTIMAGE , 0, bg
  179.     'take a snap for next player
  180.  
  181. SUB showScore
  182.     DIM s$
  183.     s$ = "Human: " + TS$(p.points) + "  Computer: " + TS$(c.points)
  184.     IF p.points = 5 THEN s$ = s$ + "  YOU WIN!"
  185.     IF c.points = 5 THEN s$ = s$ + "  Computer won."
  186.     CenterPrint 46, s$
  187.     _DISPLAY
  188.  
  189. SUB SetDisplayWind
  190.     airX = rrnd(-20, 20)
  191.     CenterPrint 44, SPACE$(24)
  192.     IF airX < 0 THEN CenterPrint 44, "<<< Wind at: " + TS$(INT(10 * airX) / 10)
  193.     IF airX > 0 THEN CenterPrint 44, "Wind at: " + TS$(INT(10 * airX) / 10) + " >>>"
  194.     airX = airX / 1000
  195.     _DISPLAY
  196.  
  197. SUB MakeMountain (xcenter, maxHeight, mountainbaseY)
  198.     DIM centerDist, i, xc, yc, xl, xr, dir
  199.     LINE (0, 0)-(xmax + 50, ymax + 50), skyC, BF
  200.     centerDist = 15 * RND + 15
  201.     FOR i = 1 TO 5
  202.         IF RND < .5 THEN dir = -1 ELSE dir = 1
  203.         xc = xcenter + dir * centerDist
  204.         yc = maxHeight - centerDist - RND * 25
  205.         xl = xc - rrnd(1.15 * yc, yc)
  206.         xr = xc + rrnd(1.15 * yc, yc)
  207.         IF mountainbaseY - yc < mountainbaseY THEN
  208.             ftri xl, mountainbaseY, xc, mountainbaseY - yc, xr, mountainbaseY, _RGB32(110 - i * 4, RND * 20 + 100 - i * 2, 100 - i * 8)
  209.         ELSE
  210.             EXIT FOR
  211.         END IF
  212.         centerDist = centerDist + 40 * RND + 30
  213.     NEXT
  214.  
  215. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  216.     DIM a&
  217.     a& = _NEWIMAGE(1, 1, 32)
  218.     _DEST a&
  219.     PSET (0, 0), K
  220.     _DEST 0
  221.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  222.     _FREEIMAGE a& '<<< this is important!
  223.  
  224. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  225.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  226.     DIM X AS INTEGER, Y AS INTEGER
  227.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  228.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  229.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  230.     WHILE X > Y
  231.         RadiusError = RadiusError + Y * 2 + 1
  232.         IF RadiusError >= 0 THEN
  233.             IF X <> Y + 1 THEN
  234.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  235.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  236.             END IF
  237.             X = X - 1
  238.             RadiusError = RadiusError - X * 2
  239.         END IF
  240.         Y = Y + 1
  241.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  242.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  243.     WEND
  244.  
  245. FUNCTION rrnd (n1, n2) 'return real number between n1, n2
  246.     rrnd = (n2 - n1) * RND + n1
  247.  
  248. SUB CenterPrint (row, s$)
  249.     LOCATE row, .125 * (xmax - 8 * LEN(s$)) / 2: PRINT s$;
  250.  
  251. FUNCTION TS$ (n)
  252.     TS$ = _TRIM$(STR$(INT(n * 100 + .5) / 100)) 'I have to add .5 for rounding coreectly
  253.  

EDIT: a couple of minor tweaks 2019-07-02
Title: Re: Artillery Wanted
Post by: johnno56 on July 02, 2019, 08:25:03 am
The player needs to be crack shot if winning is the goal. Quite a marksman that enemy player!!
Title: Re: Artillery Wanted
Post by: bplus on July 02, 2019, 08:57:05 am
The player needs to be crack shot if winning is the goal. Quite a marksman that enemy player!!

Yes, you will fall asleep if the enemy doesn't keep you on your toes! Once you get a feel for the shots, it's a pretty even game, it alternate's who goes first after a win.
Title: Re: Artillery Wanted
Post by: johnno56 on July 02, 2019, 05:24:15 pm
Sooo.... There is a good chance I can be beaten? Hmm... I have an idea for an invulnerability power-up... Activate the ability at 'start up'.... that's it... lol
Title: Re: Artillery Wanted
Post by: Pete on July 03, 2019, 04:10:57 pm
Great sound effects. Nice that the mountain size changes each round. I wish the wind would change during the round. Also, there needs to be a display for the power and the angle as they are changed. The AI needs some work, as it constantly attacks the same hole it makes.

Pete
Title: Re: Artillery Wanted
Post by: bplus on July 03, 2019, 04:56:09 pm
Great sound effects. Nice that the mountain size changes each round. I wish the wind would change during the round. Also, there needs to be a display for the power and the angle as they are changed. The AI needs some work, as it constantly attacks the same hole it makes.

Pete

Hi Pete,

If you are commenting on my MOD (which does have the mountains), the power and angle are displayed and changed with the arrow keys by the human player. (Power and angle displayed when computer is firing but not labeled.)

You are right about AI locking in on Power and Angle setting. I never noticed that happening when testing but sure enough it happened the first time I reviewed it. That's easy enough to fix!

Changing wind? That sucks when you are developing AI, but sure when does wind ever stay exactly the same?
Again easy fix, that would actually fix the other problem of AI locked in a Power and Angle setting, the wind would force change. Good! 2 birds, one stone, I will just change the wind... and label Computer's Power and Angle display.


Title: Re: Artillery Wanted
Post by: bplus on July 04, 2019, 01:57:27 pm
OK Pete's recommendations adapted, I kind of like the change in the way wind is handled in this MOD:
Code: QB64: [Select]
  1.  
  2. 'Ken:
  3. 'I've always wanted to make this game ever since I started programming in the 80's.
  4. 'This was made using the BASIC and compile language QB64 from QB64.org
  5. 'This was created by Ken G. with much help from others below.
  6. 'Thank you to B+ for posting much of this math code on the QB64.org forum!
  7. 'Also thank you to johnno56 for a little help on the explosions, from the QB64.org forum.
  8. 'It takes the computer a little time to learn how to hit your base.
  9. 'Created on June 25, 2019.
  10.  
  11. 'Hi Ken, I made a couple of changes to the game. Do you recognize it :D  MOD 2019-07-01 B+
  12. ' 2019-07-03 fix items mentioned by Pete label Computer Power and Angle display, apply constant wind change.
  13.  
  14. CONST xmax = 1200, ymax = 740
  15. _TITLE "Ken's Artillery MOD B+  Hey! They only have one cannon ball between the two of them :D" 'mod B+ makeover started 2019-06-25
  16. SCREEN _NEWIMAGE(xmax, ymax, 32)
  17.  
  18. TYPE ball
  19.     x AS SINGLE
  20.     y AS SINGLE
  21.     dx AS SINGLE
  22.     dy AS SINGLE
  23.  
  24. TYPE Contestent
  25.     baseX AS INTEGER 'butt end of cannon
  26.     baseY AS INTEGER
  27.     baseC AS _UNSIGNED LONG
  28.     cannonAngle AS SINGLE
  29.     velocity AS SINGLE
  30.     points AS INTEGER
  31.  
  32. CONST skyC = &HFF9988FF
  33. CONST ballC = &HFF000000
  34. CONST groundC = &HFF405020
  35. CONST cannonC = &HFF884422
  36. CONST printC = &HFFEEDDCC
  37. CONST groundY = 680
  38. CONST gravity = .05
  39. CONST cannonLength = 100
  40. CONST baseLength = 100
  41. CONST baseHeight = 30
  42. CONST ballRadius = 5
  43. DIM SHARED bg AS LONG, c AS Contestent, p AS Contestent, b AS ball, airX, turn, lastWind
  44.  
  45. bg = _NEWIMAGE(xmax, ymax, 32) 'get bg snap shot area ready
  46. COLOR printC, groundC
  47. setPlayerConstants
  48.     initGame
  49.     WHILE _KEYHIT <> 27 AND p.points <> 5 AND c.points <> 5
  50.         SetDisplayWind
  51.         turn = (turn + 1) MOD 2
  52.         IF turn THEN PlayerFire ELSE ComputerFire
  53.     WEND
  54.     _DELAY 3
  55.  
  56. SUB setPlayerConstants
  57.     p.baseX = 10: c.baseX = xmax - 10
  58.     p.baseY = groundY - baseHeight: c.baseY = groundY - baseHeight
  59.     p.baseC = &HFF880000: c.baseC = &HFF000088
  60.     p.cannonAngle = _D2R(360 - 45)
  61.     p.velocity = 7
  62.  
  63. SUB initGame
  64.     p.points = 0: c.points = 0
  65.     MakeMountain xmax / 2, rrnd(200, (xmax - 220) / 2.3), ymax
  66.     LINE (0, groundY)-(xmax, ymax), groundC, BF 'ground
  67.     LINE (p.baseX, p.baseY)-STEP(baseLength, baseHeight), p.baseC, BF
  68.     LINE (c.baseX, c.baseY)-STEP(-baseLength, baseHeight), c.baseC, BF
  69.     airX = rrnd(-20, 20)
  70.     SetDisplayWind
  71.     showScore
  72.  
  73. SUB PlayerFire
  74.     DIM kh AS LONG
  75.     p.cannonAngle = 360 - _R2D(p.cannonAngle)
  76.     'IF p.cannonAngle = 360 THEN p.cannonAngle = 0
  77.     LOCATE 44, 1: PRINT "Power: Left/Right   Angle: Up/Down   Fire: Spacebar";
  78.     LOCATE 45, 10: PRINT "Power (0-10): " + TS$(p.velocity);
  79.     LOCATE 46, 10: PRINT "Angle (0-90): " + TS$(p.cannonAngle);
  80.     _DISPLAY
  81.     WHILE kh <> 32
  82.         kh = _KEYHIT
  83.         IF kh = 18432 AND p.cannonAngle + 1 < 90 THEN p.cannonAngle = p.cannonAngle + 1
  84.         IF kh = 20480 AND p.cannonAngle - 1 > 0 THEN p.cannonAngle = p.cannonAngle - 1
  85.         IF kh = 19712 AND (p.velocity + .2 <= 10) THEN p.velocity = p.velocity + .2
  86.         IF kh = 19200 AND (p.velocity - .2 >= .2) THEN p.velocity = p.velocity - .2
  87.         LOCATE 45, 10: PRINT SPACE$(25);
  88.         LOCATE 46, 10: PRINT SPACE$(25);
  89.         LOCATE 45, 10: PRINT "Power (0-10): " + TS$(p.velocity);
  90.         LOCATE 46, 10: PRINT "Angle (0-90): " + TS$(p.cannonAngle);
  91.         _DISPLAY
  92.         _LIMIT 200
  93.     WEND
  94.     LOCATE 44, 1: PRINT SPACE$(55);
  95.     LOCATE 45, 10: PRINT SPACE$(25);
  96.     LOCATE 46, 10: PRINT SPACE$(25);
  97.     p.cannonAngle = _D2R(360 - p.cannonAngle)
  98.     drawCannon cannonC
  99.     b.x = p.baseX + baseLength * COS(p.cannonAngle)
  100.     b.y = p.baseY + baseLength * SIN(p.cannonAngle)
  101.     b.dx = p.velocity * COS(p.cannonAngle)
  102.     b.dy = p.velocity * SIN(p.cannonAngle)
  103.     _DISPLAY
  104.     _PUTIMAGE , 0, bg
  105.     playBall
  106.  
  107. SUB ComputerFire
  108.     IF ABS(airX - lastWind) > 2 OR c.cannonAngle <= _D2R(5 + 180) THEN 'new game or wind
  109.         c.cannonAngle = _D2R(180 + 50 - airX / 7)
  110.         c.velocity = 7.2 + airX / 10
  111.         lastWind = airX
  112.     END IF
  113.     drawCannon cannonC
  114.     b.x = c.baseX + baseLength * COS(c.cannonAngle)
  115.     b.y = c.baseY + baseLength * SIN(c.cannonAngle)
  116.     b.dx = c.velocity * COS(c.cannonAngle)
  117.     b.dy = c.velocity * SIN(c.cannonAngle)
  118.     LOCATE 45, xmax / 8 - 25: PRINT "Power: " + TS$(c.velocity);
  119.     LOCATE 46, xmax / 8 - 25: PRINT "Angle: " + TS$(_R2D(c.cannonAngle) - 180);
  120.     _DISPLAY
  121.     _PUTIMAGE , 0, bg
  122.     playBall
  123.     IF b.x - (p.baseX + .5 * baseLength) > 0 THEN
  124.         c.velocity = c.velocity + (b.x - p.baseX + .5 * baseLength) / 1000
  125.     ELSE
  126.         c.velocity = c.velocity - ((groundY - b.y) + (p.baseX + .5 * baseLength - b.x)) / 1000
  127.     END IF
  128.     LOCATE 45, xmax / 8 - 25: PRINT SPACE$(25);
  129.     LOCATE 46, xmax / 8 - 25: PRINT SPACE$(25);
  130.     _DISPLAY
  131.  
  132. SUB drawCannon (K AS _UNSIGNED LONG)
  133.     IF turn THEN 'players
  134.         LINE (p.baseX, p.baseY)-STEP(baseLength * COS(p.cannonAngle), baseLength * SIN(p.cannonAngle)), K
  135.     ELSE
  136.         LINE (c.baseX, c.baseY)-STEP(baseLength * COS(c.cannonAngle), baseLength * SIN(c.cannonAngle)), K
  137.     END IF
  138.  
  139. SUB playBall
  140.     DIM explosion
  141.     WHILE _KEYHIT <> 27
  142.         _PUTIMAGE , bg, 0 'clear last
  143.         b.dx = b.dx + airX / 1000
  144.         b.dy = b.dy + gravity
  145.         b.x = b.x + b.dx
  146.         b.y = b.y + b.dy
  147.         fcirc b.x, b.y, ballRadius, ballC 'draw new
  148.         CenterPrint 45, "                      "
  149.         CenterPrint 45, TS$(b.x) + ", " + TS$(b.y)
  150.         IF b.y >= 0 THEN
  151.             _SOURCE bg 'oh! need this to read point(x, y) off bg !!!!!!!!!1
  152.             IF POINT(b.x, b.y) <> skyC THEN 'explosions
  153.                 FOR explosion = 0 TO 14.5 STEP .25
  154.                     fcirc b.x, b.y, explosion, _RGB32(RND * 255, RND * 255, 0)
  155.                     SOUND 100 + explosion, .25
  156.                     _DISPLAY
  157.                     _DELAY .01
  158.                 NEXT
  159.                 IF POINT(b.x, b.y) = c.baseC THEN ' computer base hit
  160.                     p.points = p.points + 1
  161.                     showScore
  162.                     SOUND 500, 1: SOUND 550, 1: SOUND 600, 1: SOUND 650, 1: SOUND 700, 1
  163.                 ELSEIF POINT(b.x, b.y) = p.baseC THEN ' player base hit
  164.                     c.points = c.points + 1
  165.                     showScore
  166.                     SOUND 700, 1: SOUND 650, 1: SOUND 600, 1: SOUND 550, 1: SOUND 500, 1
  167.                 END IF
  168.                 fcirc b.x, b.y, 3 * ballRadius, skyC
  169.                 'take a snap of new background when ever we blow up
  170.                 CenterPrint 45, "                      "
  171.                 _DISPLAY
  172.                 _PUTIMAGE , 0, bg '<<<< use this after debug
  173.                 EXIT WHILE
  174.             END IF
  175.         END IF
  176.         _DISPLAY
  177.         _LIMIT 30
  178.     WEND
  179.     CenterPrint 45, "                      "
  180.     drawCannon skyC
  181.     _PUTIMAGE , 0, bg
  182.  
  183. SUB showScore
  184.     DIM s$
  185.     s$ = "Human: " + TS$(p.points) + "  Computer: " + TS$(c.points)
  186.     IF p.points = 5 THEN s$ = s$ + "  YOU WIN!"
  187.     IF c.points = 5 THEN s$ = s$ + "  Computer won."
  188.     CenterPrint 46, s$
  189.     _DISPLAY
  190.  
  191. SUB SetDisplayWind
  192.     airX = airX + rrnd(-1.5, 1.5)
  193.     IF airX < -20 THEN airX = -19.99
  194.     IF airX > 20 THEN airX = 19.99
  195.     CenterPrint 44, SPACE$(24)
  196.     IF airX < 0 THEN CenterPrint 44, "<<< Wind at: " + TS$(airX)
  197.     IF airX > 0 THEN CenterPrint 44, "Wind at: " + TS$(airX) + " >>>"
  198.     _DISPLAY
  199.  
  200. SUB MakeMountain (xcenter, maxHeight, mountainbaseY)
  201.     DIM centerDist, i, xc, yc, xl, xr, dir
  202.     LINE (0, 0)-(xmax + 50, ymax + 50), skyC, BF
  203.     centerDist = 15 * RND + 15
  204.     FOR i = 1 TO 5
  205.         IF RND < .5 THEN dir = -1 ELSE dir = 1
  206.         xc = xcenter + dir * centerDist: yc = maxHeight - centerDist - RND * 25
  207.         xl = xc - rrnd(1.15 * yc, yc): xr = xc + rrnd(1.15 * yc, yc)
  208.         IF mountainbaseY - yc < mountainbaseY THEN
  209.             ftri xl, mountainbaseY, xc, mountainbaseY - yc, xr, mountainbaseY, _RGB32(110 - i * 4, RND * 20 + 100 - i * 2, 100 - i * 8)
  210.         ELSE
  211.             EXIT FOR
  212.         END IF
  213.         centerDist = centerDist + 40 * RND + 30
  214.     NEXT
  215.  
  216. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  217.     DIM a&
  218.     a& = _NEWIMAGE(1, 1, 32)
  219.     _DEST a&
  220.     PSET (0, 0), K
  221.     _DEST 0
  222.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  223.     _FREEIMAGE a& '<<< this is important!
  224.  
  225. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  226.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  227.     DIM X AS INTEGER, Y AS INTEGER
  228.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  229.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  230.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  231.     WHILE X > Y
  232.         RadiusError = RadiusError + Y * 2 + 1
  233.         IF RadiusError >= 0 THEN
  234.             IF X <> Y + 1 THEN
  235.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  236.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  237.             END IF
  238.             X = X - 1
  239.             RadiusError = RadiusError - X * 2
  240.         END IF
  241.         Y = Y + 1
  242.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  243.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  244.     WEND
  245.  
  246. FUNCTION rrnd (n1, n2) 'return real number between n1, n2
  247.     rrnd = (n2 - n1) * RND + n1
  248.  
  249. SUB CenterPrint (row, s$)
  250.     LOCATE row, .125 * (xmax - 8 * LEN(s$)) / 2: PRINT s$;
  251.  
  252. FUNCTION TS$ (n)
  253.     TS$ = _TRIM$(STR$(INT(n * 100 + .5) / 100)) 'I have to add .5 for rounding coreectly
  254.  
Title: Re: Artillery Wanted
Post by: Pete on July 04, 2019, 02:22:47 pm
The AI is much better now! I won a couple, and lost a couple. Nice job!

Pete