Fix RayCast
This commit is contained in:
parent
c87b8d9089
commit
d7a4772fe4
3 changed files with 37 additions and 18 deletions
|
@ -16,6 +16,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
{
|
{
|
||||||
Width = 32;
|
Width = 32;
|
||||||
Height = 64;
|
Height = 64;
|
||||||
|
AppManager.Instance.InputManager.MovEventJump += AnimationJump;
|
||||||
|
|
||||||
}
|
}
|
||||||
public bool IsAlive { get { return isAlive; } }
|
public bool IsAlive { get { return isAlive; } }
|
||||||
|
|
||||||
|
@ -41,5 +43,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
|
||||||
}
|
}
|
||||||
isAlive = false;
|
isAlive = false;
|
||||||
}
|
}
|
||||||
|
public void AnimationJump()
|
||||||
|
{
|
||||||
|
velocity.Y = -300;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ namespace DangerousD.GameCore.Levels
|
||||||
new GrassBlock(new Vector2(i*32, 256));
|
new GrassBlock(new Vector2(i*32, 256));
|
||||||
}
|
}
|
||||||
new GrassBlock(new Vector2(500, 224));
|
new GrassBlock(new Vector2(500, 224));
|
||||||
|
Player player = new Player(new Vector2(400, 64));
|
||||||
|
player.AnimationJump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,37 +144,45 @@ namespace DangerousD.GameCore.Managers
|
||||||
{
|
{
|
||||||
rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X);
|
rectangle.X = (int)(entity2.Pos.X + (i / length) * distance.X);
|
||||||
rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y);
|
rectangle.Y = (int)(entity2.Pos.Y + (i / length) * distance.Y);
|
||||||
|
if (i == length - 1)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.entities[j].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.entities[i];
|
gameObject = AppManager.Instance.GameManager.entities[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.mapObjects[r].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.mapObjects[i];
|
gameObject = AppManager.Instance.GameManager.mapObjects[r];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.livingEntities[w].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.livingEntities[i];
|
gameObject = AppManager.Instance.GameManager.livingEntities[w];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameObject == entity1)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
public GameObject RayCast(LivingEntity entity1, Vector2 targetCast)
|
public GameObject RayCast(LivingEntity entity1, Vector2 targetCast)
|
||||||
{
|
{
|
||||||
Rectangle rectangle;
|
Rectangle rectangle;
|
||||||
Vector2 direction = entity1.Pos - targetCast;
|
Vector2 direction = entity1.Pos - targetCast;
|
||||||
rectangle = new Rectangle((int)targetCast.X, (int)targetCast.Y, 1, 1);
|
rectangle = new Rectangle((int)targetCast.X, (int)targetCast.Y, 1, 1);
|
||||||
|
GameObject gameObject = null;
|
||||||
double k = direction.Length();
|
double k = direction.Length();
|
||||||
|
|
||||||
for (int i = 0; i < k; i++)
|
for (int i = 0; i < k; i++)
|
||||||
|
@ -183,29 +191,32 @@ namespace DangerousD.GameCore.Managers
|
||||||
rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X);
|
rectangle.Y = (int)(targetCast.Y + (i / k) * direction.X);
|
||||||
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
for (int j = 0; j < AppManager.Instance.GameManager.entities.Count; j++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.entities[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.entities[j].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.entities[i];
|
gameObject = AppManager.Instance.GameManager.entities[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
for (int r = 0; r < AppManager.Instance.GameManager.mapObjects.Count; r++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.mapObjects[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.mapObjects[r].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.mapObjects[i];
|
gameObject = AppManager.Instance.GameManager.mapObjects[r];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
for (int w = 0; w < AppManager.Instance.GameManager.livingEntities.Count; w++)
|
||||||
{
|
{
|
||||||
if (AppManager.Instance.GameManager.livingEntities[i].Rectangle.Intersects(rectangle))
|
if (AppManager.Instance.GameManager.livingEntities[w].Rectangle.Intersects(rectangle))
|
||||||
{
|
{
|
||||||
return AppManager.Instance.GameManager.livingEntities[i];
|
gameObject = AppManager.Instance.GameManager.livingEntities[w];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (gameObject == entity1)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return gameObject;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GameObject> CheckRectangle(Rectangle rectangle, Type type)
|
public List<GameObject> CheckRectangle(Rectangle rectangle, Type type)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue