Ejemplo n.º 1
0
	private void CreateEnemy(MountainChunk mountainChunk, float linePosition) {
		MountainEnemy enemy = enemyPrefab.Spawn();
		enemy.transform.parent = transform;
		enemy.transform.localPosition = Vector3.zero;
		enemy.SetMountainChunk(mountainChunk);
		enemy.SetExactLinePosition(linePosition);
	}
Ejemplo n.º 2
0
	private void HandleMountainChunkGenerated(MountainChunk mountainChunk) {
		float linePosition = Random.Range(0.03f, 0.1f);
		for (int i = 0; i < 9; i++) {
			CreateEnemy(mountainChunk, linePosition);
			linePosition += Random.Range(0.02f, 0.1f);
		}
	}
Ejemplo n.º 3
0
	// ============= PUBLICS ==============
	public void Initialize(Vector2 origin, MountainChunk previousMountainChunk, MountainChunkAttributes attributes) {
		this.origin = origin;
		this.previousMountainChunk = previousMountainChunk;
		this.attributes = attributes;

		Generate();
	}
	public bool NeedsNewMountainChunk(MountainChunk lastMountainChunk) {
		return lastMountainChunk.GetFirstEdgePoint().x <= ScreenUtility.instance.maxX;
	}
Ejemplo n.º 5
0
	private void GenerateShape(List<Vector2> points, MountainChunk mountainChunk, GroundChunk previousGroundChunk, float distanceFromMountain) {
		float directDistFromMountain = distanceFromMountain;
		Vector2 mountainVector = mountainChunk.GetLastEdgePoint().vector - mountainChunk.GetFirstEdgePoint().vector;
		Vector2 slopePerp = new Vector2(slopeVector.y, -slopeVector.x);
		int numPoints = mountainChunk.edgePoints.Count;
		float totalDistance = mountainVector.magnitude;
		float distPerPoint = totalDistance / (numPoints - 1);
		float angleFromMountain = Vector2.Angle(Vector2.down, slopePerp * directDistFromMountain);
		float verticalDistFromMountain = directDistFromMountain / Mathf.Cos(angleFromMountain * Mathf.Deg2Rad);
		Vector2 verticalVectorFromMountain = new Vector2(0, -verticalDistFromMountain);

		Vector2 origin = mountainChunk.GetFirstEdgePoint().vector + verticalVectorFromMountain;
		Vector2 prevPoint = origin;
		points.Add(prevPoint);

		for (int i = 0; i < numPoints; i++) {
			Vector2 delta = slopeVector * distPerPoint;
			Vector2 point = prevPoint + delta;
			points.Add(point);
			prevPoint = point;
		}

		// make the first point of any new chunk the same as the last point of the previous chunk
		if (previousGroundChunk != null) {
			Vector2 previousFirstPoint = previousGroundChunk.GetLastEdgePoint().vector;
			Vector2 fourthPoint = points[3];
			Vector2 vector = fourthPoint - previousFirstPoint;
			Vector2 direction = vector.normalized;
			float dist = vector.magnitude;
			float distPer = dist / 3;
			points[0] = previousFirstPoint;
			points[1] = points[0] + direction * distPer;
			points[2] = points[1] + direction * distPer;
		}

		for (int i = 4; i < points.Count; i++) {
			Vector2 point = points[i];
			point.y += UnityEngine.Random.Range(-maxBumpHeight, maxBumpHeight);
			points[i] = point;
		}
		
		foreach (Vector2 point in points) {
			Point pointObject = new Point(point);
			edgePoints.Add(pointObject);
		}

		// add one more point, this time with margin
		Vector2 lastPoint = points[points.Count - 1];
		Vector2 lastPointWithMargin = lastPoint;
		lastPointWithMargin.x += marginSize;
		points.Add(lastPointWithMargin);
		prevPoint = lastPoint;

		int extraDepthOnBottom = -30;
		Vector2 first = points[0];
		points.Add(new Vector2(lastPointWithMargin.x, first.y + extraDepthOnBottom));
		points.Add(new Vector2(first.x, first.y + extraDepthOnBottom));
		points.Add(new Vector2(first.x, first.y - 1));
	}
Ejemplo n.º 6
0
	public void Generate(MountainChunk mountainChunk, GroundChunk previousGroundChunk, float distanceFromMountain) {
		Reset();

		slopeVector = (mountainChunk.GetLastEdgePoint().vector - mountainChunk.GetFirstEdgePoint().vector).normalized;
	
		List<Vector2> points = new List<Vector2>();
		GenerateShape(points, mountainChunk, previousGroundChunk, distanceFromMountain);
		Vector2[] pointsArray = points.ToArray();
		polygonCollider.points = pointsArray;
		meshCreator.InitMesh(pointsArray);
		CalculateDistances();
	}
Ejemplo n.º 7
0
	public void SetMountainChunk(MountainChunk mountainChunk) {
		this.mountainChunk = mountainChunk;
	}