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; }