public static CellCoordinates Find1x1OffsetRight(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates coords = _coordinates; switch (_orientation) { case ObjectOrientation.Or0: { coords.X += 1; break; } case ObjectOrientation.Or90: { coords.Y -= 1; break; } case ObjectOrientation.Or180: { coords.X -= 1; break; } case ObjectOrientation.Or270: { coords.Y += 1; break; } } return(coords); }
private static CellCoordinates[] FindOutputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates output1 = GridObjectOrientationHelper.Find1x1OffsetRight(_coordinates, _orientation); CellCoordinates output2 = GridObjectOrientationHelper.Find1x1OffsetDown(_coordinates, _orientation); return(new CellCoordinates[] { output1, output2 }); }
private static CellCoordinates[] FindInputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates input1 = GridObjectOrientationHelper.Find1x1OffsetLeft(_coordinates, _orientation); CellCoordinates input2 = GridObjectOrientationHelper.Find1x1OffsetUp(_coordinates, _orientation); return(new CellCoordinates[] { input1, input2 }); }
public InputCell(CellCoordinates _coordinates, ObjectOrientation _orientation, int _value) : base(GridObjectType.Input, FindFootprint(_coordinates, _orientation)) { CurrentValues = new int[1]; InputValue = _value; Exit = GridObjectOrientationHelper.Find1x1OffsetRight(_coordinates, _orientation); }
public OutputCell(CellCoordinates _coordinates, ObjectOrientation _orientation, int _target) : base(GridObjectType.Output, FindFootprint(_coordinates, _orientation)) { CurrentValues = new int[1]; OutputTarget = _target; Entry = GridObjectOrientationHelper.Find1x1OffsetLeft(_coordinates, _orientation); }
private void ChangeDirection() { directionChangeCountdown = Counter.NewStarted(random.Next(50, 350)); currentOrientation = ObjectOrientation.RandomInDirectionOfOrNeutral( random, headingOrientation.HorizontalVector); }
public override void Deserialize(Stream stream, GameStateSerializer serializer) { animationCountdown = stream.ReadStruct <Counter>(); animationIndex = stream.ReadStruct <Counter>(); directionChangeCountdown = stream.ReadStruct <Counter>(); currentOrientation = stream.ReadStruct <ObjectOrientation>(); headingOrientation = stream.ReadStruct <ObjectOrientation>(); base.Deserialize(stream, serializer); }
public static CellCoordinates Find1x1OffsetUp(CellCoordinates _coordinates, ObjectOrientation _orientation) { int orientation = (int)_orientation; orientation += 3; orientation = orientation % (int)ObjectOrientation.SIZE; return(Find1x1OffsetRight(_coordinates, (ObjectOrientation)orientation)); }
public override void Interact(CharacterInteraction tar) { if (orb == null) { orb = GetComponent <ObjectOrientation>(); } needsMovingToHandle = true; base.Interact(tar); }
public WalkingPenguin( ObjectOrientation orientation, Point location, PenguinStats stats) : base( location, stats) { currentOrientation = orientation; headingOrientation = orientation; }
private static CellCoordinates[] FindInputs(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates[] footprint = GridObjectOrientationHelper.Find2x1Footprint(_coordinates, _orientation); CellCoordinates[] inputs = new CellCoordinates[footprint.Length]; for (uint i = 0; i < footprint.Length; ++i) { inputs[i] = GridObjectOrientationHelper.Find1x1OffsetLeft(footprint[i], _orientation); } return(inputs); }
public void Rotate(bool _clockwise) { // Update orientation int or = (int)objectOrientation; or = _clockwise ? or + 1 : or - 1; or = or % (int)ObjectOrientation.SIZE; objectOrientation = (ObjectOrientation)or; // Do visual rotation RectTransform trans = GetComponent <RectTransform>(); if (_clockwise) { trans.Rotate(new Vector3(0, 0, -90)); } else { trans.Rotate(new Vector3(0, 0, 90)); } }
public static bool DrawForegroundBetween(List <EditorMapLayer> layers, int xmin, int ymin, int xmax, int ymax, int gridFactor, Graphics gfx) { if (layers == null || layers.Count == 0) { return(false); } foreach (EditorMapLayer layer in layers) { for (int x = xmin; x < xmax; ++x) { for (int y = ymin; y < ymax; ++y) { // Get the brush located at the provided x- and y-coordinates EditorBrush brush = layer.GetBrushAt(x, y); // If the brush is null, or no front asset is needed for this brush if (brush == null || !brush.NeedsFrontAsset || brush.FrontAsset == null) { continue; } if (brush.BrushTypes.Contains("object")) { var obj = (StarboundObject)brush.FrontAsset; ObjectOrientation orientation = obj.GetCorrectOrientation(layers[0].Parent, x, y); DrawObject(obj, x, y, orientation, brush.Direction, gridFactor, gfx); } else if (brush.BrushTypes.Contains("front")) { DrawForegroundTile((StarboundTile)brush.FrontAsset, x, y, gridFactor, gfx); } } } } return(true); }
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 void ResetBase() { objectOrientation = ObjectOrientation.Or0; RectTransform trans = GetComponent <RectTransform>(); trans.rotation = Quaternion.identity; localScale = 1.0f; GetComponent <RectTransform>().localScale = Vector2.one * localScale; for (int i = 1; i <= 2; i++) { if (transform.Find("InConnector_" + i) != null) { transform.Find("InConnector_" + i).gameObject.SetActive(true); } if (transform.Find("OutConnector_" + i) != null) { transform.Find("OutConnector_" + i).gameObject.SetActive(true); } } }
private static CellCoordinates[] FindFootprint(CellCoordinates _coordinates, ObjectOrientation _orientation) { return(GridObjectOrientationHelper.Find2x1Footprint(_coordinates, _orientation)); }
public CrossGate(CellCoordinates _coordinates, ObjectOrientation _orientation) : base(FindFootprint(_coordinates, _orientation), FindInputs(_coordinates, _orientation), FindOutputs(_coordinates, _orientation), GateType.Cross) { }
protected override void OnPaint(PaintEventArgs e) { if (m_image == null) { return; } e.Graphics.PixelOffsetMode = PixelOffsetMode.Half; e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; // Identity matrix var trans = new Matrix(); // Uniform scale by zoom factor trans.Scale(m_zoomFactor, m_zoomFactor, MatrixOrder.Append); // Translate to the correct image location trans.Translate(m_imageX, m_imageY, MatrixOrder.Prepend); // Set the graphics transformation matrix e.Graphics.Transform = trans; // Draw the image in the world e.Graphics.DrawImage(m_image, 0, 0, m_image.Width, m_image.Height); // Draw border if (m_gridFactor > 1) { ControlPaint.DrawBorder( e.Graphics, new Rectangle( 0, 0, m_image.Width, m_image.Height), SystemColors.ControlDarkDark, ButtonBorderStyle.Dashed); } // Only proceed if the mouse is in bounds, and there is a selected asset // If so, draw the preview image of the currently selected brush if (m_selectedAsset != null && m_selectedAsset.Image != null && m_mouseGridX != -1 && m_mouseGridY != -1) { if (m_selectedAsset is StarboundObject) { ObjectOrientation orientation = ((StarboundObject)m_selectedAsset).GetCorrectOrientation(m_parent.SelectedMap, m_mouseGridX, m_mouseGridY); Renderer.DrawObject( (StarboundObject)m_selectedAsset, m_mouseGridX, m_mouseGridY, orientation, m_selectedBrush.Direction, m_gridFactor, e.Graphics, 0.5f); } else if (m_selectedAsset is StarboundTile) { Renderer.DrawForegroundTile( (StarboundTile)m_selectedAsset, m_mouseGridX, m_mouseGridY, m_gridFactor, e.Graphics, 0.5f); } else { e.Graphics.DrawImage(m_selectedAsset.Image, m_mouseGridX * 8, m_mouseGridY * 8, 8, 8); } } }
public static CellCoordinates[] Find2x1Footprint(CellCoordinates _coordinates, ObjectOrientation _orientation) { CellCoordinates coords = Find1x1OffsetDown(_coordinates, _orientation); return(new CellCoordinates[] { _coordinates, coords }); }
internal GameObjectBuilder SetOrientation(ObjectOrientation orientation) { _orientation = orientation; return(this); }
private readonly int _angle; // Question, is it possible to allow more than one angle? #endregion #region constructor /// <summary> /// Create a new orientation. /// </summary> /// <param name="constraint">Constraint type.</param> /// <param name="angle">Angle.</param> public COrientation(ObjectOrientation constraint, int angle) { _constraint = constraint; _angle = angle; }
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 void AddGate(GateType _type, CellCoordinates _coordinates, ObjectOrientation _orientation, GameObject _selfGameObject, int _value = 0, bool _isSwap = false) { //Check if an object is already there GridObject gridObject = gridManager.GetCell(_coordinates); if (gridObject != null) { ClearCell(_coordinates, _isSwap); gridObject = null; } switch (_type) { case GateType.Add: { gridObject = new AddGate(_coordinates, _orientation); break; } case GateType.Subtract: { gridObject = new SubtractGate(_coordinates, _orientation); break; } case GateType.Multiply: { gridObject = new MultiplyGate(_coordinates, _orientation); break; } case GateType.Divide: { gridObject = new DivideGate(_coordinates, _orientation); break; } case GateType.IncrementDecrement: { gridObject = new IncrementDecrementGate(_coordinates, _orientation, _value); break; } case GateType.Cross: { gridObject = new CrossGate(_coordinates, _orientation); break; } case GateType.Replicate: { gridObject = new ReplicateGate(_coordinates, _orientation); break; } } gridManager.InsertObject(gridObject); placedGridObjects.Add(gridObject, _selfGameObject); //Create Visual Wire Gate gate = (Gate)gridObject; uint index = 0; foreach (CellCoordinates inputCoords in gate.Inputs) { GridObject inputGridObject = gridManager.GetCell(inputCoords); if (inputGridObject != null) { if (inputGridObject.ObjectType != GridObjectType.Wire) { if (IsConnected(false, inputCoords, gridObject)) { wireVisualManager.CreateWireAndLink(inputCoords, gate.GetCoordinateForInput(index)); } } } index++; } index = 0; foreach (CellCoordinates outputCoords in gate.Outputs) { GridObject outputGridObject = gridManager.GetCell(outputCoords); if (outputGridObject != null) { if (outputGridObject.ObjectType != GridObjectType.Wire) { if (IsConnected(true, outputCoords, gridObject)) { wireVisualManager.CreateWireAndLink(_coordinates, outputCoords); } } } index++; } UpdateGiblets(_coordinates, true); }
public MultiplyGate(CellCoordinates _coordinates, ObjectOrientation _orientation) : base(FindFootprint(_coordinates, _orientation), FindInputs(_coordinates, _orientation), FindOutputs(_coordinates, _orientation), GateType.Multiply) { }
public static CellCoordinates[] Find1x1Footprint(CellCoordinates _coordinates, ObjectOrientation _orientation) { return(new CellCoordinates[] { _coordinates }); }
// Static creation methods. /// <summary> /// Create a fixed orientation. /// </summary> public static COrientation CreateOrientation(ObjectOrientation obj, int ob) { return(new COrientation(obj, 0)); }
// 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(); } }
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)); }
public SubtractGate(CellCoordinates _coordinates, ObjectOrientation _orientation) : base(FindFootprint(_coordinates, _orientation), FindInputs(_coordinates, _orientation), FindOutputs(_coordinates, _orientation), GateType.Subtract) { }
public IncrementDecrementGate(CellCoordinates _coordinates, ObjectOrientation _orientation, int _amount = 1) : base(FindFootprint(_coordinates, _orientation), FindInputs(_coordinates, _orientation), FindOutputs(_coordinates, _orientation), GateType.IncrementDecrement) { m_amount = _amount; }