Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. private void CheckCollisionX()
  2.         {
  3.             Debug.Print("Checking X Collision");
  4.             foreach (Tile entity in entityManager.Entities.OfType<Tile>().Where(entity => entity.HitRect.Intersects(hitRect)))
  5.             {
  6.                 if ((hitRect.Left > entity.HitRect.Left && hitRect.Left < entity.HitRect.Right) ||
  7.                     (hitRect.Right < entity.HitRect.Right && hitRect.Right > entity.HitRect.Left))
  8.                 {
  9.                     if (moveSpeed.X > 0)
  10.                     {
  11.                         position.X -= (position.X%entity.HitRect.Width);
  12.                         moveSpeed.X = 0;
  13.                     }
  14.                     else if (moveSpeed.X < 0)
  15.                     {
  16.                         position.X += (position.X%entity.HitRect.Width);
  17.                         moveSpeed.X = 0;
  18.                     }
  19.                 }
  20.             }
  21.         }
  22.  
  23.         private void CheckCollisionY()
  24.         {
  25.             Debug.Print("Checking Y Collision");
  26.             foreach (Tile entity in entityManager.Entities.OfType<Tile>().Where(entity => entity.HitRect.Intersects(hitRect)))
  27.             {
  28.                 if ((hitRect.Top > entity.HitRect.Top && hitRect.Top < entity.HitRect.Bottom) ||
  29.                     (hitRect.Bottom < entity.HitRect.Bottom && hitRect.Bottom > entity.HitRect.Top))
  30.                 {
  31.                     if (moveSpeed.Y > 0)
  32.                     {
  33.                         position.Y -= (position.Y%entity.HitRect.Height);
  34.                         moveSpeed.Y = 0;
  35.                         hasJumped = false;
  36.                     }
  37.                     else if (moveSpeed.Y < 0)
  38.                     {
  39.                         position.Y += (position.Y%entity.HitRect.Height);
  40.                         moveSpeed.Y = 0;
  41.                     }
  42.                 }
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement