Author Topic: Cave Fighter - Side Scrolling Action Game  (Read 7428 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #15 on: November 11, 2020, 03:14:30 pm »
Awesome, I will have to experiment with them. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #16 on: November 11, 2020, 03:53:21 pm »
The most obvious one to start using is fcirc which you can rename FillCircle or CircleFill.... that's an advantage to these SUBs and FUNCTIONs because you load them in yourself or create them, you can name them as you please.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #17 on: November 11, 2020, 04:24:59 pm »
That was SO COOL! I just used your FillCircle Sub and made a large bright green circle. It feels almost like learning BASIC again back in the 80's. LOL
I also made a new folder called - SUB EXAMPLES that I can go to easily from now on. :))

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. x = 400: y = 300: r = 100
  3. c = _RGB32(0, 255, 0)
  4.  
  5. fillcircle x, y, r, c
  6.  
  7.  
  8. SUB fillcircle (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG) 'vince version  fill circle x, y, radius, color
  9.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  10.     x0 = R: y0 = 0: e = 0
  11.     DO WHILE y0 < x0
  12.         IF e <= 0 THEN
  13.             y0 = y0 + 1
  14.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  15.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  16.             e = e + 2 * y0
  17.         ELSE
  18.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  19.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  20.             x0 = x0 - 1: e = e - 2 * x0
  21.         END IF
  22.     LOOP
  23.     LINE (x - R, y)-(x + R, y), C, BF
  24.  

FellippeHeitor

  • Guest
Re: Cave Fighter - Side Scrolling Action Game
« Reply #18 on: November 11, 2020, 05:15:37 pm »
Very good idea for a game using the map technique, Ken!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #19 on: November 11, 2020, 05:18:43 pm »
Thanks Felippe!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #20 on: November 11, 2020, 07:22:36 pm »
I noticed something odd using _vince version of circle fill, tiny white crosses were appearing on spheres whereas the Steve Gold Standard does not have them.

Check it out: I put an s before the Steve Gold Standard circle to test the vince version result: little white crosses on the spheres whereas put a v on vince version and remove the s on the Steve Gold Standard version result: no crosses.

