fix collisions
This commit is contained in:
parent
566e42d6d2
commit
180fdae2ec
1 changed files with 24 additions and 28 deletions
|
@ -20,9 +20,9 @@ namespace DangerousD.GameCore.Managers
|
||||||
item.velocity = item.velocity + item.acceleration * delta;
|
item.velocity = item.velocity + item.acceleration * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckCollisions(livingEntities, mapObjects);
|
CheckCollisionsLE_MO(livingEntities, mapObjects);
|
||||||
OnCollision(entities, livingEntities);
|
CheckCollisionsE_LE(entities, livingEntities);
|
||||||
OnCollision(livingEntities);
|
CheckCollisionsLE_LE(livingEntities);
|
||||||
|
|
||||||
//entities dont move
|
//entities dont move
|
||||||
//Living entities dont move
|
//Living entities dont move
|
||||||
|
@ -33,29 +33,27 @@ namespace DangerousD.GameCore.Managers
|
||||||
//OnCollision
|
//OnCollision
|
||||||
|
|
||||||
}
|
}
|
||||||
public void CheckCollisions(List<LivingEntity> livingEntities,
|
private void CheckCollisionsLE_MO(List<LivingEntity> livingEntities,
|
||||||
List<MapObject> mapObjects)
|
List<MapObject> mapObjects)
|
||||||
{
|
{
|
||||||
LivingEntity currentEntity;
|
foreach (var currentEntity in livingEntities)
|
||||||
Rectangle oldRect;
|
|
||||||
for (int i = 0; i < livingEntities.Count; i++)
|
|
||||||
{
|
{
|
||||||
currentEntity = livingEntities[i];
|
Rectangle oldRect = currentEntity.Rectangle;
|
||||||
oldRect = currentEntity.Rectangle;
|
|
||||||
bool isXNormalise = true;
|
bool isXNormalise = true;
|
||||||
bool isYNormalise = true;
|
bool isYNormalise = true;
|
||||||
|
|
||||||
oldRect.Offset((int)currentEntity.velocity.X, 0);
|
oldRect.Offset((int)currentEntity.velocity.X, 0);
|
||||||
for (int j = 0; j < mapObjects.Count; j++)
|
foreach (var mapObject in mapObjects)
|
||||||
{
|
{
|
||||||
if (Math.Abs(mapObjects[i].Pos.X - currentEntity.Pos.X) < 550 && Math.Abs(mapObjects[i].Pos.Y - currentEntity.Pos.Y) < 550)
|
if (
|
||||||
|
Math.Abs(mapObject.Pos.X - currentEntity.Pos.X) < 550
|
||||||
|
&& Math.Abs(mapObject.Pos.Y - currentEntity.Pos.Y) < 550
|
||||||
|
&& oldRect.Intersects(mapObject.Rectangle)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
isXNormalise = false;
|
||||||
{
|
oldRect.Offset(-(int)currentEntity.velocity.X, 0);
|
||||||
isXNormalise = false;
|
break;
|
||||||
oldRect.Offset(-(int)currentEntity.velocity.X, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isXNormalise)
|
if (!isXNormalise)
|
||||||
|
@ -63,10 +61,9 @@ namespace DangerousD.GameCore.Managers
|
||||||
|
|
||||||
|
|
||||||
oldRect.Offset(0, (int)currentEntity.velocity.Y);
|
oldRect.Offset(0, (int)currentEntity.velocity.Y);
|
||||||
for (int j = 0; j < mapObjects.Count; j++)
|
foreach (var mapObject in mapObjects)
|
||||||
{
|
{
|
||||||
|
if (oldRect.Intersects(mapObject.Rectangle))
|
||||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
|
||||||
{
|
{
|
||||||
isYNormalise = false;
|
isYNormalise = false;
|
||||||
oldRect.Offset(0, -(int)currentEntity.velocity.Y);
|
oldRect.Offset(0, -(int)currentEntity.velocity.Y);
|
||||||
|
@ -79,22 +76,21 @@ namespace DangerousD.GameCore.Managers
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void OnCollision(List<Entity> entities, List<LivingEntity> livingEntities)
|
private void CheckCollisionsE_LE(List<Entity> entities, List<LivingEntity> livingEntities)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < entities.Count; i++)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < livingEntities.Count; j++)
|
foreach (var livingEntity in livingEntities)
|
||||||
{
|
{
|
||||||
if (livingEntities[j].Rectangle.Intersects(entities[i].Rectangle))
|
if (livingEntity.Rectangle.Intersects(entity.Rectangle))
|
||||||
{
|
{
|
||||||
livingEntities[j].OnCollision(entities[i]);
|
livingEntity.OnCollision(entity);
|
||||||
entities[i].OnCollision(livingEntities[j]);
|
entity.OnCollision(livingEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void OnCollision(List<LivingEntity> livingEntities)
|
private void CheckCollisionsLE_LE(List<LivingEntity> livingEntities)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < livingEntities.Count; i++)
|
for (int i = 0; i < livingEntities.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue