Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void ResolveCollisions() {
- List<Entity> elist = GetCollisionsList(this.BoundingSprite);
- if (elist.Count > 0) {
- foreach (Entity e in elist) {
- //Entity e = elist[0];
- CollisionPart ep = (CollisionPart)e.SignalPart("CollisionPart");
- //where to move
- float moveX = 0.0f;
- float moveY = 0.0f;
- //left/right/top/bottom
- float l = ep.BoundingSprite.Position.X - (this.BoundingSprite.Position.X + this.BoundingSprite.Texture.Size.X);
- float r = (ep.BoundingSprite.Position.X + ep.BoundingSprite.Texture.Size.X) - this.BoundingSprite.Position.X;
- float t = ep.BoundingSprite.Position.Y - (this.BoundingSprite.Position.Y + this.BoundingSprite.Texture.Size.Y);
- float b = (ep.BoundingSprite.Position.Y + ep.BoundingSprite.Texture.Size.Y) - this.BoundingSprite.Position.Y;
- // find the offset of both sides
- moveX = Math.Abs(l) < r ? l : r;
- moveY = Math.Abs(t) < b ? t : b;
- //speed at which entities will move out of each other (for cooler effect)
- //um, never mind, using delta time causes things to get pushed by
- //other entities when they shouldn't be able to.
- float s = 1; // Globals.DeltaTime.AsSeconds() * 26.0f;
- // only use whichever offset is the smallest
- if (Math.Abs(moveX) < Math.Abs(moveY))
- this.HorizontalPosition += moveX * s; else
- this.VerticlePosition += moveY * s;
- //making these negative is very funny
- //multiplying the values by deltatime has a cool slowdown effect
- }
- this.UpdateBounding();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement