Fix bags in RayCast
This commit is contained in:
parent
adc2d44243
commit
e00a5ebf73
1 changed files with 46 additions and 46 deletions
|
@ -136,7 +136,7 @@ namespace DangerousD.GameCore.Managers
|
|||
|
||||
Rectangle rectangle;
|
||||
Vector2 distance = entity1.Pos - entity2.Pos;
|
||||
rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y, entity2.Width, entity2.Height);
|
||||
rectangle = new Rectangle((int)entity1.Pos.X, (int)entity1.Pos.Y - 5, entity2.Width, entity2.Height);
|
||||
GameObject gameObject = null;
|
||||
double length = distance.Length();
|
||||
|
||||
|
@ -144,32 +144,31 @@ namespace DangerousD.GameCore.Managers
|
|||
{
|
||||
rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X);
|
||||
rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y);
|
||||
}
|
||||
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
||||
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
||||
{
|
||||
return AppManager.Instance.GameManager.entities[i];
|
||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.entities[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
||||
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
||||
{
|
||||
return AppManager.Instance.GameManager.mapObjects[i];
|
||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.mapObjects[i];
|
||||
}
|
||||
}
|
||||
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.livingEntities[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.livingEntities[i];
|
||||
}
|
||||
}
|
||||
return gameObject;
|
||||
return null;
|
||||
}
|
||||
public GameObject RayCast(LivingEntity entity1, Vector2 targetCast)
|
||||
{
|
||||
|
@ -182,28 +181,29 @@ namespace DangerousD.GameCore.Managers
|
|||
{
|
||||
rectangle.X = (int)(targetCast.X + (i / k) * direction.X);
|
||||
rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X);
|
||||
}
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.entities.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
||||
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
||||
{
|
||||
return AppManager.Instance.GameManager.entities[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.mapObjects.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.mapObjects[i];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < AppManager.Instance.GameManager.livingEntities.Count; i++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.livingEntities[i];
|
||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.entities[i];
|
||||
}
|
||||
}
|
||||
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.mapObjects[i];
|
||||
}
|
||||
}
|
||||
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
||||
{
|
||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
return AppManager.Instance.GameManager.livingEntities[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue