aboutsummaryrefslogtreecommitdiff
path: root/source/game/components/physics
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/game/components/physics
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/game/components/physics')
-rw-r--r--source/game/components/physics/CollisionBox.cs36
-rw-r--r--source/game/components/physics/PhysicsEntity.cs38
2 files changed, 74 insertions, 0 deletions
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
diff --git a/source/game/components/physics/PhysicsEntity.cs b/source/game/components/physics/PhysicsEntity.cs
new file mode 100644
index 0000000..7214dff
--- /dev/null
+++ b/source/game/components/physics/PhysicsEntity.cs
@@ -0,0 +1,38 @@
+using Microsoft.Xna.Framework;
+
+namespace Celesteia.Game.Components.Physics {
+ public class PhysicsEntity {
+ public float Mass;
+
+ public bool Gravity;
+
+ public bool CollidingUp;
+ public bool CollidingLeft;
+ public bool CollidingRight;
+ public bool CollidingDown;
+
+ public PhysicsEntity(float mass, bool affectedByGravity) {
+ Mass = mass;
+ Gravity = affectedByGravity;
+ }
+
+ private Vector2 _velocity;
+ public Vector2 Velocity => _velocity;
+
+ public void SetVelocity(Vector2 vector) {
+ _velocity = vector;
+ }
+
+ public void SetVelocity(float x, float y) {
+ SetVelocity(new Vector2(x, y));
+ }
+
+ public void AddVelocity(Vector2 vector) {
+ _velocity += vector;
+ }
+
+ public void AddVelocity(float x, float y) {
+ AddVelocity(new Vector2(x, y));
+ }
+ }
+} \ No newline at end of file