From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/game/components/physics/CollisionBox.cs | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 source/game/components/physics/CollisionBox.cs (limited to 'source/game/components/physics/CollisionBox.cs') diff --git a/source/game/components/physics/CollisionBox.cs b/source/game/components/physics/CollisionBox.cs new file mode 100644 index 0000000..6e678ac --- /dev/null +++ b/source/game/components/physics/CollisionBox.cs @@ -0,0 +1,36 @@ +using System; +using MonoGame.Extended; +using Microsoft.Xna.Framework; + +namespace Celesteia.Game.Components.Physics { + public class CollisionBox { + public RectangleF _bounds; + public RectangleF Bounds { get => _bounds; set => _bounds = value; } + private Rectangle _rounded; + public Rectangle Rounded { get => _rounded; } + + public CollisionBox(float width, float height) { + _bounds = new RectangleF(-width / 2f, -height / 2f, width, height); + _rounded = Round(_bounds); + } + + public void Update(Vector2 position) { + _bounds.X = position.X - (Bounds.Width / 2f); + _bounds.Y = position.Y - (Bounds.Height / 2f); + _rounded = Round(_bounds); + } + + public Rectangle Round(RectangleF floatRect) { + return new Rectangle((int)MathF.Floor(floatRect.X), (int)MathF.Floor(floatRect.Y), (int)MathF.Ceiling(floatRect.Width), (int)MathF.Ceiling(floatRect.Height)); + } + + public RectangleF Intersection(CollisionBox other) { + return Intersection(other.Bounds); + } + + public RectangleF Intersection(RectangleF other) { + RectangleF intersection = other.Intersection(Bounds); + return intersection; + } + } +} \ No newline at end of file -- cgit v1.2.3