Skip to content

C# object problem

Anthony Rose

Asked Jan 29, 2009, 10:02 PM EST1 answer
Share
LinkedInX
Hey guys i am trying to make this work it works with out the function (or method as C# calls it) but it would require a lot of similar code copied and pasted over and over again how would i get this to work? (if im making any sense)

public void objCollision(object a, object b)
        {
            if (a.Bottom >= b.Top && a.Right >= b.Left && a.Left <= b.Right && a.Top <= b.Bottom)
            {
                MessageBox.Show("Collision Detected!");
            }
        }

i just want to be able to use objCollision(box1, box2); if that is possible...

thanks in advance!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    I didn't understand the question very well but I try to answer it
    Ok you create a class

    public class Box
    {
        // put your code here to perform the Shape strucutre and behaviour "how it moves for example"
        public void ObjectCollision(Box box)
        {
              //you put your code here to check whether this and box
              //make chocs
              if(this.Left ... box.Left && ....)
              {
                       
               }
        }
    }


    in the Main code


    Box box1 = new Box();
    Box box2 = new Box();

    box2.ObjectCollision(Box1);
    0