Exemplo n.º 1
0
	public void AddConnectedPlanet (PregenPlanet pc, PregenVine v)
	{
		connectedPlanets.Add (pc);
		if (planetType != "travelPlanet") {
			pc.connectedPlanets.Add (this);
		}
		if (pc.planetType == "travelPlanet" && planetType == "travelPlanet") {
			pc.connectedPlanets.Add (this);
		}

		vines [pc] = v;
		pc.vines [this] = v;
	}
Exemplo n.º 2
0
	// Update is called once per frame
	void Update () {
		if (vine != null)
		{
			line1.transform.position = gameObject.transform.position;
			line1.SetPosition(0, vine.ends[0].gameObject.transform.position);
			line1.SetPosition(2, vine.ends[1].gameObject.transform.position);

			var temp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
			temp.z = 1f;
			line1.SetPosition(1, temp);
		}

		if (Input.GetMouseButtonUp(0))
		{
			if (vine != null)
			{

				CameraPanningScript.Enable();

				//show the vine
				vine.gameObject.GetComponent<SpriteRenderer>().enabled = true;

				//turn collisions on again
				vine.colliderOnAgainTime = Time.time + .5f;

				//destroy the lines
				GameObject.Destroy(line1);
				line1 = null;

				Vector3 dir = vine.gameObject.transform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition);
				OnDragRelease(dir);

				//Debug.Log ("Releasing vine: " + vine.gameObject.name + " at dir: " + dir);

				vine = null;
			}
		}


		if (dragging && vine != null)
		{
			var mP = ClickToDrag.GetCursorWorldLocation();

			var pp1 = vine.ends[0].gameObject.transform.position;

			var pp2 = vine.ends[1].gameObject.transform.position;

			for (int i = 0; i < vine.seedizens.Count; ++i)
			{
				var seedizen = vine.seedizens[i];
				if (seedizen == null || seedizen.gameObject == null)
				{
					continue;
				}
				if (i >= vinePercentagePositions.Count)
				{
					Debug.Log("The system of coordinating positions on lists stored on multiple classes has failed!!! Consider storing this data on the seedizens");
					continue;
				}
				var perc = vinePercentagePositions[i];
				if (perc < clickStartPercentage)
				{
					var halfPer = perc / clickStartPercentage;
					//Debug.Log ("proportional percentage: "+halfPer);
					seedizen.transform.position = halfPer * (mP - pp1) + pp1;

				}
				else {
					var halfPer = (perc - clickStartPercentage) / (1 - clickStartPercentage);
					//Debug.Log ("proportional percentage past cursor: "+halfPer);
					seedizen.transform.position = halfPer * (pp2 - mP) + mP;

				}
			}

			UpdateFlingArrow();
		}

	}
Exemplo n.º 3
0
	// Update is called once per frame
	void Update ()
	{
		//get mouse position
		Vector3 mousePos = MathTools.ScreenToWorldPosition (Input.mousePosition);
		if (VineDragPlanet != null) {
			if (Vector3.Distance (mousePos, startPos) > VineDragPlanet.maxDragDist
			    || (currentPlanetByMouse != null
			    && (!currentPlanetByMouse.CanConnectVine () || currentPlanetByMouse.connectedPlanets.Contains (VineDragPlanet)))) {
				vine.GetComponent<SpriteRenderer> ().material.color = vineInvalidColor;
			} else {
				if (vineVisible) {
					vineBaseColor.a = 1f;
					vine.GetComponent<SpriteRenderer> ().material.color = vineBaseColor;
				} else {
					vineBaseColor.a = .5f;
					vine.GetComponent<SpriteRenderer> ().material.color = vineBaseColor;
				}
			}
		}


		bool end = false;
		bool destroy = false;

		if (Input.GetMouseButtonUp (0)) {
			if (VineDragPlanet != null) {
				if (currentPlanetByMouse == null
				    || currentPlanetByMouse.connectedPlanets.Contains (VineDragPlanet)
				    || currentPlanetByMouse == VineDragPlanet
				    || !currentPlanetByMouse.CanConnectVine ()
				    || Vector3.Distance (mousePos, startPos) > VineDragPlanet.maxDragDist) {//|| !vine.IsNotColliding ()) {
					destroy = true;
				} else {
					mousePos = currentPlanetByMouse.transform.position;
					OnFlowerDragSuccessfulEnd ();
				}

				end = true;
			}
		}

		//limit their distance
		//var dif = mousePos - startPos;
		//if (flower != null && dif.magnitude > flower.maxDragDist)
		//mousePos = startPos + dif.normalized * flower.maxDragDist;

		if (VineDragPlanet != null) {
			PlaceVine (startPos, mousePos, vine.gameObject);
			/*
			//position the vine between the two points
			Vector3 pos = (startPos + mousePos) / 2f;
			pos.z = .1f;
			vine.gameObject.transform.position = pos;

			//vine facing
			Vector3 dir = mousePos - startPos;
			var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
			vine.gameObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

			//vine stretching
			var scale = vine.gameObject.transform.localScale;
			scale.x = dir.magnitude / 8f;
			scale.y = 2f;
			//Debug.Log (mousePos + " " + startPos + " " + dir.magnitude);
			vine.gameObject.transform.localScale = scale;*/
		}

		if (destroy) {
			GameObject.Destroy (vine.gameObject);
		}
		if (end) {
			VineDragPlanet = null;
			vine = null;
			CameraPanningScript.Enable ();
		}
	}
