Ejemplo n.º 1
0
 public static Node.Direction Opposite(Node.Direction dir)
 {
     if (dir == Node.Direction.RIGHT)
     {
         return(Node.Direction.LEFT);
     }
     else if (dir == Node.Direction.LEFT)
     {
         return(Node.Direction.RIGHT);
     }
     else if (dir == Node.Direction.UP)
     {
         return(Node.Direction.DOWN);
     }
     else if (dir == Node.Direction.DOWN)
     {
         return(Node.Direction.UP);
     }
     else if (dir == Node.Direction.FORWARD)
     {
         return(Node.Direction.BACK);
     }
     else if (dir == Node.Direction.BACK)
     {
         return(Node.Direction.FORWARD);
     }
     else
     {
         Debug.Log("ERROR");
         return(dir);
     }
 }
Ejemplo n.º 2
0
 public static Vector3 GetVectorByDirection(Node.Direction dir)
 {
     if (dir == Node.Direction.RIGHT)
     {
         return(new Vector3(1, 0, 0));
     }
     else if (dir == Node.Direction.LEFT)
     {
         return(new Vector3(-1, 0, 0));
     }
     else if (dir == Node.Direction.UP)
     {
         return(new Vector3(0, 1, 0));
     }
     else if (dir == Node.Direction.DOWN)
     {
         return(new Vector3(0, -1, 0));
     }
     else if (dir == Node.Direction.FORWARD)
     {
         return(new Vector3(0, 0, 1));
     }
     else if (dir == Node.Direction.BACK)
     {
         return(new Vector3(0, 0, -1));
     }
     else
     {
         Debug.Log("ERROR");
         return(Vector3.zero);
     }
 }
Ejemplo n.º 3
0
    public static Node.Direction GetDirectionByVector(Vector3 normal)
    {
        Vector3 localNormal = GameController.Game.LevelController.transform.InverseTransformPoint(normal);

        Node.Direction dir = Node.Direction.UP;
        if (Vector3.SqrMagnitude(localNormal - new Vector3(1, 0, 0)) < 0.1f)
        {
            dir = Node.Direction.RIGHT;
        }
        else if (Vector3.SqrMagnitude(localNormal - new Vector3(-1, 0, 0)) < 0.1f)
        {
            dir = Node.Direction.LEFT;
        }
        else if (Vector3.SqrMagnitude(localNormal - new Vector3(0, 1, 0)) < 0.1f)
        {
            dir = Node.Direction.UP;
        }
        else if (Vector3.SqrMagnitude(localNormal - new Vector3(0, -1, 0)) < 0.1f)
        {
            dir = Node.Direction.DOWN;
        }
        else if (Vector3.SqrMagnitude(localNormal - new Vector3(0, 0, 1)) < 0.1f)
        {
            dir = Node.Direction.FORWARD;
        }
        else if (Vector3.SqrMagnitude(localNormal - new Vector3(0, 0, -1)) < 0.1f)
        {
            dir = Node.Direction.BACK;
        }
        return(dir);
    }
Ejemplo n.º 4
0
 public void OnNodeClick(Node n, Node.Direction dir)
 {
     //if (n.NodeGraphic.GetComponent<Lever>() != null)
     //{
     //    n.NodeGraphic.GetComponent<Lever>().TurnTheLever();
     //}
     //else
     GameController.Game.CurrentLevel.Player.Move(n, dir);
 }
Ejemplo n.º 5
0
    private void MoveToDestNode()
    {
        Node.Direction upDir = Dir.GetDirectionByVector(GameController.Game.CameraController.UpVector);
        if (GameController.Game.CurrentLevel.GetNodeInTheDirection(currentNode, upDir).NodeMember != null)
        {
            GameController.Game.CurrentLevel.GetNodeInTheDirection(currentNode, upDir).NodeMember.NodeObjectGraphic.transform.parent = this.transform;
            GameController.Game.CurrentLevel.MoveMemberLogically(GameController.Game.CurrentLevel.GetNodeInTheDirection(currentNode, upDir), GameController.Game.CurrentLevel.GetNodeInTheDirection(destNode, upDir));

            StartCoroutine(ReturnToLevelParent(GameController.Game.CurrentLevel.GetNodeInTheDirection(destNode, upDir).NodeMember.NodeObjectGraphic.transform));
        }
        GameController.Game.CurrentLevel.MoveObject(currentNode, destNode);
        UpdateState();
    }
Ejemplo n.º 6
0
    private Level DeserializeLevel(LevelData levelData)
    {
        Level level = new Level(levelData.width, levelData.height, levelData.length);

        level.InitializeLevel();
        int x, y, z;

        Node.Direction facing      = Node.Direction.FORWARD;
        Node.Direction upDirection = Node.Direction.UP;

        for (int i = 0; i < levelData.nodeDataList.Count; i++)
        {
            NodeData nodeData = levelData.nodeDataList[i];
            x = nodeData.x;
            y = nodeData.y;
            z = nodeData.z;
            if (nodeData.facing != "" && nodeData.upDirection != "")
            {
                facing      = (Node.Direction) int.Parse(nodeData.facing);
                upDirection = (Node.Direction) int.Parse(nodeData.upDirection);
            }
            level.SetNode(x, y, z, nodeData.id, facing, upDirection);
        }
        for (int i = 0; i < levelData.nodeMemberDataList.Count; i++)
        {
            NodeMemberData nodeMemberData = levelData.nodeMemberDataList[i];
            x = nodeMemberData.x;
            y = nodeMemberData.y;
            z = nodeMemberData.z;
            if (nodeMemberData.facing != "" && nodeMemberData.upDirection != "")
            {
                facing      = (Node.Direction) int.Parse(nodeMemberData.facing);
                upDirection = (Node.Direction) int.Parse(nodeMemberData.upDirection);
            }

            level.AddNodeMember(x, y, z, nodeMemberData.id, facing, upDirection);
        }
        for (int i = 0; i < levelData.nodeConnections.Count; i++)
        {
            level.NodeConnections.Add(levelData.nodeConnections[i]);
        }

        return(level);
    }
Ejemplo n.º 7
0
    private Node FindNodeToFallTo(Node locationNode, Node.Direction dir)
    {
        Node n = GameController.Game.CurrentLevel.GetNodeInTheDirection(locationNode, dir);

        if (n == null)
        {
            isGoingToDie = true;
            return(locationNode);
        }
        nodeCount++;
        if (n.Id == 0)
        {
            if (n.NodeMember != null)
            {
                //n.NodeMember.Destroy();
            }
            return(FindNodeToFallTo(n, dir));
        }
        else
        {
            return(locationNode);
        }
    }
Ejemplo n.º 8
0
 public void OnNodeClick(Node n, Node.Direction dir)
 {
     GameController.Game.LevelDesignController.OnNodeClick(n, dir);
 }
