Author Topic: collision questions and hard work  (Read 6383 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
Re: collision questions and hard work
« Reply #15 on: February 26, 2020, 09:07:09 pm »
Oh, bplus. How will you get an a+ with this subpar work that doesn't meet the criteria? You better up your game man.

FellippeHeitor

  • Guest
Re: collision questions and hard work
« Reply #16 on: February 26, 2020, 09:08:39 pm »
that was a good code, and the link's code was amazing! but i meant a image, y'know, a bmp file containing a gray spike on it.

Stop requesting code. Present your work so people can help debug and/or improve or, if you have nothing, try to have something first.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: collision questions and hard work
« Reply #17 on: February 26, 2020, 09:10:46 pm »
Oh, bplus. How will you get an a+ with this subpar work that doesn't meet the criteria? You better up your game man.

He is pretty demanding isn't he?

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: collision questions and hard work
« Reply #18 on: March 01, 2020, 08:22:10 pm »
Code: QB64: [Select]
  1.  
  2. spike& = _LOADIMAGE("spikeup.bmp")
  3.  
  4. xs = (RND * _WIDTH - 10): ys = (RND * _HEIGHT - 10)
  5.  
  6.     _PUTIMAGE (xs, ys), spike&
  7.  
  8.  

after that, simply asked to myself: what now?
« Last Edit: March 01, 2020, 08:24:22 pm by codevsb12 »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: collision questions and hard work
« Reply #19 on: March 01, 2020, 08:39:34 pm »
Stop requesting code. Present your work so people can help debug and/or improve or, if you have nothing, try to have something first.

With all due respect, you call this "trying something"?

Code: QB64: [Select]
  1. spike& = _LOADIMAGE("spikeup.bmp")
  2.  
  3. xs = (RND * _WIDTH - 10): ys = (RND * _HEIGHT - 10)
  4.  
  5.     _PUTIMAGE (xs, ys), spike&

..... right after bplus GAVE you the answer? Scroll up man.
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: collision questions and hard work
« Reply #20 on: March 01, 2020, 10:05:12 pm »
Where ever you can put a rectangle, you can put an image and you can do 90 degree rotations maybe better than _maptriangle  until you need rotations like 30 degrees.

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: collision questions and hard work
« Reply #21 on: March 02, 2020, 07:30:57 pm »
alright, first: now THIS was trying something
Code: QB64: [Select]
  1. SUB rotation (xt, yt, x1, y1, x2, y2, x3, y3, sp)
  2.  
  3.     IF xt < _WIDTH / 2 THEN xt = 10
  4.     IF xt > _WIDTH / 2 THEN xt = _WIDTH - 30
  5.     IF yt < _HEIGHT / 2 THEN yt = (RND * _HEIGHT / 2)
  6.     IF yt > _HEIGHT / 2 THEN yt = _HEIGHT - 30
  7.     IF yt = 10 THEN _MAPTRIANGLE _SEAMLESS(xt, yt)-(xt, yt)-(xt, yt), sp TO(x1, y1)-(x2, y2)-(x3, y3)
  8.  
  9.  

second: is there any statement  that can replace _maptriangle in case of 90 degrees rotation? cuz i'm sure there is not, even thought its qB A S I C

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: collision questions and hard work
« Reply #22 on: March 02, 2020, 07:34:41 pm »
You're correct in that there is no way to rotate an underscore command by 90 degrees in any meaningful direction - so there's not a statement that does this. What you're surely needing to do is rotate the coordinates themselves, and then throw the rotated coordinates back into maptriangle to make a rotated picture.

Before understanding rotations, do you know how to say, reflect your image about the horizontal or vertical direction?
You're not done when it works, you're done when it's right.

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: collision questions and hard work
« Reply #23 on: March 02, 2020, 07:55:49 pm »
well, no. but actually yes. you guys taught me about how to flip my sprite using _PUTIMAGE.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: collision questions and hard work
« Reply #24 on: March 02, 2020, 08:04:08 pm »
Okay, cool - so a quick review.

To flip an image about the vertical axis, you might let all x-points just become negative x, as in: x -> -x

Similarly to flip an image along the horizontal axis, you would have y -> -y.

Of course, you can do both, etc. etc. - and this is what paint lets you do with one click basically.

... So rotations are a little bit harder, and involve changing coordinates like reflections. Now, for maptriangle, you have to feed it three points. I don't want to confuse things, so we'd better stick to rotating one point. To finish the job we will apply the methods of one point to all three and boom, you're rotating the whole triangle.

Unfortunately, there are three ways to get you into rotations: (i) vectors, (ii) trig functions, (iii) butcher a working example. While various people will see this post and probably get right to work on (iii) (or I will later if nobody does)... how is your proficiency with (i) and (ii)?

« Last Edit: March 02, 2020, 08:05:11 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
Re: collision questions and hard work
« Reply #25 on: March 02, 2020, 08:11:12 pm »
not that much of a proficiency...
but i suppose (i) is way easier, even for my first game ever on qb64.

funny story: when i tried improve my code to this

Code: QB64: [Select]
  1. SUB rotation (xt, yt, x1, y1, x2, y2, x3, y3, sp)
  2.  
  3.     IF xt < _WIDTH / 2 THEN xt = 10
  4.     IF xt > _WIDTH / 2 THEN xt = _WIDTH - 30
  5.     IF yt < _HEIGHT / 2 THEN yt = (RND * _HEIGHT / 2)
  6.     IF yt > _HEIGHT / 2 THEN yt = _HEIGHT - 30
  7.     IF yt = 10 THEN _MAPTRIANGLE _SEAMLESS(xt, yt)-(xt, yt)-(xt, yt), sp TO(x1, y1)-(x2, y2)-(x3, y3)
  8.     IF yt = _HEIGHT - 30 THEN _MAPTRIANGLE _SEAMLESS(xt, yt)-(xt, yt)-(xt, yt), sp TO(x1, y1)-(x2, y2)-(x3, y3)
  9.  
  10.  

the spike started glitching in a certain way that made me grin
« Last Edit: March 02, 2020, 08:15:46 pm by codevsb12 »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: collision questions and hard work
« Reply #26 on: March 02, 2020, 08:37:41 pm »
Question: Is maptriange irreducibly necessary, or can you work with putimage? I actually forget if putimage works well with rotations. i should go look that up...

Okay we're stuck with maptriangle. I'll cook something up.
« Last Edit: March 02, 2020, 08:45:21 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

FellippeHeitor

  • Guest
Re: collision questions and hard work
« Reply #27 on: March 02, 2020, 09:07:44 pm »
Might offer some insight: https://github.com/FellippeHeitor/Snippets/blob/master/rotateImage.bas

Code: QB64: [Select]
  1.  
  2. TYPE vertex
  3.     x AS SINGLE
  4.     y AS SINGLE
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7. DIM bee AS LONG
  8. bee = _LOADIMAGE("bee-12.jpg")
  9.  
  10.     CLS
  11.     i = map(_MOUSEX, 0, _WIDTH - 1, -90, 90)
  12.     IF _KEYDOWN(100306) THEN i = INT(i)
  13.     PRINT "rotation angle:"; i
  14.     putImage _WIDTH / 2 - _WIDTH(bee) / 2, _HEIGHT / 2 - _HEIGHT(bee) / 2, bee, i
  15.     _DISPLAY
  16.     _LIMIT 30
  17.  
  18. SUB putImage (__x AS SINGLE, __y AS SINGLE, image AS LONG, angleDegrees AS SINGLE)
  19.     DIM i AS LONG
  20.  
  21.     DIM center AS vertex
  22.     DIM corner(1 TO 4) AS vertex
  23.  
  24.     center.x = __x + _WIDTH(image) / 2
  25.     center.y = __y + _HEIGHT(image) / 2
  26.  
  27.     FOR i = 1 TO 4
  28.         SELECT CASE i
  29.             CASE 1
  30.                 corner(i).x = __x
  31.                 corner(i).y = __y
  32.             CASE 2
  33.                 corner(i).x = __x
  34.                 corner(i).y = (__y + _HEIGHT(image) - 1)
  35.             CASE 3
  36.                 corner(i).x = (__x + _WIDTH(image) - 1)
  37.                 corner(i).y = __y
  38.             CASE 4
  39.                 corner(i).x = (__x + _WIDTH(image) - 1)
  40.                 corner(i).y = (__y + _HEIGHT(image) - 1)
  41.         END SELECT
  42.  
  43.         rotate corner(i), center, angleDegrees
  44.     NEXT
  45.  
  46.     _MAPTRIANGLE (0, 0)-(0, _HEIGHT(image) - 1)-(_WIDTH(image) - 1, 0), image TO(corner(1).x, corner(1).y)-(corner(2).x, corner(2).y)-(corner(3).x, corner(3).y)
  47.     _MAPTRIANGLE (0, _HEIGHT(image) - 1)-(_WIDTH(image) - 1, 0)-(_WIDTH(image) - 1, _HEIGHT(image) - 1), image TO(corner(2).x, corner(2).y)-(corner(3).x, corner(3).y)-(corner(4).x, corner(4).y)
  48.  
  49. SUB rotate (p AS vertex, center AS vertex, angleDegrees AS SINGLE)
  50.     'as seen on https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d
  51.     DIM s AS SINGLE, c AS SINGLE
  52.     DIM newP AS vertex
  53.     DIM angle AS SINGLE
  54.  
  55.     angle = _D2R(angleDegrees)
  56.  
  57.     s = SIN(angle)
  58.     c = COS(angle)
  59.  
  60.     p.x = p.x - center.x
  61.     p.y = p.y - center.y
  62.  
  63.     newP.x = p.x * c - p.y * s
  64.     newP.y = p.x * s + p.y * c
  65.  
  66.     p.x = newP.x + center.x
  67.     p.y = newP.y + center.y
  68.  
  69. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  70.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: collision questions and hard work
« Reply #28 on: March 02, 2020, 09:37:55 pm »
I hate the fact that BASIC uses the wrong coordinate system in screen modes. This puts 0,0 at the center and +y means up. Requires the image attached or any image if you rename.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. Image& = _LOADIMAGE("QB64-1.4-Release.png")
  4.  
  5. TYPE vec2
  6.     x AS DOUBLE
  7.     y AS DOUBLE
  8.  
  9. TYPE triplet
  10.     u AS vec2
  11.     v AS vec2
  12.     w AS vec2
  13.  
  14. a = 0
  15.     CLS
  16.     a = a + .005
  17.     CALL showimage(0, 0, Image&, 1, 1, a)
  18.     _DISPLAY
  19.     _LIMIT 60
  20.  
  21.  
  22. SUB showimage (x0, y0, i&, sx, sy, ang)
  23.     DIM sc AS triplet
  24.     DIM dc AS triplet
  25.     w = _WIDTH(i&) / 2
  26.     h = _HEIGHT(i&) / 2
  27.     sc.u.x = w - 1
  28.     sc.u.y = h - 1
  29.     sc.v.x = -w
  30.     sc.v.y = h - 1
  31.     sc.w.x = -w
  32.     sc.w.y = -h
  33.     dc.u.x = x0 + (sx * w) * COS(ang) - (sy * h) * SIN(ang)
  34.     dc.u.y = y0 + (sx * w) * SIN(ang) + (sy * h) * COS(ang)
  35.     dc.v.x = x0 + (-sx * w) * COS(ang) - (sy * h) * SIN(ang)
  36.     dc.v.y = y0 + (-sx * w) * SIN(ang) + (sy * h) * COS(ang)
  37.     dc.w.x = x0 + (-sx * w) * COS(ang) - (-sy * h) * SIN(ang)
  38.     dc.w.y = y0 + (-sx * w) * SIN(ang) + (-sy * h) * COS(ang)
  39.     CALL cmaptriangle(i&, 2 * w, 2 * h, sc, dc)
  40.     sc.u.x = -w
  41.     sc.u.y = -h
  42.     sc.v.x = w - 1
  43.     sc.v.y = -h
  44.     sc.w.x = w - 1
  45.     sc.w.y = h - 1
  46.     dc.u.x = x0 + (-sx * w) * COS(ang) - (-sy * h) * SIN(ang)
  47.     dc.u.y = y0 + (-sx * w) * SIN(ang) + (-sy * h) * COS(ang)
  48.     dc.v.x = x0 + (sx * w) * COS(ang) - (-sy * h) * SIN(ang)
  49.     dc.v.y = y0 + (sx * w) * SIN(ang) + (-sy * h) * COS(ang)
  50.     dc.w.x = x0 + (sx * w) * COS(ang) - (sy * h) * SIN(ang)
  51.     dc.w.y = y0 + (sx * w) * SIN(ang) + (sy * h) * COS(ang)
  52.     CALL cmaptriangle(i&, 2 * w, 2 * h, sc, dc)
  53.  
  54. SUB cmaptriangle (i&, w, h, s AS triplet, d AS triplet)
  55.     _MAPTRIANGLE (w / 2 + s.u.x, -s.u.y + h / 2)-(w / 2 + s.v.x, -s.v.y + h / 2)-(w / 2 + s.w.x, -s.w.y + h / 2), i& TO(_WIDTH / 2 + d.u.x, -d.u.y + _HEIGHT / 2)-(_WIDTH / 2 + d.v.x, -d.v.y + _HEIGHT / 2)-(_WIDTH / 2 + d.w.x, -d.w.y + _HEIGHT / 2)
  56.  
« Last Edit: March 02, 2020, 10:11:33 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: collision questions and hard work
« Reply #29 on: March 02, 2020, 10:47:52 pm »
Oh man what fun! Now 2nd time I use Paint 3D to make transparent background (except it left a gray halo around image thus gray background):
« Last Edit: March 02, 2020, 11:19:28 pm by bplus »