public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, int gridFactor, Graphics gfx, float opacity) { if (obj.Image == null) { return(false); } Image objImage = orientation.RightImage; if (direction == ObjectDirection.DIRECTION_LEFT) { objImage = orientation.LeftImage; } int sizeX = orientation.GetWidth(direction, gridFactor); int sizeY = orientation.GetHeight(direction, gridFactor); int originX = orientation.GetOriginX(direction, gridFactor); int originY = orientation.GetOriginY(direction, gridFactor); var colourMatrix = new ColorMatrix(); colourMatrix.Matrix33 = opacity; var attributes = new ImageAttributes(); attributes.SetColorMatrix(colourMatrix); // Fix this, scaling on colour map gfx.DrawImage(objImage, new Rectangle( (x * gridFactor) + originX, (y * gridFactor) + originY, sizeX, sizeY), 0, 0, sizeX, sizeY, GraphicsUnit.Pixel, attributes); return(true); }
public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, Graphics gfx) { return(DrawObject(obj, x, y, orientation, direction, Editor.DEFAULT_GRID_FACTOR, gfx)); }
public static bool DrawObject(StarboundObject obj, int x, int y, ObjectOrientation orientation, ObjectDirection direction, int gridFactor, Graphics gfx) { return(DrawObject(obj, x, y, orientation, direction, gridFactor, gfx, 1.0f)); }
// Sets the collision at the provided x- and y- coordinates to match the provided brush // Also handles removing old collisions if the brush is being replaced public void SetCollisionAt(EditorBrush brush, int x, int y, bool updateComposite) { // First, remove the old collision EditorBrush oldBrush = GetBrushAt(x, y); // Remove references based on size if the old brush was an object if (oldBrush != null && oldBrush.FrontAsset != null && oldBrush.FrontAsset is StarboundObject) { StarboundObject sbObject = (StarboundObject)oldBrush.FrontAsset; ObjectOrientation orientation = sbObject.GetCorrectOrientation(m_parent, x, y); int sizeX = orientation.GetWidth(brush.Direction, 1); int sizeY = orientation.GetHeight(brush.Direction, 1); int originX = orientation.GetOriginX(brush.Direction, 1); int originY = orientation.GetOriginY(brush.Direction, 1); for (int j = originX + x; j < sizeX + originX + x; ++j) { for (int k = originY + y; k < sizeY + originY + y; ++k) { HashSet <List <int> > objAnchorSet = GetCollisionsAt(j, k); if (objAnchorSet != null) { // Remove from the set if we have a match objAnchorSet.RemoveWhere(coord => coord[0] == x && coord[1] == y); } } } } // Else just remove the tile we're at else { HashSet <List <int> > tileAnchorSet = GetCollisionsAt(x, y); if (tileAnchorSet != null) { // Remove from the set if we have a match tileAnchorSet.RemoveWhere(coord => coord[0] == x && coord[1] == y); } } // If this tile has a front component, continue if (brush != null && brush.FrontAsset != null) { // Collisions for objects based on size if (brush.FrontAsset is StarboundObject) { var sbObject = (StarboundObject)brush.FrontAsset; ObjectOrientation orientation = sbObject.GetCorrectOrientation(m_parent, x, y); int sizeX = orientation.GetWidth(brush.Direction, 1); int sizeY = orientation.GetHeight(brush.Direction, 1); int originX = orientation.GetOriginX(brush.Direction, 1); int originY = orientation.GetOriginY(brush.Direction, 1); // Set the elements at j, k to point to the anchor at x, y for (int j = originX + x; j < sizeX + originX + x; ++j) { for (int k = originY + y; k < sizeY + originY + y; ++k) { List <int> list = new List <int> { x, y }; AddCollisionAt(list, j, k); } } } // Collisions for non-special front tiles else if (!brush.IsSpecial) { List <int> list = new List <int> { x, y }; AddCollisionAt(list, x, y); } } // Ship brushes have a special flag for things that block // foreground collisions if (brush is ShipBrush && ((ShipBrush)brush).ForegroundBlock) { List <int> list = new List <int> { x, y }; AddCollisionAt(list, x, y); } // If the update composite flag is set, rebuild // the composite collision map. if (updateComposite) { Parent.UpdateCompositeCollisionMap(); } }