Example #1
0
	// Use this for initialization
	void Start () 
	{
		GameObject mGameObject = GameObject.FindGameObjectWithTag("Music");
		music = mGameObject.GetComponent<Music> ();

		GlobalFlags.resetMultiplier();
		GlobalFlags.setScore(0);
		grid = new triangleNode[20,20];
		gridSize = (int)Mathf.Sqrt(grid.Length);
		gridOutline = new System.Collections.Generic.List<triangleNode>();
		
		for(int i=0; i<gridSize; i++)
		{
			for(int j=0; j<gridSize; j++)
			{
				grid[i,j] = null;
			}
		}

		setNode(0, 0, rootTriangle);

		if(doShowGrid)
		{
			showGrid();
		}
		if(!inEditMode)
		{
			loadLevel(1);
		}
	}
Example #2
0
	// Update is called once per frame
	void Update ()
	{
		if(inEditMode && Input.GetMouseButtonUp(0))
		{
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit hitInfo;
			if(Physics.Raycast(ray,out hitInfo))
			{
				if(hitInfo.collider.gameObject.tag == "gridPanel")
				{
					triangleNode node = findOutlineNode(hitInfo.collider.gameObject.transform.parent.gameObject);
					if(node != null && GetComponent<HandleUI>().IsAdding())
					{
						string c = GetComponent<HandleUI>().GetColourString();
						Vector2 realCoords = getRealCoords(node.x, node.y);
						if(grid[(int)realCoords.x,(int)realCoords.y] == null)
						{
							createTriangleOnGrid(node.x, node.y, c);
						}
					}
				}
				else if(hitInfo.collider.gameObject.tag == "Triangle")
				{
					triangleNode node = getNode(hitInfo.collider.gameObject);
					if(node != null && !GetComponent<HandleUI>().IsAdding()
					   && !(node.x == 0 && node.y == 0))
					{
						Vector2 realCoords = getRealCoords(node.x, node.y);
						grid[(int)realCoords.x,(int)realCoords.y] = null;
						Destroy(hitInfo.collider.gameObject);
					}
				}
			}
		}

		GameObject[] triangles = GameObject.FindGameObjectsWithTag("Triangle");
		GameObject gObject = GameObject.FindGameObjectWithTag("Queue");

		queue queueScript = gObject.GetComponent<queue>();

		if(GlobalFlags.updateControlPoints)			
		{
			updateAllAttractionPoints();
			GlobalFlags.updateControlPoints = false;

			//if all triangles are atatched to grid, let the player fire again
			if(allTrianglesStatic())
			{
				GlobalFlags.trianglesStatic = true;
				if (queueScript.trisLeftInQueue() == 0 && triangles.Length != 1) {
					if(GlobalFlags.getMusicVolume() > 0.1f)
					{
						music.audio.volume = 0.1f;
					}
					music.setSeStartTime(Time.time, 2);
					music.playSoundEffect("gameOver");
					Application.LoadLevel("EndGameMenu");
				}
			}
		}

		if(!inEditMode)
		{
			GameObject[] queueTriangles = GameObject.FindGameObjectsWithTag("QueueTriangle");
			GlobalFlags.setQueueBonusTotal(queueTriangles.Length * GlobalFlags.getQueueBounus());

			//decrement delay time
			if(((elapsedChainDelay > 0 && elapsedChainDelay != float.MaxValue)) && (chainedClusters.Count == 0 || (chainedClusters.Count > 0 && !chainedClusters.Peek().skipDelay)))
			{
				elapsedChainDelay -= Time.deltaTime;
			}
			else if (elapsedChainDelay != float.MaxValue)
			{
				elapsedChainDelay = float.MaxValue;
			
				//if clusters left to deal with, color them and chain more
				if(chainedClusters.Count > 0)
				{
					GlobalFlags.incrementMultiplier();
					CheckForGreaterTriangle(chainedClusters.Pop());
					startChainDelay();
				
				}
				else if(chainedClusters.Count == 0)
				{
		
					foreach (triangleNode n in grid)
					{
						if(n != null && n.delayedDestroy && n.triangleObject.GetComponent<TriangleColour>().GetColour() != Color.black)
						{
							Destroy(n.triangleObject);
							deleteNode(n.x, n.y);
						}
						else if(n != null) // if it is black, set to not deleted
						{
							n.delayedDestroy = false;
						}
					}
					
					//Remove any triangles stranded by this action
					dettatchStranded();
					
					GlobalFlags.updateControlPoints = true;
						
					GlobalFlags.resetMultiplier();	
				}		
			}
			else
			{
				if(triangles.Length == 1)
				{
					if(GlobalFlags.getMusicVolume() > 0.1f)
					{
						music.audio.volume = 0.1f;
					}
					music.setSeStartTime(Time.time, 6);
					music.playSoundEffect("machoMadness");
					if (!GlobalFlags.infiniteRandomMode){ 
						GlobalFlags.setScore(GlobalFlags.getScore() + GlobalFlags.getQueueBounusTotal());
					}
					else {
						GlobalFlags.setScore(GlobalFlags.getScore());
					}
					Application.LoadLevel("PostGameMenu");
				}
			}
		}
	}