本文整理汇总了C#中World.CanTileBeOccupied方法的典型用法代码示例。如果您正苦于以下问题:C# World.CanTileBeOccupied方法的具体用法?C# World.CanTileBeOccupied怎么用?C# World.CanTileBeOccupied使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.CanTileBeOccupied方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetermineDirectionAggressive
private static Direction DetermineDirectionAggressive(Monster m, World w, Func<bool> shouldMakeAnAggressiveMove)
{
var p = w.Player;
if (p == null || !p.IsExtant)
{
return MonsterMovement.DetermineDirectionRolling(m, w);
}
TilePos tp = m.TilePosition;
/* bool isCurrentlyMovingTowardsFreeSpace;
if (this.Direction == Direction.None)
isCurrentlyMovingTowardsFreeSpace = false;
else
{
TilePos pp = TilePos.GetPositionAfterOneMove(tp, this.Direction);
isCurrentlyMovingTowardsFreeSpace = this._world.IsTileUnoccupied(pp, true);
if (isCurrentlyMovingTowardsFreeSpace)
{
Vector2 newPos = World.GetBounds(pp).GetCentre();
if (!IsInSameRoom(this.Position, newPos) && MonsterRandom.Next(4) != 0)
isCurrentlyMovingTowardsFreeSpace = false;
}
}
*/
Direction newDirection = Direction.None;
TilePos playerPosition = p.TilePosition;
int yDiff = tp.Y - playerPosition.Y;
int xDiff = tp.X - playerPosition.X;
if (m.Direction == Direction.Left || m.Direction == Direction.Right)
{
if (Math.Abs(tp.X - playerPosition.X) == 1 && Math.Abs(yDiff) > 3 && Math.Abs(yDiff) <= 16 && shouldMakeAnAggressiveMove())
{
newDirection = yDiff > 0 ? Direction.Up : Direction.Down;
}
else if ((tp.X - playerPosition.X) == 0 && Math.Abs(yDiff) <= 3 && shouldMakeAnAggressiveMove())
{
newDirection = yDiff > 0 ? Direction.Up : Direction.Down;
}
}
else if (m.Direction == Direction.Up || m.Direction == Direction.Down)
{
if (Math.Abs(tp.Y - playerPosition.Y) == 1 && Math.Abs(xDiff) > 3 && Math.Abs(xDiff) <= 16 && shouldMakeAnAggressiveMove())
{
newDirection = xDiff > 0 ? Direction.Left : Direction.Right;
}
else if ((tp.Y - playerPosition.Y) == 0 && Math.Abs(xDiff) <= 3 && shouldMakeAnAggressiveMove())
{
newDirection = xDiff > 0 ? Direction.Left : Direction.Right;
}
}
if (newDirection != Direction.None)
{
TilePos pp = tp.GetPositionAfterOneMove(newDirection);
if (w.CanTileBeOccupied(pp, true))
{
return newDirection;
}
}
return MonsterMovement.DetermineDirectionRolling(m, w);
}
示例2: DetermineDirectionStandardPatrolling
public static Direction DetermineDirectionStandardPatrolling(Monster m, World w)
{
if (m.Direction == Direction.None)
throw new InvalidOperationException("Direction must be set for patrolling.");
TilePos tp = m.TilePosition;
TilePos pp = tp.GetPositionAfterOneMove(m.Direction);
bool isCurrentlyMovingTowardsFreeSpace = w.CanTileBeOccupied(pp, true);
Vector2 potentiallyMovingTowards = pp.ToPosition();
bool isInSameRoom = IsInSameRoom(m.Position, potentiallyMovingTowards);
bool canContinueMovingInTheSameDirection = isCurrentlyMovingTowardsFreeSpace && isInSameRoom;
var result = canContinueMovingInTheSameDirection ? m.Direction : m.Direction.Reversed();
System.Diagnostics.Trace.WriteLine(string.Format("{0} {1} {2} {3} {4}", tp, pp, isCurrentlyMovingTowardsFreeSpace, isInSameRoom, result));
return result;
}
示例3: DetermineDirectionAggressive
private static Direction DetermineDirectionAggressive(Monster m, World w)
{
TilePos tp = m.TilePosition;
bool isCurrentlyMovingTowardsFreeSpace;
if (m.Direction == Direction.None)
isCurrentlyMovingTowardsFreeSpace = false;
else
{
TilePos pp = tp.GetPositionAfterOneMove(m.Direction);
isCurrentlyMovingTowardsFreeSpace = w.CanTileBeOccupied(pp, true);
if (isCurrentlyMovingTowardsFreeSpace)
{
Vector2 newPos = pp.ToPosition();
if (!MonsterMovement.IsInSameRoom(m.Position, newPos) && MonsterRandom.Next(4) != 0)
isCurrentlyMovingTowardsFreeSpace = false;
}
}
Direction newDirection = Direction.None;
if (w.Player != null)
{
TilePos playerPosition = w.Player.TilePosition;
int yDiff = tp.Y - playerPosition.Y;
int xDiff = tp.X - playerPosition.X;
if (xDiff > 16 || yDiff > 16)
{
// player is out of sight
}
else if (m.Direction == Direction.Left || m.Direction == Direction.Right)
{
// Check if travelling on same row as player
if (yDiff == 0 && ShouldMakeMove())
{
// Move aside
newDirection = MonsterRandom.Next(2) == 0 ? Direction.Up : Direction.Down;
}
else if ((m.Direction == Direction.Left && xDiff <= -5) || (m.Direction == Direction.Right && xDiff >= 5))
{
newDirection = yDiff > 0 ? Direction.Up : Direction.Down;
}
}
else if (m.Direction == Direction.Up || m.Direction == Direction.Down)
{
if (xDiff == 0 && ShouldMakeMove())
{
// Move aside
newDirection = MonsterRandom.Next(2) == 0 ? Direction.Left : Direction.Right;
}
else if ((m.Direction == Direction.Up && yDiff <= -5) || (m.Direction == Direction.Down && yDiff >= 5))
{
newDirection = xDiff > 0 ? Direction.Left : Direction.Right;
}
}
if (newDirection != Direction.None)
{
TilePos pp = tp.GetPositionAfterOneMove(newDirection);
if (!w.CanTileBeOccupied(pp, true))
newDirection = Direction.None;
}
}
if (newDirection == Direction.None)
{
if (m.Direction == Direction.None)
{
newDirection = MonsterMovement.RandomDirection(m, w);
}
else if (!isCurrentlyMovingTowardsFreeSpace)
{
// tend to bounce backwards
newDirection = MonsterRandom.Next(5) == 0 ? MonsterMovement.GetRandomPerpendicularDirection(m.Direction) : m.Direction.Reversed();
}
else if (MonsterRandom.Next(16) == 0)
{
newDirection = MonsterMovement.GetRandomPerpendicularDirection(m.Direction);
}
else
{
newDirection = m.Direction;
}
}
return newDirection;
}
示例4: UpdateDirectionWhereMovementBlocked
public static Direction UpdateDirectionWhereMovementBlocked(Monster m, World w, Direction d)
{
Direction intendedDirection = d;
TilePos tp = m.TilePosition;
do
{
TilePos potentiallyMovingTowardsTile = tp.GetPositionAfterOneMove(d);
Vector2 potentiallyMovingTowards = potentiallyMovingTowardsTile.ToPosition();
if (m.ChangeRooms == ChangeRooms.StaysWithinRoom && !IsInSameRoom(m.Position, potentiallyMovingTowards))
{
d = GetNextDirection(d);
continue;
}
if (w.CanTileBeOccupied(potentiallyMovingTowardsTile, true))
{
return d;
}
d = GetNextDirection(d);
} while (d != intendedDirection);
return Direction.None;
}