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); } } } }
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))); }
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)); } } } }
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)); }
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); }
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)); }
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); }
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); }
public IntRectangle UncastRectangle(IntRectangle rectangle) { return(IntRectangle.FromPositionAndSize(UncastPosition(rectangle.Position), UncastSize(rectangle.Size))); }
public IEnumerable <T> GetAll() { return(base.GetAllWithin(IntRectangle.FromPositionAndSize(IntVector.Zero, SizeVector))); }