Exemplo n.º 4
0
	public static void StartVineDrag(PregenVine vc)
	{
		CameraPanningScript.Disable();
		vine = vc;

		dragging = true;
		clickStartPosition = ClickToDrag.GetCursorWorldLocation();
		//var sph = GameObject.CreatePrimitive (PrimitiveType.Sphere);
		//sph.transform.position = clickStartPosition;


		startDragPositions.Clear();
		vinePercentagePositions.Clear();
		releasePositions.Clear();
		var vineVector = vine.ends[1].gameObject.transform.position - vine.ends[0].gameObject.transform.position;
		clickStartPercentage = (clickStartPosition - vine.ends[0].gameObject.transform.position).magnitude / vineVector.magnitude;
		//Debug.Log ("click percentage: " + clickStartPercentage);
		foreach (var seedizen in vine.seedizens)
		{
			if (seedizen == null || seedizen.gameObject == null)
			{
				Debug.Log("null seedizen");
				continue;
			}
			seedizen.inTransit = false;

			startDragPositions.Add(seedizen.transform.position);
			vinePercentagePositions.Add((seedizen.transform.position - vine.ends[0].gameObject.transform.position).magnitude / vineVector.magnitude);
		}

		//create some lines
		var l1 = GameObject.Instantiate(instance.linePrefab) as GameObject;
		line1 = l1.GetComponent<LineRenderer>();

		//hide the vine
		vc.gameObject.GetComponent<SpriteRenderer>().enabled = false;

		//turn off collisions
		vc.gameObject.GetComponent<Collider2D>().enabled = false;

		MakeFlingArrow();

	}
Exemplo n.º 5
0
	public static void StartDrag (VinePlanet flo, bool isVisible)
	{
		if (flo == null || flo.gameObject == null) {
			Debug.Log ("ERRORS");
			return;
		}

		if (flo.numBridges <= 0) {
			Debug.Log ("Insufficient bridges");
			return;
		}

		CameraPanningScript.Disable ();
		VineDragPlanet = flo;

		vineVisible = isVisible;
		var v = GameObject.Instantiate (instance.vinePrefab);
		vine = v.GetComponent <PregenVine> ();
		if (VineDragPlanet.planetType == "travelPlanet")
			vine.travelVine = true;
		else
			vine.travelVine = false;
		vine.ends.Add (VineDragPlanet);
		vine.flowerPlanet = VineDragPlanet;
		VineDragPlanet.spawnedVines.Add (vine);
		VineDragPlanet.travelVine = vine;
		vine.gameObject.transform.SetAsFirstSibling ();
		startPos = flo.gameObject.transform.position;
	}
Exemplo n.º 6
0
	void AttachToVine (PregenVine vc) {
		EndFlight ();
		currentVine = vc;
		if (!vc.seedizens.Contains (this))
			vc.seedizens.Add (this);
		GoToRandomNeighbor (vc);
	}
Exemplo n.º 7
0
	public void GoToRandomNeighbor (PregenVine vine) {
		if (vine == null)
			return;
		if (vine.ends.Count < 2) {
			Debug.Log ("Weird vine collision");
			return;
		}
		PregenPlanet dest;
		if (Random.Range (0, 2) == 0)
			dest = vine.ends [0];
		else
			dest = vine.ends [1];
		destinationPlanet = dest;
	}
Exemplo n.º 8
0
	/// <summary>
	/// It's assumed this will only be called when they're at the planet
	/// </summary>
	public void GoToRandomNeighbor (PregenPlanet planet) {
		if (planet == null)
			return;
		planet.ProcessSeedizen (this);
		//		var oldPlanet = planet;
		/*var options = new List <PregenPlanet> (planet.connectedPlanets);
		foreach (var p in planet.connectedPlanets)
			if (planet.vines [p].dispreferred)
				options.Remove (p);
		if (options.Count == 0) {
			destinationPlanet = null;
			return;
		}
		destinationPlanet = options [Random.Range (0, options.Count)];*/
		destinationPlanet = PregenPathfinding.GetDirection (planet, this);
		if (destinationPlanet == null)
			return;
		var oldVine = currentVine;
		if (destinationPlanet == null)
			return;
		currentVine = destinationPlanet.vines [planet];
		if (oldVine != null)
			oldVine.seedizens.Remove (this);
		if (!currentVine.seedizens.Contains (this))
			currentVine.seedizens.Add (this);
		idealAngle = 0f;
	}
Exemplo n.º 9
0
	public void StartFlight (Vector3 dir) {
		Debug.Log (dir);
		Vector2 dir2d = dir;

		flying = true;
		inTransit = false;
		if (currentVine != null)
			currentVine.seedizens.Remove (this);
		currentPlanet = null;
		destinationPlanet = null;
		currentVine = null;
		//flightDir = dir;

		//Debug.Log (this);
		//Debug.Log (gameObject);

		var rigid = gameObject.GetComponent <Rigidbody2D> ();
		rigid.gravityScale = 1f;


		rigid.AddForce (dir2d.normalized * Mathf.Sqrt (dir2d.magnitude) * 500f);
	}