Code: QB64: [Select]
  1. _TITLE "Plasma Laser Cannon demo" 'b+ 2020-11-11
  2. SCREEN _NEWIMAGE(1024, 700, 32)
  3. _DELAY .25
  4.  
  5. DIM SHARED tx, ty, tr, tc AS _UNSIGNED LONG
  6. newTarget
  7.     CLS
  8.     PRINT tx, ty, tr, tc
  9.     drawBall tx, ty, tr, tc
  10.     WHILE _MOUSEINPUT: WEND 'aim with mouse
  11.     mx = _MOUSEX: my = _MOUSEY: mb = _MOUSEBUTTON(1)
  12.     IF mb THEN
  13.         PLC _WIDTH / 2, _HEIGHT / 2, _MOUSEX, _MOUSEY, tr
  14.         drawShip _WIDTH / 2, _HEIGHT / 2, &HFF66FF88
  15.         _DISPLAY
  16.     ELSE
  17.         drawShip _WIDTH / 2, _HEIGHT / 2, &HFF66FF88
  18.     END IF
  19.     IF _HYPOT(mx - tx, my - ty) < tr AND mb THEN
  20.         FOR r = 0 TO 255
  21.             fcirc tx, ty, r, _RGBA32(255, 255 - r, 0, 10)
  22.             _DISPLAY
  23.             _LIMIT 400
  24.         NEXT
  25.         newTarget
  26.     END IF
  27.     IF INKEY$ = " " THEN newTarget
  28.     _DISPLAY
  29.     _LIMIT 60
  30.  
  31. SUB newTarget
  32.     IF RND < .5 THEN
  33.         IF RND < .5 THEN tx = RND * 200 + 50 ELSE tx = _WIDTH - 250 + RND * 200
  34.         ty = RND * (_HEIGHT - 100) + 50
  35.     ELSE
  36.         IF RND < .5 THEN ty = RND * 200 + 50 ELSE ty = _HEIGHT - 250 + RND * 100
  37.         tx = RND * (_WIDTH - 100) + 50
  38.     END IF
  39.     tr = RND * 50 + 20
  40.     tc = _RGB32(60 + RND * 195, RND * 255, RND * 255)
  41.  
  42. SUB PLC (baseX, baseY, targetX, targetY, targetR) ' PLC for PlasmaLaserCannon
  43.     r = RND ^ 2 * RND: g = RND ^ 2 * RND: b = RND ^ 2 * RND: hp = _PI(.5) ' red, green, blue, half pi
  44.     ta = _ATAN2(targetY - baseY, targetX - baseX) ' angle of target to cannon base
  45.     dist = _HYPOT(targetY - baseY, targetX - baseX) ' distance cannon to target
  46.     dr = targetR / dist
  47.     FOR r = 0 TO dist STEP .25
  48.         x = baseX + r * COS(ta)
  49.         y = baseY + r * SIN(ta)
  50.         c = c + .3
  51.         fcirc x, y, dr * r, _RGB32(128 + 127 * SIN(r * c), 128 + 127 * SIN(g * c), 128 + 127 * SIN(b * c))
  52.     NEXT
  53.     FOR rr = dr * r TO 0 STEP -.5
  54.         c = c + 1
  55.         fcirc x, y, rr, _RGB32(128 + 127 * SIN(r * c), 128 + 127 * SIN(g * c), 128 + 127 * SIN(b * c))
  56.     NEXT
  57.  
  58. SUB drawBall (x, y, r, c AS _UNSIGNED LONG)
  59.     DIM rred AS LONG, grn AS LONG, blu AS LONG, rr AS LONG, f
  60.     rred = _RED32(c): grn = _GREEN32(c): blu = _BLUE32(c)
  61.     FOR rr = r TO 0 STEP -1
  62.         f = 1 - rr / r
  63.         fcirc x, y, rr, _RGB32(rred * f, grn * f, blu * f)
  64.     NEXT
  65.  
  66. SUB drawShip (x, y, colr AS _UNSIGNED LONG) 'shipType     collisions same as circle x, y radius = 30
  67.     STATIC ls
  68.     DIM light AS LONG, r AS LONG, g AS LONG, b AS LONG
  69.     r = _RED32(colr): g = _GREEN32(colr): b = _BLUE32(colr)
  70.     fellipse x, y, 6, 15, _RGB32(r, g - 120, b - 100)
  71.     fellipse x, y, 18, 11, _RGB32(r, g - 60, b - 50)
  72.     fellipse x, y, 30, 7, _RGB32(r, g, b)
  73.     FOR light = 0 TO 5
  74.         fcirc x - 30 + 11 * light + ls, y, 1, _RGB32(ls * 50, ls * 50, ls * 50)
  75.     NEXT
  76.     ls = ls + 1
  77.     IF ls > 5 THEN ls = 0
  78.  
  79. SUB fellipse (CX AS LONG, CY AS LONG, xr AS LONG, yr AS LONG, C AS _UNSIGNED LONG)
  80.     IF xr = 0 OR yr = 0 THEN EXIT SUB
  81.     DIM x AS LONG, y AS LONG
  82.     w2 = xr * xr: h2 = yr * yr: h2w2 = h2 * w2
  83.     LINE (CX - xr, CY)-(CX + xr, CY), C, BF
  84.     DO WHILE y < yr
  85.         y = y + 1
  86.         x = SQR((h2w2 - y * y * w2) \ h2)
  87.         LINE (CX - x, CY + y)-(CX + x, CY + y), C, BF
  88.         LINE (CX - x, CY - y)-(CX + x, CY - y), C, BF
  89.     LOOP
  90.  
  91. 'vince version  fill circle x, y, radius, color
  92. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  93.     DIM x0 AS LONG, y0 AS LONG, e AS LONG
  94.     x0 = R: y0 = 0: e = 0
  95.     DO WHILE y0 < x0
  96.         IF e <= 0 THEN
  97.             y0 = y0 + 1
  98.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  99.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  100.             e = e + 2 * y0
  101.         ELSE
  102.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  103.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  104.             x0 = x0 - 1: e = e - 2 * x0
  105.         END IF
  106.     LOOP
  107.     LINE (x - R, y)-(x + R, y), C, BF
  108.  
  109. 'from Steve Gold standard
  110. SUB sfcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  111.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  112.     DIM X AS INTEGER, Y AS INTEGER
  113.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  114.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  115.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  116.     WHILE X > Y
  117.         RadiusError = RadiusError + Y * 2 + 1
  118.         IF RadiusError >= 0 THEN
  119.             IF X <> Y + 1 THEN
  120.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  121.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  122.             END IF
  123.             X = X - 1
  124.             RadiusError = RadiusError - X * 2
  125.         END IF
  126.         Y = Y + 1
  127.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  128.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  129.     WEND
  130.  
  131.  
  132.  

