Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# Untitled

By: a guest on Jun 21st, 2011  |  syntax: C#  |  size: 2.67 KB  |  views: 45  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1.   public void Update()
2.         {
3.             Velocity += World.Gravity;
4.
5.             Vector2 next = Velocity;
6.
7.             bool xCollided = false;
8.             bool yCollided = false;
9.
10.             List<SSSPBody> toCheck = World.Bodies; // spatial hash is fucked up, entities at YMax +1 and Y 7 are fucked up
11.
12.             for (int i = 0; i < toCheck.Count; i++)
13.             {
14.                 SSSPBody body = toCheck[i];
15.                 body.Test.Color = Color.Red;
16.
17.                 if (body != this)
18.                 {
19.                     Vector2 nextCornerMin = CornerMin + new Vector2(next.X, 0);
20.                     Vector2 nextCornerMax = CornerMax + new Vector2(next.X, 0);
21.
22.                     if (SSSPUtils.AABBIsOverlapping(nextCornerMin, nextCornerMax, body.CornerMin, body.CornerMax))
23.                     {
24.                         body.Test.Color = Color.Red;
25.                         xCollided = true;
26.                         float left = (body.CornerMin.X - nextCornerMax.X);
27.                         float right = (body.CornerMax.X - nextCornerMin.X);
28.
29.                         if (Math.Abs(left) < right)
30.                             Position = new Vector2(Position.X + next.X + left, Position.Y);
31.                         else
32.                             Position = new Vector2(Position.X + next.X + right, Position.Y);
33.
34.                         next = new Vector2(0, next.Y);
35.                         Velocity = new Vector2(0, next.Y);
36.                     }
37.
38.                     nextCornerMin = CornerMin + new Vector2(0, next.Y);
39.                     nextCornerMax = CornerMax + new Vector2(0, next.Y);
40.
41.                     if (SSSPUtils.AABBIsOverlapping(nextCornerMin, nextCornerMax, body.CornerMin, body.CornerMax))
42.                     {
43.                         body.Test.Color = Color.Red;
44.                         yCollided = true;
45.                         float top = (body.CornerMin.Y - nextCornerMax.Y);
46.                         float bottom = (body.CornerMax.Y - nextCornerMin.Y);
47.
48.                         if (Math.Abs(top) < bottom)
49.                             Position = new Vector2(Position.X, Position.Y + next.Y + top);
50.                         else
51.                             Position = new Vector2(Position.X, Position.Y + next.Y + bottom);
52.
53.                         next = new Vector2(next.X, 0);
54.                         Velocity = new Vector2(next.X, 0);
55.                     }
56.                 }
57.             }
58.
59.             if (xCollided == false) Position = new Vector2(Position.X + next.X, Position.Y);
60.             if (yCollided == false) Position = new Vector2(Position.X, Position.Y + next.Y);
61.         }
clone this paste RAW Paste Data
Top