Solid Object Collision=Stop movement

Something for the pros? *cough*

Page 1 of 1

4 Replies - 9773 Views - Last Post: 23 May 2008 - 05:47 PM Rate Topic: -----

#1 True Valhalla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-May 08

Solid Object Collision=Stop movement

Posted 16 May 2008 - 11:41 PM

I would like to know how to get a picture box to stop movement when it collides with another picture box. This is for use in a game. So, for example, when the character collides with a block, movement will be stopped. I am using the WASD keys for movement with the image changing direction as you ress the associated WASD key.

I have searched the net for liek an hour and cant find any tutorial/mention of solid objects.

Found this site and hoping you can have an answer for me soon!!

Will check back tomorrow.

Thanks in advance!! :rolleyes:

Is This A Good Question/Topic? 0
  • +

Replies To: Solid Object Collision=Stop movement

#2 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Solid Object Collision=Stop movement

Posted 17 May 2008 - 12:29 AM

I made a tutorial on creating a fully functional pong game a while a go, and I believe section 5) demonstrates how to check for collisions (its pretty hard-coded towards creation of the pong game however).

You can view it here (click). Let me know how you go. :)

This post has been edited by RodgerB: 17 May 2008 - 12:30 AM

Was This Post Helpful? 0
  • +
  • -

#3 True Valhalla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-May 08

Re: Solid Object Collision=Stop movement

Posted 17 May 2008 - 11:37 PM

Is this the code i code use (im still new to VB):

' Check for computer paddle.
If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then
gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _
gameBall.Location.Y)
xVel = -xVel
End If


So if i have a picture box, and i go

If player.Bounds.IntersectsWith(solidobject.Bounds) Then
Exceute code

would that work?

Also, if so, how do i go "Doesnt intersect with" so

If W pressed
If player.Bounds.IntersectsWith(solidobject.Bounds) Then 'How would you say "not intersecting with"?
moveleftcodehere
End
End



Thanks fr your help already!
Was This Post Helpful? 0
  • +
  • -

#4 omalsa04  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 05-May 08

Re: Solid Object Collision=Stop movement

Posted 19 May 2008 - 02:31 PM

View PostTrue Valhalla, on 17 May, 2008 - 11:37 PM, said:

Is this the code i code use (im still new to VB):

' Check for computer paddle.
If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then
gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _
gameBall.Location.Y)
xVel = -xVel
End If


So if i have a picture box, and i go

If player.Bounds.IntersectsWith(solidobject.Bounds) Then
Exceute code

would that work?

Also, if so, how do i go "Doesnt intersect with" so

If W pressed
If player.Bounds.IntersectsWith(solidobject.Bounds) Then 'How would you say "not intersecting with"?
moveleftcodehere
End
End



Thanks fr your help already!



Have you added a timer?
For a game, it is best to have it check for collisions every timer tick, which is what RodgerB did in his pong game

and I'm not sure, but isn't it just:
If player.Bounds.IntersectsWith(solidobject.Bounds) = False Then 'when it doesn't intersect

End If
Was This Post Helpful? 0
  • +
  • -

#5 True Valhalla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-May 08

Re: Solid Object Collision=Stop movement

Posted 23 May 2008 - 05:47 PM

View Postomalsa04, on 19 May, 2008 - 02:31 PM, said:

View PostTrue Valhalla, on 17 May, 2008 - 11:37 PM, said:

Is this the code i code use (im still new to VB):

' Check for computer paddle.
If gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then
gameBall.Location = New Point(paddleComputer.Location.X + paddleComputer.Size.Width + 1, _
gameBall.Location.Y)
xVel = -xVel
End If


So if i have a picture box, and i go

If player.Bounds.IntersectsWith(solidobject.Bounds) Then
Exceute code

would that work?

Also, if so, how do i go "Doesnt intersect with" so

If W pressed
If player.Bounds.IntersectsWith(solidobject.Bounds) Then 'How would you say "not intersecting with"?
moveleftcodehere
End
End



Thanks fr your help already!



Have you added a timer?
For a game, it is best to have it check for collisions every timer tick, which is what RodgerB did in his pong game

and I'm not sure, but isn't it just:
If player.Bounds.IntersectsWith(solidobject.Bounds) = False Then 'when it doesn't intersect

End If


I got it to work with 2 colliding labels now so i can imlement it into my game.

As to the "DOESNT INTERSECT WITH" code, i simply added a If Not gameBall.Bounds.IntersectsWith(paddleComputer.Bounds) Then


And that has worked.

Thanks for all the help everyone...i'm sure to post aain when other issues arise. :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1