7 Replies - 1698 Views - Last Post: 16 December 2011 - 03:41 PM Rate Topic: -----

#1 Banksy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-July 11

Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 10:45 AM

What I'm trying to do (for a pong game), is what the original creator of pong did. What he did was, he divided the paddle into eight segments to change the ball's angle of return. Now I only want 3 as it's more simplistic, among other reasons. But my problem is, getting to see if the ball intersects with an area of another picturebox.

My user's picturebox has a height of 120, so I want to see if the ball picturebox intersects with the area of the user's picturebox's height to the user's picturebox's height - 40.

I know that was probably a really, really confusing question, because even I confused myself. If you need more details, I'll be happy to supply them.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem: If a picturebox intersects with a specific area of another.

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,276
  • Joined: 12-June 08

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 11:02 AM

Yeah.. not a hundred percent sure what you are asking for. Can you throw us a quick image of what you want done?
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,100
  • Joined: 02-July 08

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 11:03 AM

You can check the PB.ClientRectangle.IntersectWith(<another rectangle>). You could also do the whole thing with rectangles and no PB's if you wanted a bit more challenge later. Kind of a pure graphics version. Sorry I am a huge graphics guy.
Was This Post Helpful? 0
  • +
  • -

#4 Banksy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-July 11

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 14 December 2011 - 10:15 AM

View Post_HAWK_, on 12 December 2011 - 11:03 AM, said:

You can check the PB.ClientRectangle.IntersectWith(<another rectangle>). You could also do the whole thing with rectangles and no PB's if you wanted a bit more challenge later. Kind of a pure graphics version. Sorry I am a huge graphics guy.

The problem is not getting it intersecting with another rectangle, but getting it to intersect with a specific part of that triangle.

Attached Image

Basically, I want to see if the pong ball intersects with the part of the user's paddle that i made a square around.

Also, sorry for the late reply. I've been really busy lately.
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,100
  • Joined: 02-July 08

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 14 December 2011 - 12:43 PM

That would be a math thing. Once you have determined they have connected you figure out where it struck the paddle.

This post has been edited by _HAWK_: 14 December 2011 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

#6 Banksy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 10-July 11

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 10:34 AM

View Post_HAWK_, on 14 December 2011 - 12:43 PM, said:

That would be a math thing. Once you have determined they have connected you figure out where it struck the paddle.

I know that's what I need to do, however I don't know how to do it.
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,100
  • Joined: 02-July 08

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 11:16 AM

Logic:

1) detect collision, skip all if false
2) variable to hold the the paddle top integer
3) create the zones of the paddle -> height / number of zones
4) determine the middle of the ball rect - integer variable,
5) loop thru the number of zones where you test the lower and upper numbers and if the middle variable is between them
6) apply the angle base on which zone returned a true result

Loop(the harder part):

Dim zoneTop As Integer = paddleTop
For z As Integer = 1 To zoneCount
  Select Case z
    Case 1 'top
      If ballMiddle < zoneTop + zoneHt Then 
         'adjust angle for top zone
      End If
    Case 2 To zoneCount - 1
      If ballMiddle > zoneTop AndAlso < zoneTop + zoneHt
         'adjust angle for a middle zone
      End If
    Case zoneCount
      If ballMiddle > zoneTop + zoneHt
         'adjust angle for bottom zone
      End If
   End Select
  zoneTop += zoneHt 'increment the zone ht 
Next


You still need to create the variable above - just an example.

This post has been edited by _HAWK_: 16 December 2011 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

#8 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 03:41 PM

Link:
http://www.dreaminco...onal-pong-game/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1