Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Update()
- {
- Position += Velocity;
- Velocity += World.Gravity;
- List<SSSPBody> toCheck = World.SpatialHash.GetNearbyItems(this);
- for (int i = 0; i < toCheck.Count; i++)
- {
- SSSPBody body = toCheck[i];
- body.Test.Color = Color.White;
- if (body != this && body.Static)
- {
- float left = (body.CornerMin.X - CornerMax.X);
- float right = (body.CornerMax.X - CornerMin.X);
- float top = (body.CornerMin.Y - CornerMax.Y);
- float bottom = (body.CornerMax.Y - CornerMin.Y);
- if (SSSPUtils.AABBIsOverlapping(this, body))
- {
- body.Test.Color = Color.Yellow;
- Vector2 overlapVector = SSSPUtils.AABBGetOverlapVector(left, right, top, bottom);
- Position += overlapVector;
- }
- if (SSSPUtils.AABBIsCollidingTop(this, body))
- {
- if ((Position.X >= body.CornerMin.X && Position.X <= body.CornerMax.X) &&
- (Position.Y + Height/2f == body.Position.Y - body.Height/2f))
- {
- body.Test.Color = Color.Red;
- Velocity = new Vector2(Velocity.X, 0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement