Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a mario, platformer type game, and from following a tutorial, they've done the collision like this, but im wondering if there is a simpler way to it since I want to have collision on more than one object.

1.Side collision

if (Player.Right > Block.Left && Player.Left < Block.Right -   Player.Width     && Player.Bottom < Block.Bottom && Player.Bottom > Block.Top)
        {
            right = false;
        }
        if (Player.Left < Block.Right && Player.Right > Block.Left + Player.Width && Player.Bottom < Block.Bottom && Player.Bottom > Block.Top)
        {
            left = false;
        }

2. Top collision

        if (Player.Left + Player.Width > Block.Left && Player.Left + Player.Width < Block.Left + Block.Width + Player.Width && Player.Top + Player.Height >= Block.Top && Player.Top < Block.Top)
        {
            //Player.Top = Screen.Height - Block.Height - Player.Height;
            //force = 0;
            //if (jump == true)
            //{
            //    Player.Image = Image.FromFile("mario_stand.png");
            //}
            jump = false;
            force = 0;
            Player.Top = Block.Location.Y - Player.Height;
        }

3.Head collision

        if (Player.Left + Player.Width > Block.Left && Player.Left + Player.Width < Block.Left + Block.Width + Player.Width && Player.Top - Block.Bottom <= 10 && Player.Top - Block.Top  > -10)
        {
            force = -1;
        }
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.