本文整理汇总了C#中Room.GetCollidingSolidEntities方法的典型用法代码示例。如果您正苦于以下问题:C# Room.GetCollidingSolidEntities方法的具体用法?C# Room.GetCollidingSolidEntities怎么用?C# Room.GetCollidingSolidEntities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Room
的用法示例。
在下文中一共展示了Room.GetCollidingSolidEntities方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveWithCollision
public void MoveWithCollision(Room room)
{
if (Velocity.X > 0)
{
int x = ((position.X + Velocity.X) / Resolution + Width) / room.TileMap.TileSize.X;
int yStart = Y / room.TileMap.TileSize.Y;
int yEnd = (Y + Height - 2) / room.TileMap.TileSize.Y;
for (int y = yStart; y <= yEnd; y++)
{
if (room.TileMap.IsSolid(x, y))
{
X = x * room.TileMap.TileSize.X - Width;
Velocity.X = 0;
break;
}
}
if (Velocity.X != 0)
{
IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, Y, Width, Height));
foreach (Entity s in solids)
{
if (s == this) continue;
X = s.X - Width;
Velocity.X = 0;
}
}
}
else if (Velocity.X < 0)
{
int x = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;
int yStart = Y / room.TileMap.TileSize.Y;
int yEnd = (Y + Height - 2) / room.TileMap.TileSize.Y;
for (int y = yStart; y <= yEnd; y++)
{
if (room.TileMap.IsSolid(x, y))
{
X = (1 + x) * room.TileMap.TileSize.X;
Velocity.X = 0;
break;
}
}
if (Velocity.X != 0)
{
IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, Y, Width, Height));
foreach (Entity s in solids)
{
if (s == this) continue;
X = s.X + s.Width;
Velocity.X = 0;
}
}
}
if (Velocity.Y > 0)
{
int y = ((position.Y + Velocity.Y) / Resolution + Height) / room.TileMap.TileSize.Y;
int xStart = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;
int xEnd = ((position.X + Velocity.X) / Resolution + Width - 1) / room.TileMap.TileSize.X;
for (int x = xStart; x <= xEnd; x++)
{
if (room.TileMap.IsSolid(x, y))
{
Y = y * room.TileMap.TileSize.Y - Height;
Velocity.Y = 0;
break;
}
}
if (Velocity.Y != 0)
{
IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle((position.X + Velocity.X) / Resolution, (position.Y + Velocity.Y) / Resolution, Width, Height));
foreach (Entity s in solids)
{
if (s == this) continue;
Y = s.Y - Height;
Velocity.Y = 0;
}
}
}
else if (Velocity.Y < 0)
{
int y = ((position.Y + Velocity.Y) / Resolution - 1) / room.TileMap.TileSize.Y;
int xStart = ((position.X + Velocity.X) / Resolution) / room.TileMap.TileSize.X;
int xEnd = ((position.X + Velocity.X) / Resolution + Width - 1) / room.TileMap.TileSize.X;
//.........这里部分代码省略.........
示例2: IsTileSolidBelow
public bool IsTileSolidBelow(Room room)
{
int y = (Dimension.Y + Dimension.Height) / room.TileMap.TileSize.Y;
int xStart = Dimension.X / room.TileMap.TileSize.X;
int xEnd = (Dimension.X + Dimension.Width - 1) / room.TileMap.TileSize.X;
for (int x = xStart; x <= xEnd; x++)
{
if (room.TileMap.IsSolid(x, y))
{
return true;
}
}
IList<Entity> solids = room.GetCollidingSolidEntities(new Rectangle(X, Y + Height, Width, 1));
return solids.Count > 0 && !(solids.Count == 1 && solids.Contains(this));
}