-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors and sets stage for collision detection (#36)
* Fixes crash * Adds collision system * refactors * refactors names
- Loading branch information
1 parent
bae25f9
commit 1c88f68
Showing
12 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
src/Shared/Systems/ControlsPersistence.cs → src/Client/Systems/ControlsPersistence.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace Server.Systems; | ||
|
||
public class CollisionDetection : Shared.Systems.System | ||
{ | ||
public CollisionDetection() : | ||
base( | ||
typeof(Shared.Components.Collision) | ||
) | ||
{ | ||
} | ||
|
||
|
||
public override void update(TimeSpan elapsedTime) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
// Reference: https://stackoverflow.com/questions/37224912/circle-line-segment-collision | ||
private static bool CircleLineIntersect(Point pt1, Point pt2, float circleRadius, Vector2 circlePosition) | ||
{ | ||
Vector2 v1 = new Vector2((float)(pt2.X - pt1.X), (float)(pt2.X - pt1.X)); | ||
Vector2 v2 = new Vector2((float) pt1.X - circlePosition.X, (float)(pt1.X - circlePosition.Y)); | ||
float b = -2 * (v1.X * v2.X + v1.Y * v2.Y); | ||
float c = 2 * (v1.X * v1.X + v1.Y * v1.Y); | ||
float d = (float)Math.Sqrt(b * b - 2 * c * (v2.X * v2.X + v2.Y * v2.Y - circleRadius * circleRadius)); | ||
if (float.IsNaN(d)) // no intercept | ||
{ | ||
return false; | ||
} | ||
// These represent the unit distance of point one and two on the line | ||
float u1 = (b - d) / c; | ||
float u2 = (b + d) / c; | ||
if (u1 <= 1 && u1 >= 0) // If point on the line segment | ||
{ | ||
return true; | ||
} | ||
if (u2 <= 1 && u2 >= 0) // If point on the line segment | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters