예제 #1
0
        // Defines what should happen when balls have been succesfully dispersed
        private static void OnDispersed()
        {
            int index = numberList.GetIndexOfNode(newlyInsertedNode);

            // Check for combo
            // Suggestion for improvement: onderstaande functie een array aanleveren zodat je alleen het deel
            // van de ketting bekijkt waar:
            // - De bal net is ingekomen
            // - De delen die niet door dit deel van de ketting worden aangeraakt
            //   worden niet in acht genomen
            if (numberList.CheckForComboAt(index, target))
            {
                nextBallValue = UnityEngine.Random.Range(NumberList.BOUND_LOW, NumberList.BOUND_HIGH);
            }

            nodeDestroyer.DestroyDeadNodes();

            // Check win condition
            if (numberList.nodeLinkedList.Count == 0)
            {
                UnityEngine.Debug.Log("GUTTER CLEARED! Game won!");
                GameStateManager.SwitchToWon();
                return;
            }

            GetValidTarget();

            // Reset the newly inserted node
            newlyInsertedNode = null;

            // Switch the gamestate to resetting
            GameStateManager.SwitchToResetting();
            ScoreAdd.ReduceScore();
        }
예제 #2
0
        // Handle collision
        public void OnTriggerEnter2D(Collider2D collision)
        {
            NumberNode otherNode = collision.GetComponent <NumberNode>();

            if (otherNode != null)
            {
                // Prevent collision with Preview nodes
                if (otherNode.state == NodeState.PREVIEW || this.state == NodeState.PREVIEW)
                {
                    return;
                }
                // Prevent collision detection with other nodes in gutter
                if (NodeManager.Contains(otherNode))
                {
                    return;
                }
                // Collision happened between this node and the other node,
                // where this node is in the gutter and the other node is in a projectile state
                // So place said the other node into the gutter at the place of this node.
                // Also disable the node motor since it will no longer be used in the gutter.
                otherNode.nodeMotor.enabled = false;
                NodeManager.InsertAtPlaceOf(NodeManager.GetNodes().Find(this), otherNode);
                GameStateManager.SwitchToDispersing();
            }
        }
예제 #3
0
 public static bool Contains(NumberNode node)
 {
     if (numberList.nodeLinkedList.Contains(node))
     {
         return(true);
     }
     return(false);
 }
예제 #4
0
 // Checks whether this bool is touching another node.
 public bool IsTouching(NumberNode otherNode)
 {
     if (otherNode != null)
     {
         if (circleCollider.IsTouching(otherNode.circleCollider))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #5
0
        public static void InsertAtPlaceOf(LinkedListNode <NumberNode> nodeInGutter, NumberNode node)
        {
            // Set the newlyInserted node
            newlyInsertedNode = node;
            // Set it's position and distance travelled accordingly
            float distTravelled = nodeInGutter.Value.pathFollower.distanceTravelled - NumberNode.DIAMETER / 2f;

            newlyInsertedNode.pathFollower.SetDistanceTravelled(distTravelled);
            newlyInsertedNode.transform.position = nodeInGutter.Value.pathFollower.pathCreator.path.GetPointAtDistance(distTravelled);

            // Add it before the node that was already in the gutter
            numberList.nodeLinkedList.AddBefore(nodeInGutter, newlyInsertedNode);
            // Let the gamestate manager know we're now dispersing
            GameStateManager.SwitchToDispersing();
        }
예제 #6
0
 public static void RemoveNode(NumberNode node)
 {
     numberList.nodeLinkedList.Remove(node);
 }
예제 #7
0
 // Newly added nodes are placed in the front of the list,
 // so nodes in the list are ordered like they are on the path
 // (from start to end)
 public static void AddNode(NumberNode node)
 {
     numberList.nodeLinkedList.AddFirst(node);
 }