public List <CollectableEntityType> Collect(ICollidableEntity collidableEntity) { List <CollectableEntityType> collectedEntityTypes = new List <CollectableEntityType>(); Rectangle collidableBounds = collidableEntity.CollisionBounds; Point[] collidablePixels = collidableEntity.CollisionPixels; Matrix collidableTransformMatrix = collidableEntity.CollisionTransformMatrix; Point[] collidableTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidablePixels, collidableTransformMatrix); foreach (ICollectableEntity collectableEntity in collectableEntities) { if (collectableEntity.CollectionBounds.Intersects(collidableBounds)) { Boolean[,] collectableBooleans = collectableEntity.CollectionBooleans; foreach (Point collectionPixel in collidableTransformedPixels) { Vector2 collectablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel( new Vector2((float)collectionPixel.X, (float)collectionPixel.Y), collectableEntity.CollectionTransformMatrix); Point collectablePoint = new Point((int)collectablePixelVector.X, (int)collectablePixelVector.Y); if (collectablePoint.X >= 0 && collectablePoint.Y >= 0 && collectablePoint.X < collectableBooleans.GetLength(0) && collectablePoint.Y < collectableBooleans.GetLength(1)) { collectedEntityTypes.Add(collectableEntity.CollectionEntityType); collectableEntity.Collected(); break; } } } } return(collectedEntityTypes); }
public List<CollectableEntityType> Collect(ICollidableEntity collidableEntity) { List<CollectableEntityType> collectedEntityTypes = new List<CollectableEntityType>(); Rectangle collidableBounds = collidableEntity.CollisionBounds; Point[] collidablePixels = collidableEntity.CollisionPixels; Matrix collidableTransformMatrix = collidableEntity.CollisionTransformMatrix; Point[] collidableTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidablePixels, collidableTransformMatrix); foreach (ICollectableEntity collectableEntity in collectableEntities) { if (collectableEntity.CollectionBounds.Intersects(collidableBounds)) { Boolean[,] collectableBooleans = collectableEntity.CollectionBooleans; foreach (Point collectionPixel in collidableTransformedPixels) { Vector2 collectablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel( new Vector2((float)collectionPixel.X, (float)collectionPixel.Y), collectableEntity.CollectionTransformMatrix); Point collectablePoint = new Point((int)collectablePixelVector.X, (int)collectablePixelVector.Y); if (collectablePoint.X >= 0 && collectablePoint.Y >= 0 && collectablePoint.X < collectableBooleans.GetLength(0) && collectablePoint.Y < collectableBooleans.GetLength(1)) { collectedEntityTypes.Add(collectableEntity.CollectionEntityType); collectableEntity.Collected(); break; } } } } return collectedEntityTypes; }
public Boolean CheckForCollisionsWith(ICollidableEntity collidableEntity) { Rectangle collidableEntityCollisionBounds = collidableEntity.CollisionBounds; Point[] collidableEntityCollisionPixels = collidableEntity.CollisionPixels; Matrix collidableEntityCollisionTransformMatrix = collidableEntity.CollisionTransformMatrix; Point[] collisionPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidableEntityCollisionPixels, collidableEntityCollisionTransformMatrix); foreach (ICollidableEntity _collidableEntity in collidableEntities) { if (_collidableEntity.CollisionBounds.Intersects(collidableEntityCollisionBounds) && collidableEntity != _collidableEntity) { Boolean[,] collisionBooleans = _collidableEntity.CollisionBooleans; foreach (Point collisionPixel in collisionPixels) { Vector2 _collisionPixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel(new Vector2((float)collisionPixel.X, (float)collisionPixel.Y), _collidableEntity.CollisionTransformMatrix); Point _collisionPixel = new Point((int)_collisionPixelVector.X, (int)_collisionPixelVector.Y); if (_collisionPixel.X >= 0 && _collisionPixel.Y >= 0 && _collisionPixel.X < collisionBooleans.GetLength(0) && _collisionPixel.Y < collisionBooleans.GetLength(1)) { if (collisionBooleans[_collisionPixel.X, _collisionPixel.Y]) { return(true); } } } } } return(false); }
public Boolean CheckForCollisionsWith(ICollidableEntity collidableEntity) { Rectangle collidableEntityCollisionBounds = collidableEntity.CollisionBounds; Point[] collidableEntityCollisionPixels = collidableEntity.CollisionPixels; Matrix collidableEntityCollisionTransformMatrix = collidableEntity.CollisionTransformMatrix; Point[] collisionPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidableEntityCollisionPixels, collidableEntityCollisionTransformMatrix); foreach (ICollidableEntity _collidableEntity in collidableEntities) { if (_collidableEntity.CollisionBounds.Intersects(collidableEntityCollisionBounds) && collidableEntity != _collidableEntity) { Boolean[,] collisionBooleans = _collidableEntity.CollisionBooleans; foreach (Point collisionPixel in collisionPixels) { Vector2 _collisionPixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel(new Vector2((float)collisionPixel.X, (float)collisionPixel.Y), _collidableEntity.CollisionTransformMatrix); Point _collisionPixel = new Point((int)_collisionPixelVector.X, (int)_collisionPixelVector.Y); if (_collisionPixel.X >= 0 && _collisionPixel.Y >= 0 && _collisionPixel.X < collisionBooleans.GetLength(0) && _collisionPixel.Y < collisionBooleans.GetLength(1)) { if (collisionBooleans[_collisionPixel.X, _collisionPixel.Y]) { return true; } } } } } return false; }