我正在尝试制作一个马里奥,平台游戏类型的游戏,并且通过遵循教程,他们已经完成了这样的碰撞,但我想知道是否有更简单的方法,因为我想要更多的碰撞而不是一个对象。
侧面碰撞
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;
}
顶级碰撞
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;
}
头部碰撞
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;
}