본문 바로가기
개발/Unity) 코드분석

코드분석)ZigTapZag

by 테샤르 2022. 9. 26.

ZigTapZag

게임을 진행하면 공처럼 생긴게 한쪽 방향으로 이동한다. 떨어지지 말고 계속 길을 따라가서 더 높은 점수를 쌓는 게임으로

TAP(클릭)을 하게되면 방향이 바뀐다.

 

반응형

 

프로젝트 링크 주소 : [링크]

 

GitHub - coderDarren/ZigZagClone: A complete project. Hoping someone could learn from this.

A complete project. Hoping someone could learn from this. - GitHub - coderDarren/ZigZagClone: A complete project. Hoping someone could learn from this.

github.com

 

<플레이 영상>

 

 

------------------------------------

 

게임을 시작하면 MainCamera의 Position으로 게임스러운 연출?을 진행하느데 Target Entry를 기준으로 Smooth하게 이동된다.

 

<WallSpawner에서 이동하는 만큼 지형(Wall)을 만든다.

GameManager Prefab에 많은 Manager Component가 포함되어있다.

관리에 차원에서는 같이 있는게 좋지만 개인적으로는 가독성이 좀떨어지지 않을까싶다.

 

기본적으로 Wall, Pickup, Orb에 대해서는 Pooling이 가능하도록 처리한다. (생성 및 재사용)

<WallSpawner>

해당 클래스에서 pickUp을 생성 관리(Pooling) 및 Spwan에 대한 처리를 진행한다.

void Shift() {
				transform.position += -Vector3.forward * shiftSpeed * Time.deltaTime;
			}

			/// <summary>
			/// Simple procedural function (randomization with rules)
			/// Choose a number (0 or 1) and that determines the direction of the next wall (left or right)
			/// If the next spawn position is offscreen, switch the number (0 to 1 OR 1 to 0)
			/// Find a wall from the wall pool and set that position to the newly calculated position (nextPos)
			/// Store the last spawned wall in a variable 'lastSpawnedWall'
			/// Randomly spawn a pickup item on this wall
			/// </summary>
			public void SpawnWall() {
				Vector3 nextPos = lastSpawnedWall.position;
				int random = Random.Range(0, 2);
				if (random == 0) {
					if (nextPos.x + leftSlot.x < xRange.min ||
						nextPos.x + leftSlot.x > xRange.max) {
						//cannot use leftSlot
						nextPos += rightSlot;
					} else {
						nextPos += leftSlot;
					}
				}
				if (random == 1) {
					if (nextPos.x + rightSlot.x < xRange.min ||
						nextPos.x + rightSlot.x > xRange.max) {
						//cannot use rightSlot
						nextPos += leftSlot;
					}
					else {
						nextPos += rightSlot;
					}
				}
				Transform t = wallPool.GetFirstAvailable();
				t.SetParent(transform);
				nextPos.y = 0;
				t.position = nextPos;
				lastSpawnedWall = t;

				TrySpawnPickup();
			}

			/// <summary>
			/// Called when the game restarts. All wall pieces child of the Wall Spawner need..
			/// ..to be moved back to the persistent, undying wallPool object
			/// Same goes for pickup objects
			/// </summary>
			public void ReleasePoolObjects() {
				Wall[] walls = GetComponentsInChildren<Wall>();
				Pickup[] pickups = GetComponentsInChildren<Pickup>();
				foreach (Wall wall in walls) {
					wallPool.Dispose(wall.gameObject.transform);
				}
				foreach (Pickup pickup in pickups) {
					pickupPool.Dispose(pickup.gameObject.transform);
				}
			}

			/// <summary>
			/// Randomly place a pickup above the last spawned wall
			/// </summary>
			void TrySpawnPickup() {
				float random = Random.Range(0.0f, 1.0f);
				if (random <= pickupProbability) {
					Transform t = pickupPool.GetFirstAvailable();
					t.SetParent(transform);
					t.position = lastSpawnedWall.position + Vector3.up * 1.7f;
				}
			}

 

특이한 기능은 없지만 맵을 재활용하고 게임스러운 연출(카메라연출, 맵의 컬러 변경, 스코어 표현, 시작 연출등)들이

포함되어있어서 참고하기에는 괜찮다.

 

매직넘버로 맵이 추가되는 수치값이 포함되어있다.

[Unity -Top Paid Package]

[Unity -Top Free Package]

[Unity -New Asset Package]

 

 

반응형

댓글