Stuck in wall bug (#5)

* Created a GetCollisionSide method.

* Bug Fixed and Tested

Co-authored-by: jme9 <jme9@pdx.edu>
This commit is contained in:
J. M. Ellis
2025-05-17 18:55:17 -07:00
committed by GitHub
parent 218f4da157
commit b9b339d51c
5 changed files with 90 additions and 19 deletions
+21 -7
View File
@@ -27,8 +27,11 @@ namespace LunaLightXMG
private Texture2D texture;
public Vector2 position;
public BoundingBox boundingBox { get; private set; }
public CollisionManager.CollisionSide collisionSide { get; private set; }
private CollisionManager collisionManager;
public Player(Vector2 initPosition)
{
hsp = 0;
@@ -130,7 +133,7 @@ namespace LunaLightXMG
hsp = 0;
}
position.X += hsp; // Horizontal move
// Vertical collision prediction
float onePixv = Math.Sign(vsp);
if (CollisionManager.IsColliding(position + new Vector2(0, vsp), boundingBox, platforms))
@@ -150,6 +153,8 @@ namespace LunaLightXMG
walled = CollisionManager.WallCheck(position, boundingBox, platforms);
if (walled)
wasWalled = walled;
collisionSide = CollisionManager.GetCollisionSide(position, boundingBox, platforms);
}
private float Approach(float start, float end, float shift)
@@ -168,17 +173,26 @@ namespace LunaLightXMG
}
return start;
}
private void DumpFractions()
{
if (grounded)
{
float adjustedPosX = (float)Math.Round(position.X);
float adjustedPosY = (float)Math.Round(position.Y);
position.X = adjustedPosX;
position.Y = adjustedPosY;
if (collisionSide == CollisionManager.CollisionSide.Right)
{
position.X = (float)Math.Floor(position.X);
}
else if (collisionSide == CollisionManager.CollisionSide.Left)
{
position.X = (float)Math.Ceiling(position.X);
}
else
{
position.X = (float)Math.Round(position.X);
}
position.Y = (float)Math.Round(position.Y);
}
if (vsp >= 0)
{
hsp += hsp_frac;