mirror of
https://github.com/TheRavenwoodArts/LunaLightXMG.git
synced 2026-07-30 22:55:03 -07:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user