Smaller green spheres easiest to see:
 
Sphere with cross.PNG

« Last Edit: November 11, 2020, 07:23:45 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #21 on: November 13, 2020, 11:27:28 am »
@SierraKen  just saying if you are going to use Fill Circle SUB to use the Steve Gold Standard (I think the name came from vince.) I am wondering how vince version got into my code but at least now I know now why Steves is slightly better.

BTW I did a time test between Steve's version doing INTEGERs and then doing LONG. He mentioned earlier when we were discussing DIM versus REDIM that LONG were faster than INTEGERs. I did not find much difference with INTEGERs edging out LONGs more significantly when x, y were integers too; the reverse case not so much.

To be perfectly explicit use this for FILL CIRCLE:
Code: QB64: [Select]
  1. 'from Steve Gold standard
  2. SUB fillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  3.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  4.     DIM X AS INTEGER, Y AS INTEGER
  5.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  6.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  7.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  8.     WHILE X > Y
  9.         RadiusError = RadiusError + Y * 2 + 1
  10.         IF RadiusError >= 0 THEN
  11.             IF X <> Y + 1 THEN
  12.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  13.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  14.             END IF
  15.             X = X - 1
  16.             RadiusError = RadiusError - X * 2
  17.         END IF
  18.         Y = Y + 1
  19.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  20.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  21.     WEND
  22.  
  23.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #22 on: November 13, 2020, 02:30:51 pm »
Thanks B+, I deleted the old one and put this one in its place.

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #23 on: November 14, 2020, 04:52:12 am »
Uff i cannot compile this one with my 1.3qb64_32bit win7
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

FellippeHeitor

  • Guest
Re: Cave Fighter - Side Scrolling Action Game
« Reply #24 on: November 14, 2020, 10:39:09 am »
Time to update, Aurel.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #25 on: November 15, 2020, 12:03:41 am »
bplus,

Just for "the fun of it"... I removed the boxfill from all the line() statements... and it still drew a complete disc....
Does it do it on 'your' screen? If it still draws a disc then is there a purpose for the boxfill? Just curious...
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Cave Fighter - Side Scrolling Action Game
« Reply #26 on: November 15, 2020, 01:34:12 am »
bplus,

Just for "the fun of it"... I removed the boxfill from all the line() statements... and it still drew a complete disc....
Does it do it on 'your' screen? If it still draws a disc then is there a purpose for the boxfill? Just curious...

Run some speed tests sometime: BF is faster than just drawing a line without it.  (It’s from the way BF is optimized in our c-translated code, and a line, by itself, isn’t.)

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Aurel

  • Forum Regular
  • Posts: 167
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #27 on: November 15, 2020, 03:40:37 am »
Quote
Time to update, Aurel.

yes that is ok,,but i suspect that is something else too
well other programs by Sierra worked?
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #28 on: November 15, 2020, 11:43:31 am »
yes that is ok,,but i suspect that is something else too
well other programs by Sierra worked?

@Aurel What is the error message?

Are you Saving EXE in same folder as Source in your IDE Run Menu?
« Last Edit: November 15, 2020, 11:52:15 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Cave Fighter - Side Scrolling Action Game
« Reply #29 on: November 15, 2020, 02:04:11 pm »
Aurel, also make sure all of the files are in the same directory, I suggest its own directory.