Advertisement
Guest User

Untitled

a guest
Jun 20th, 2011
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1.     public void Update()
  2.         {
  3.             Position += Velocity;
  4.             Velocity += World.Gravity;
  5.            
  6.             List<SSSPBody> toCheck = World.SpatialHash.GetNearbyItems(this);
  7.  
  8.             for (int i = 0; i < toCheck.Count; i++)
  9.             {
  10.                 SSSPBody body = toCheck[i];
  11.                 body.Test.Color = Color.White;
  12.  
  13.                 if (body != this && body.Static)
  14.                 {                  
  15.                     float left = (body.CornerMin.X - CornerMax.X);
  16.                     float right = (body.CornerMax.X - CornerMin.X);
  17.                     float top = (body.CornerMin.Y - CornerMax.Y);
  18.                     float bottom = (body.CornerMax.Y - CornerMin.Y);
  19.  
  20.                     if (SSSPUtils.AABBIsOverlapping(this, body))
  21.                     {
  22.                         body.Test.Color = Color.Yellow;
  23.  
  24.                         Vector2 overlapVector = SSSPUtils.AABBGetOverlapVector(left, right, top, bottom);
  25.  
  26.                         Position += overlapVector;
  27.                     }
  28.  
  29.                     if (SSSPUtils.AABBIsCollidingTop(this, body))
  30.                     {                      
  31.                         if ((Position.X >= body.CornerMin.X && Position.X <= body.CornerMax.X) &&
  32.                             (Position.Y + Height/2f == body.Position.Y - body.Height/2f))
  33.                         {
  34.                             body.Test.Color = Color.Red;
  35.                             Velocity = new Vector2(Velocity.X, 0);
  36.                            
  37.                         }
  38.                     }
  39.                 }              
  40.             }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement