예제 #1
0
        public void TryConnectWireFromCharacter(GridCell batteryCell, GridCell wireCell, CharacterBase character)
        {
            if (character.CanConnectViaCell(wireCell))
            {
                var posDiff = batteryCell.GridPos - wireCell.GridPos;
                posDiff.Normalize();

                Direction direction = Direction.None;
                if (posDiff == Vector2.right)
                {
                    direction = Direction.Right;
                }
                else if (posDiff == Vector2.left)
                {
                    direction = Direction.Left;
                }
                else if (posDiff == Vector2.down)
                {
                    direction = Direction.Top;
                }
                else if (posDiff == Vector2.up)
                {
                    direction = Direction.Bottom;
                }

                if (direction != Direction.None)
                {
                    var wirePiece = wireCell.DrawableBase as WirePiece;
                    wirePiece.AddConnectionOnGrid(direction, character.PositionOnGrid);
                    wirePiece.UpdateConnections();

                    character.AddConnection(wirePiece);
                }
            }
        }
예제 #2
0
        public bool TryConnectToCharacterOverBridge(GridCell cell, GridCell bridge, CharacterBase character, bool userConnection = true)
        {
            if (character.CanConnectViaCell(bridge))
            {
                var posDiff = cell.GridPos - bridge.GridPos;
                posDiff.Normalize();

                Direction direction = Direction.None;
                if (posDiff == Vector2.right)
                {
                    direction = Direction.Right;
                }
                else if (posDiff == Vector2.left)
                {
                    direction = Direction.Left;
                }
                else if (posDiff == Vector2.down)
                {
                    direction = Direction.Top;
                }
                else if (posDiff == Vector2.up)
                {
                    direction = Direction.Bottom;
                }

                if (direction != Direction.None)
                {
                    PreviousSelectedWirePiece.AddConnectionOnGrid(direction, character.PositionOnGrid);
                    PreviousSelectedWirePiece.UpdateConnections();

                    character.AddConnection(PreviousSelectedWirePiece);
                }

                if (userConnection)
                {
                    PreviousSelectedWirePiece = null;
                }

                return(true);
            }

            if (userConnection)
            {
                PreviousSelectedWirePiece = null;
            }

            return(false);
        }