private void CreateFloes() { IceFloe floe; int whileInt = 0; int lastId = 0; int listPos = 0; SetBoundingValues(); // get positions playerPosition = Camera.main.transform.position; sourcePosition = playerPosition; startPosition = new Vector3(playerPosition.x, yPositionFloor, playerPosition.z); // create first floe exactly at player position (under his/her feet) floe = Instantiate(iceFloe, startPosition, Quaternion.identity, iceFloeParent.transform).GetComponent <IceFloe>(); startFloe = floe; startFloe.SetPosition(startPosition); startFloe.SetID(0); floeList.Add(startFloe); while (whileInt < whileLimit) { newPosList.Add(new Vector3(sourcePosition.x + spawnDistance, yPositionFloor, sourcePosition.z)); newPosList.Add(new Vector3(sourcePosition.x + newPosVec.x, yPositionFloor, sourcePosition.z + newPosVec.z)); newPosList.Add(new Vector3(sourcePosition.x - newPosVec.x, yPositionFloor, sourcePosition.z + newPosVec.z)); newPosList.Add(new Vector3(sourcePosition.x - spawnDistance, yPositionFloor, sourcePosition.z)); newPosList.Add(new Vector3(sourcePosition.x - newPosVec.x, yPositionFloor, sourcePosition.z - newPosVec.z)); newPosList.Add(new Vector3(sourcePosition.x + newPosVec.x, yPositionFloor, sourcePosition.z - newPosVec.z)); for (int i = 0; i < newPosList.Count; i++) { // if there is anough space, and the distance to the other floes big enough, create and place floe if (CheckNewPosition(newPosList[i]) && CompareToFloes(newPosList[i])) { lastId++; floe = Instantiate(iceFloe, newPosList[i], Quaternion.identity, iceFloeParent.transform).GetComponent <IceFloe>(); floe.SetPosition(newPosList[i]); floe.SetID(lastId); floeList.Add(floe); } else { whileInt++; } } newPosList.Clear(); // next loop will start at the position of the newly created floe if (listPos < floeList.Count) { sourcePosition = floeList[listPos].GetPosition(); listPos++; } } print(floeList.Count + "floes created."); CreatePath(); }
/// <summary> /// Reset all floes, clear lists, create new path /// </summary> /// <param name="startPosFloe">IceFloe, where the new path should start</param> public void Reset(IceFloe startPosFloe) { startFloe = startPosFloe; foreach (IceFloe floe in floeList) { floe.Reset(); } pathList.Clear(); usedFieldsList.Clear(); CreatePath(); }
void OnCollisionEnter(Collision col) { IceFloe iceFloe = col.gameObject.GetComponent <IceFloe>(); if (iceFloe != null && iceFloe != transform.parent && JumpTimer > 0.5f) { Quaternion rotation = transform.rotation; transform.parent = iceFloe.transform; transform.rotation = rotation; iceFloe.GetComponent <Rigidbody>().AddForce(LastJumpDirectionWorld * JUMP_FORCE_FACTOR); GetComponent <PlayerMovementController>().currentFloe = iceFloe; } else if (col.gameObject.tag == "Goal") { StopCoroutine("Jump"); gameController.updateGameLevels(); return; } }
/// <summary> /// reaction to the step on a floe /// </summary> /// <param name="floe">entered floe</param> void FloeEnter(IceFloe floe) { int pathID = floe.GetPathID(); if (iceFloePathList != null) { // enter good floe if (floe.GetIsGoodFloe()) { // enter final floe if (pathID == iceFloeManager.finalPathFloeID) { currentFloeID = floe.GetID(); currentFloe = iceFloeManager.GetFloeList()[pathID]; Finish(); } // player moved to the next floe -> change color (only after level 1) else if (pathID != currentFloeID && currentLevel > 1) { // beginning of the path if (currentFloeID == 0 || currentFloeID == 1) // whole path was visible at the beginning, because player was standing on the first floe { for (int i = pathID + 1; i < iceFloePathList.Count - 1; i++) { iceFloePathList[i].ChangeColor(false); // hide the color of all other path floes (except of the first two) } iceFloePathList[pathID].ChangeColor(true); // change color of the floe the player stepped on to "good" if (pathID + currentLevel < iceFloePathList.Count) { iceFloePathList[pathID + currentLevel].ChangeColor(true); // show the color of the floe after the next (gap becomes bigger with higher level) } } // somewhere in between the path else { iceFloePathList[pathID].ChangeColor(true); // change color of the floe the player stepped on to "good" if (pathID + currentLevel - 1 < iceFloePathList.Count - 1) { iceFloePathList[pathID + currentLevel - 1].ChangeColor(false); // hide the color of the next floe if (pathID + currentLevel < iceFloePathList.Count) { iceFloePathList[pathID + currentLevel].ChangeColor(true); // show the color of the floe after the next (gap becomes bigger with higher level) } } } } waitingForDeath = false; } // enter bad floe -> die else { waitingForDeath = true; } currentFloeID = floe.GetID(); currentFloe = iceFloeManager.GetFloeList()[floe.GetID()]; } }