public bool Intersects(BoundingBox2D other) { float dX = Math.Abs(Center.X - other.Center.X); float dY = Math.Abs(Center.Y - other.Center.Y); return dX <= (Width + other.Width) / 2 && dY <= (Height + other.Height) / 2; }
private void UpdateValues() { sprite.Position = position; OldBoundingBox.SetCenter(NewBoundingBox.Center); BoundingBox2D newBoundingBox = NewBoundingBox; newBoundingBox.SetCenter(position); groundTestingPointLeft = new Vector2(newBoundingBox.Left, newBoundingBox.Bottom + GROUND_TESTING_OFFSET); groundTestingPointRight = new Vector2(newBoundingBox.Right, newBoundingBox.Bottom + GROUND_TESTING_OFFSET); Vector2 cameraPosition = Camera.Instance.Position; cameraPosition.Y = position.Y; Camera.Instance.Position = cameraPosition; }
public Player(HeightDisplay heightDisplay) { this.heightDisplay = heightDisplay; Texture2D texture = ContentLoader.LoadTexture("Player"); int width = texture.Width; int height = texture.Height; sprite = new Sprite(texture, position); halfBounds = new Vector2(width, height) / 2; OldBoundingBox = new BoundingBox2D(position, width, height); NewBoundingBox = new BoundingBox2D(position, width, height); heightOffset = int.MinValue; ResetValues(); SimpleEvent.AddEvent(EventTypes.LISTENER, new ListenerEventData(EventTypes.KEYBOARD, this)); SimpleEvent.AddEvent(EventTypes.LISTENER, new ListenerEventData(EventTypes.RESET, this)); }
public BoundingBox2D(BoundingBox2D other) : this(other.Center, other.Width, other.Height) { }
private bool OffPlatform() { BoundingBox2D platformBox = platform.BoundingBox; return(!platformBox.Contains(groundTestingPointLeft) && !platformBox.Contains(groundTestingPointRight)); }