Ejemplo n.º 9
0
    /// <summary>
    /// Move Blocks by User Input.
    /// </summary>
    /// <param name="dir"></param>
    public void MoveTo(Node.Direction dir)
    {
        if (dir == Node.Direction.RIGHT)
        {
            for (int j = 0; j < col; j++)
            {
                for (int i = (row - 2); i >= 0; i--)
                {
                    var node = nodeMap[new Vector2Int(i, j)];
                    if (node.value == null)
                    {
                        continue;
                    }
                    var right = node.FindTarget(node, Node.Direction.RIGHT);
                    if (right != null)
                    {
                        if (node.value.HasValue && right.value.HasValue)
                        {
                            if (node.value == right.value)
                            {
                                Combine(node, right);
                            }
                        }
                        else if (right != null && right.value.HasValue == false)
                        {
                            Move(node, right);
                        }
                        else if (right == null)
                        {
                            return;
                        }
                    }
                }
            }
        }
        if (dir == Node.Direction.LEFT)
        {
            for (int j = 0; j < col; j++)
            {
                for (int i = 1; i < row; i++)
                {
                    var node = nodeMap[new Vector2Int(i, j)];
                    if (node.value == null)
                    {
                        continue;
                    }

                    var left = node.FindTarget(node, Node.Direction.LEFT);
                    if (left != null)
                    {
                        if (node.value.HasValue && left.value.HasValue)
                        {
                            if (node.value == left.value)
                            {
                                Combine(node, left);
                            }
                        }
                        else if (left != null && left.value.HasValue == false)
                        {
                            Move(node, left);
                        }
                    }
                }
            }
        }
        if (dir == Node.Direction.UP)
        {
            for (int j = col - 2; j >= 0; j--)
            {
                for (int i = 0; i < row; i++)
                {
                    var node = nodeMap[new Vector2Int(i, j)];
                    if (node.value == null)
                    {
                        continue;
                    }
                    var up = node.FindTarget(node, Node.Direction.UP);
                    if (up != null)
                    {
                        if (node.value.HasValue && up.value.HasValue)
                        {
                            if (node.value == up.value)
                            {
                                Combine(node, up);
                            }
                        }
                        else if (up != null && up.value.HasValue == false)
                        {
                            Move(node, up);
                        }
                    }
                }
            }
        }
        if (dir == Node.Direction.DOWN)
        {
            for (int j = 1; j < col; j++)
            {
                for (int i = 0; i < row; i++)
                {
                    var node = nodeMap[new Vector2Int(i, j)];
                    if (node.value == null)
                    {
                        continue;
                    }
                    var down = node.FindTarget(node, Node.Direction.DOWN);
                    if (down != null)
                    {
                        if (node.value.HasValue && down.value.HasValue)
                        {
                            if (node.value == down.value)
                            {
                                Combine(node, down);
                            }
                        }
                        else if (down != null && down.value.HasValue == false)
                        {
                            Move(node, down);
                        }
                    }
                }
            }
        }

        foreach (var data in realNodeList)
        {
            if (data.target != null)
            {
                state = State.PROCESSING;
                data.StartMoveAnimation();
            }
        }

        Show();
        if (IsGameOver())
        {
            OnGameOver();
        }
    }
	public void Configure( Cube realCube )
	{
		Transform t = transform.FindChild( "Icon" ).FindChild( "Canvas" );
		if ( t != null )
		{
			canvasAnimator = t.GetComponent<Animator>();
		}

		// Determine start node
		cube = realCube;

		var startNode = cube.Graph.Nodes.Cast<Node>()
			.Single( node => node.Type == NodeTypeEnum.Start );

		transform.position = startNode.Quad.transform.position + -startNode.Quad.transform.forward * 0.01f;

		var meshCenter = GetComponentInChildren<MeshRenderer>().bounds.center;
		var ray = new Ray( meshCenter, -meshCenter.normalized );
		Debug.DrawRay( ray.origin, ray.direction, Color.red, 1000 );
		var hits = Physics.RaycastAll( ray, 1.5f, layerMask )
			.Where( h => h.collider.gameObject.GetComponent<Quad>() != null )
			.Where( h => h.normal.x > hitNormalThreshold )
			.Where( h => h.normal.y > hitNormalThreshold )
			.Where( h => h.normal.z > hitNormalThreshold )
			.ToArray();

		if ( hits.Length == 0 )
		{
			Debug.LogError( "TheGoat is not on a Quad. Dafuq" );
			gameObject.SetActive( false );
			return;
		}

		var hit = hits.First();

		var quad = hit.collider.gameObject.GetComponent<Quad>();

		currentDirection = quad.Node.MoveableDirections.First();

		StartPosition = transform.position;

		Vector3 directionVector = Vector3.zero;
		switch ( currentDirection )
		{
			case Node.Direction.up: directionVector = quad.transform.up; break;
			case Node.Direction.down: directionVector = -quad.transform.up; break;
			case Node.Direction.right: directionVector = quad.transform.right; break;
			case Node.Direction.left: directionVector = -quad.transform.right; break;
		}

		StartRotation = transform.rotation = Quaternion.LookRotation( directionVector, hit.normal );
	}
Ejemplo n.º 11
0
 public void OnNodeClick(Node n, Node.Direction dir)
 {
 }
Ejemplo n.º 12
0
 public void OnNodeClick(Node n, Node.Direction dir)
 {
     GameController.Game.CurrentLevel.Player.Move(n, dir);
 }