Ahmad Zia

Ahmad Zia

  • NA
  • 21
  • 656

Simple Platform game, player doesnt move properly on blocks

Feb 12 2016 12:00 PM
I have made a simple platfrom game, when i made a simple block on screen, the character had proper movements around, but when i add some background and a little more in game, the character doesn't move properly when it is on the block and it keep in viberating.
 
following is the code for a block.
 
  #region Block1
/////1. side collision
if (player.Right > Block1.Left && player.Left < Block1.Right - player.Width && player.Bottom<Block1.Bottom && player.Bottom > Block1.Top)
right = false;
if (player.Left < Block1.Right && player.Right > Block1.Left + player.Width && player.Bottom < Block1.Bottom && player.Bottom > Block1.Top)
left = false;


/////2. top collisions
if (player.Left + player.Width > Block1.Left && player.Left + player.Width < Block1.Left + Block1.Width + player.Width && player.Top + player.Height >= Block1.Top && player.Top < Block1.Top)
{
jump = false;
force = 0;
player.Top = Block1.Location.Y - player.Height;

}


///3. head collisions
if (player.Left + player.Width > Block1.Left && player.Left + player.Width < Block1.Left + Block1.Width + player.Width && player.Top-Block1.Bottom<=10 && player.Top-Block1.Top>-10)
{
force = -1;
}
#endregion