コード例 #1
0
        public void DetectTouchedBlocks(ICollisionEngineContext context, IMovableObject checkedObject)
        {
            checkedObject.TouchedObjects.Clear();

            var areaToCheck = IntRectangle.FromPositionAndSize(checkedObject.Position, checkedObject.Size).Extend(Constants.BlockSize);

            var checkedObjBounds = checkedObject.Bounds;

            foreach (var obj in context.GetCollidableObjectsWithin(areaToCheck))
            {
                if (obj == checkedObject)
                {
                    continue;
                }

                if (obj.IsSolid)
                {
                    var objBounds = CoordinateSystem.Denormalize(obj.Bounds, checkedObjBounds);

                    if (checkedObjBounds.TryGetTouchedSide(objBounds, out var touchedSide))
                    {
                        checkedObject.TouchedObjects[touchedSide].Add(obj);
                    }
                }
            }
        }
コード例 #2
0
 public static IntRectangle Denormalize(this ICoordinateSystem coordinateSystem, IntVector position, IntVector size, IntVector referencePosition, IntVector referenceSize)
 {
     // TODO: consider size
     return(coordinateSystem.Denormalize(
                IntRectangle.FromPositionAndSize(position, size),
                IntRectangle.FromPositionAndSize(referencePosition, referenceSize)));
 }
コード例 #3
0
        public void RemoveBlock(IntVector positionOfBlockToRemove)
        {
            var areaAroundBlock = IntRectangle.FromPositionAndSize(positionOfBlockToRemove, IntVector.RightDown * Constants.BlockSize).Extend(Constants.BlockSize);

            foreach (var grid in Grids)
            {
                var removedBlock = grid.SetBlock(positionOfBlockToRemove, null);

                if (removedBlock == null)
                {
                    continue;
                }

                // var removedBlockBounds = IntRectangle.FromPositionAndSize(positionOfBlockToRemove, Constants.PhysicsUnitVector);

                foreach (var block in grid.GetAllWithin(areaAroundBlock))
                {
                    if (block != null && block != removedBlock)
                    {
                        // var blockBounds = IntRectangle.FromPositionAndSize(position, Constants.PhysicsUnitVector);
                        block.OnNeighborChanged(
                            this,
                            new BlockInWorld <Block>(block, grid, positionOfBlockToRemove));
                    }
                }
            }
        }
コード例 #4
0
        public IntRectangle GetBlockBounds(IntVector position)
        {
            position = position - Position;
            var blockPosition = position.Floor(Constants.BlockSize);

            blockPosition = CoordinateSystem.Normalize(blockPosition);
            return(IntRectangle.FromPositionAndSize(Position + blockPosition, Constants.BlockSizeVector));
        }
コード例 #5
0
        private void RenderBackgroundBlocks(DrawingContext dc, IntRectangle visibleArea, Camera camera)
        {
            var visibleAreaPosition = visibleArea.Position;

            visibleAreaPosition.Z = Constants.BlockSize;
            var visibleAreaSize = visibleArea.Size;

            visibleAreaSize.Z = Constants.BlockSize;
            RenderGrids(dc, IntRectangle.FromPositionAndSize(visibleAreaPosition, visibleAreaSize), camera);
        }
コード例 #6
0
        public IEnumerable <Block> GetAllWithin(IntRectangle rectangle)
        {
            var transformedRectangle = rectangle.Move(-Position);

            transformedRectangle = IntRectangle.FromPositionAndSize(
                transformedRectangle.Position.DivideRoundDown(Constants.BlockSize),
                transformedRectangle.Size.DivideRoundUp(Constants.BlockSize)
                );

            return(InnerGrid.GetAllWithin(transformedRectangle));
        }
コード例 #7
0
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            if (ApplicationViewModel?.WorldController == null)
            {
                return;
            }

            var camera   = ApplicationViewModel.World.Camera;
            var viewport = GetViewport();

            camera.Viewport = viewport;
            camera.Position = ApplicationViewModel.Player.Position + IntVector.Up * Constants.BlockSize;

            var visibleArea = camera.UncastRectangle(IntRectangle.FromPositionAndSize(IntVector.Zero, viewport))
                              .Extend(new IntVector(2 * Constants.BlockSize, Constants.BlockSize, 0));

            RenderBackgroundBlocks(dc, visibleArea, camera);
            RenderEntities(dc, visibleArea, camera);
            RenderItems(dc);
            RenderForegroundBlocks(dc, visibleArea, camera);
            RenderHoveredBlockEffect(dc);
        }
コード例 #8
0
 public BlockInWorld(TBlock obj, Grid grid, IntVector position)
 {
     Object = obj ?? throw new ArgumentNullException(nameof(obj));
     Grid   = grid ?? throw new ArgumentNullException(nameof(grid));
     Bounds = IntRectangle.FromPositionAndSize(position, Constants.BlockSizeVector);
 }
コード例 #9
0
 public IntRectangle UncastRectangle(IntRectangle rectangle)
 {
     return(IntRectangle.FromPositionAndSize(UncastPosition(rectangle.Position), UncastSize(rectangle.Size)));
 }
コード例 #10
0
 public IEnumerable <T> GetAll()
 {
     return(base.GetAllWithin(IntRectangle.FromPositionAndSize(IntVector.Zero, SizeVector)));
 }