コード例 #1
0
        public static IEnumerable <Vector2> GetPositionsRelativeToTarget(this AbilityShape shape)
        {
            var positions      = new List <Vector2>();
            var targetPosition = Vector2.Zero;

            for (var y = 0; y < shape.Size; ++y)
            {
                for (var x = 0; x < shape.Size; ++x)
                {
                    if (shape[y, x] != AbilityShape.EmptyPoint)
                    {
                        if (shape[y, x] == AbilityShape.TargetPoint)
                        {
                            targetPosition = new Vector2(x, y);
                        }
                        else
                        {
                            positions.Add(new Vector2(x, y));
                        }
                    }
                }
            }

            foreach (var position in positions)
            {
                yield return(new Vector2(position.X - targetPosition.X, position.Y - targetPosition.Y));
            }
            yield return(Vector2.Zero);
        }
コード例 #2
0
        public static int ActiveCellCount(this AbilityShape shape)
        {
            var count = 0;

            for (var y = 0; y < shape.Size; ++y)
            {
                for (var x = 0; x < shape.Size; ++x)
                {
                    if (shape[y, x] != AbilityShape.EmptyPoint)
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
コード例 #3
0
        public static AbilityShape Rotate90(this AbilityShape shape)
        {
            var result = new byte[shape.Size, shape.Size];

            for (var y = 0; y < shape.Size; ++y)
            {
                for (var x = 0; x < shape.Size; ++x)
                {
                    result[y, x] = shape.ShapeData[shape.Size - x - 1, y];
                }
            }

            var newDirection = (byte)(shape.FacingDirection + 1);

            if (newDirection > DirectionTypes.Left)
            {
                newDirection = DirectionTypes.Up;
            }
            return(new AbilityShape(shape.Size, result, newDirection));
        }
コード例 #4
0
 public HasEnemiesInShapeModifier(Level level, AbilityShape shape)
 {
     Level = level;
     Shape = shape;
     _maxTargetableCount = Shape.ActiveCellCount();
 }
コード例 #5
0
 public static AbilityShape Rotate180(this AbilityShape shape)
 {
     return(Rotate90(Rotate90(shape)));
 }
コード例 #6
0
        public static IEnumerable <Vector2> GetLocationsFromShape(this Vector2 position, AbilityShape shape)
        {
            var relativePositions = shape.GetPositionsRelativeToTarget();

            foreach (var relativePosition in relativePositions)
            {
                yield return(position + relativePosition);
            }
        }
コード例 #7
0
        public static int CountUnitsInShape(this Level level, Vector2 targetPosition, AbilityShape shape,
                                            bool aliveOnly = true)
        {
            var allUnits = GetAllUnitsInShape(level, targetPosition, shape);

            return(aliveOnly ? allUnits.ThatAreAlive().Count() : allUnits.Count());
        }
コード例 #8
0
        public static IEnumerable <GameUnit> GetAllUnitsInShape(this Level level, Vector2 targetPosition, AbilityShape shape)
        {
            var targetPositions = targetPosition.GetLocationsFromShape(shape);

            foreach (var position in targetPositions)
            {
                var possibleUnit = GetUnitAt(level, position);
                if (possibleUnit != null)
                {
                    yield return(possibleUnit);
                }
            }
        }