Author Topic: Artillery Wanted  (Read 23156 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #15 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. :)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #16 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.  
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Artillery Wanted
« Reply #17 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.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #18 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....
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #19 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.
« Last Edit: June 24, 2019, 12:15:23 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #20 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!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Artillery Wanted
« Reply #21 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 ;-))

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #22 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.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #23 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
« Last Edit: June 25, 2019, 12:48:28 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #24 on: June 25, 2019, 01:15:13 pm »
Post erased by original poster.
« Last Edit: June 25, 2019, 09:28:46 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #25 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?
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #26 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.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Artillery Wanted
« Reply #27 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?)
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Artillery Wanted
« Reply #28 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.
« Last Edit: June 25, 2019, 09:50:54 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Artillery Wanted
« Reply #29 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!