1 Replies - 254 Views - Last Post: 15 November 2012 - 07:57 PM Rate Topic: -----

#1 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

Collisions Aren't Working Properly

Posted 15 November 2012 - 04:24 PM

 
For i As Integer = 0 To objects.Count - 1
            objects(i).DrawLocation = New Point(objects(i).DrawLocation.X, objects(i).DrawLocation.Y - 16)

           
            If New Rectangle(objects(i).DrawLocation.X, objects(i).DrawLocation.Y, 32, 32).IntersectsWith(New Rectangle(playerRect.X, playerRect.Y + 64, 32, 0)) Then


                If Not objects(i).Transparent = True And Not objects(i).Btype = "air" Then
                    graph.DrawRectangle(Pens.Black, playerRect)
                    graph.FillRectangle(Brushes.Chartreuse, playerRect)
                    fall = False
                    Debug.WriteLine("collision")

                Else

                    graph.DrawRectangle(Pens.Black, playerRect)
                    graph.FillRectangle(Brushes.Chartreuse, playerRect)
                    fall = True
                End If


                If fall = True Then
                Else
                    REM Deutsch
                    ' Deutsch
                    For ni = 0 To i
                        objects(i).DrawLocation = New Point(objects(i).DrawLocation.X, objects(i).DrawLocation.Y + 16)
                    Next
                    Exit For
                End If


            End If


          
        Next


Hey guys
I've been hard at work recently on a certain kind of graivity for my game. I got the actual player to move, but now I am trying to instead get the blocks to move. This is proving to be a bit of an issue. What I really want is, as soon as the player hits a non-transparent block or air the blocks will stop moving and it will arrange itself properly. What happens is this...
Attached Image
It is not working the way it's supposed to. I've done what I can but nothing works so I have decided to come to you. I'll keep working on it in the meantime but I hope someone can help me out.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Collisions Aren't Working Properly

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1062
  • View blog
  • Posts: 4,144
  • Joined: 02-July 08

Re: Collisions Aren't Working Properly

Posted 15 November 2012 - 07:57 PM

Sorry, that picture does not tell me anything - not sure what to look at. Here is a poss solution, as a guess, the thing about IntersectsWith it checks the rectangle in question - probably the one your moving. Instead create a fake rectangle that would be the new move - if that one IntersectsWith the one your checking(wall, unmovable space, etc...) then cancel the move procedure. Think of it this way, you are setting a new location not moving the player 1 pixel at a time - right? so IntersectWith only knows the new location - which of course could be any number of pixel into the wrong spot before it catches it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1