private void MoveInLane(CharacterBase[] laneCharacters, Lane lane) { if (laneCharacters.Length == 0) { return; } LanePositions positions = GetLanePositionsObject(lane); bool evenAmountOfCharacters = IsIntEven(laneCharacters.Length); for (int i = 0; i < laneCharacters.Length; i++) { Transform targetPosition = null; if (evenAmountOfCharacters) { targetPosition = positions.evenPositions[i]; } else { targetPosition = positions.oddPositions[i]; } Transform characterTransform = laneCharacters[i].transform; characterTransform.DOMove(laneCharacters[i].Faction == Faction.Player ? targetPosition.position : new Vector3(transform.position.x * 2 - targetPosition.position.x, targetPosition.position.y, targetPosition.position.z), moveDuration).SetEase(easeType); } }
// Check if the player leaned in the wrong direction private void checkIfPlayerLeanedInWrongDirection(LanePositions laneToCheck) { // If the current target to destroy is not in the lane to check if (targetManager.targetToDestroy.lanePosition != laneToCheck) { print("Wrong Position!"); gameStateController.endGame(true); } }
/// <summary> ///コンストラクタ /// </summary> /// <param name="playerModelObject"></param> public CurveEvent(GameObject playerModelObject, EventManager eventManager) : base(playerModelObject, eventManager) { playerMove = playerModelObject.GetComponent <PlayerMove>(); GameObject laneObject = this.playerModelObject.GetComponentInParent <Player>().LaneObject; lanePositions = laneObject.GetComponent <LanePositions>(); gameSpeed = eventManager.GameSpeed; middleCheckTimer = new Timer(0.5f); }
//returns the lane number or -1 if the lane is not found public int whichLane(float xPos) { float tolerance = LanePositions.GetLaneTolerance(0); //0.25f; for (int i = 0; i < lanes.Length; i++) { if (tolerance >= Mathf.Abs(xPos - lanes[i].x)) { return(i); } } return(-1); }
//moves the element when the player drags there finger. void OnMouseDrag() { if (this.gameObject.name == "TutorialElement1" || this.gameObject.name == "TutorialElement2" || this.gameObject.name == "TutorialElement4" || this.gameObject.name == "TutorialElement5") { return; } if (this.gameObject.name == GlobalVars.POWER_UP_TUTORIAL_TAP_NAME && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_POWER_UP) == 0) { return; } if (this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_ELEMENT_NAME && firstSwipeTutorialElementsMoved) { return; } if (this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_SECOND_ELEMENT_NAME && secondSwipeTutorialElementMoved) { return; } if (this.gameObject.name == GlobalVars.POWER_UP_TUTORIAL_SWIPE_NAME && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_POWER_UP) == 0 && this.gameObject.transform.position.x >= -2.8f) { this.gameObject.GetComponent <ActivatePowerUp>().OnMouseUp(); } currentMousePosition = new Vector3(Input.mousePosition.x, elementScreenPoint.y, elementScreenPoint.z); hoveringMousePosition = Camera.main.ScreenToWorldPoint(currentMousePosition) + cameraOffset; if (!GlobalVars.PAUSED && hoveringMousePosition.x <= (LanePositions.GetLanePositions(0)[3].x + LanePositions.GetLaneTolerance(0)) && hoveringMousePosition.x >= (LanePositions.GetLanePositions(0)[0].x - LanePositions.GetLaneTolerance(0))) { hoveringMousePosition.y = transform.position.y; hoveringMousePosition.z = -1; transform.position = Vector3.Lerp(transform.position, hoveringMousePosition, elementMovementSpeed * 10); // Redundent code for highlighting lanes. if (hoveringMousePosition.x < -4.8) { } else if (hoveringMousePosition.x >= -4.8 && hoveringMousePosition.x < -0.5) { } else if (hoveringMousePosition.x >= -0.5 && hoveringMousePosition.x < 1.5) { } else if (hoveringMousePosition.x > 1.5) { } } }
// Use this for initialization void Start() { gridSpace = LanePositions.GetDistanceBetweenLanes(0); lanes = LanePositions.GetLanePositions(0); //finds references to spriterenders myRing = transform.GetChild(1).GetComponent <SpriteRenderer>(); // Get the contoller game object from the game scene. controller = GameObject.Find("Controller"); //sets sound clickSound = transform.GetComponent <AudioSource>(); //sets the move speed elementMovementSpeed = controller.GetComponent <GenerationScript> ().elementMovementSpeed; //variables to control movement gameObjectWorldPosition = this.transform.position; transform.position = new Vector3((gameObjectWorldPosition.x / gridSpace) * gridSpace, gameObjectWorldPosition.y, gameObjectWorldPosition.z); element = transform.GetChild(0).GetComponent <SpriteRenderer>().sprite; }
void Start() { //sets the screen height screenHeight = Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)); // Grabbing the screen width. widthSetting = (float)(Camera.main.orthographicSize * 2.0 * Screen.width / Screen.height); // Grabbing the screen height. heightSetting = (float)(Camera.main.orthographicSize * 2.0 * Screen.height / Screen.width); // A forloop to iterate through all of the arrays and set their various positions and scales. for (int i = 0; i < lanes.Length; i++) { lanes[i].transform.position = LanePositions.GetLanePositions(-3.65f, -1f)[i]; lanes[i].transform.localScale = new Vector3(widthSetting / widthDivider, widthSetting / widthDivider, widthSetting / widthDivider); spawners[i].transform.position = LanePositions.GetLanePositions(Mathf.Floor(screenHeight.y), -1f)[i]; elements[i].transform.localScale = new Vector3(widthSetting / widthDivider, widthSetting / widthDivider, widthSetting / widthDivider); } }
private LanePositions GetLanePositionsObject(Lane lane) { LanePositions lanePositions = null; switch (lane) { case Lane.Close: lanePositions = closeRange; break; case Lane.Mid: lanePositions = midRange; break; case Lane.Long: lanePositions = longRange; break; } return(lanePositions); }
// A function to create the power up tutorial. public void CreatePowerUpTutorial() { // Spawning in the tutorial elements in the correct positions. powerUpTutorialPosition [0] = new Vector3(LanePositions.GetLanePositions(0)[1].x, 10.92f, 0); powerUpTutorialPosition [1] = new Vector3(LanePositions.GetLanePositions(0)[1].x, 13.52f, 0); powerUpTutorialPosition [2] = new Vector3(LanePositions.GetLanePositions(0)[0].x, 16.06f, 0); powerUpTutorialPosition [3] = new Vector3(LanePositions.GetLanePositions(0)[2].x, 11.89f, 0); powerUpTutorialPosition [4] = new Vector3(LanePositions.GetLanePositions(0)[2].x, 14.43f, 0); powerUpTutorialPosition [5] = new Vector3(LanePositions.GetLanePositions(0)[2].x, 16.73f, 0); // Assigning the tutorialElements their type. (fire, water, powerup etc...) elementNumbers [0] = 0; elementNumbers [1] = 1; elementNumbers [2] = 4; elementNumbers [3] = 4; elementNumbers [4] = 3; elementNumbers [5] = 0; // Loop through the powerUpTutorialPosition and spawn in the element, add MoveElementDown script and disable moving and colliders, set the powerup type. for (int i = 0; i < powerUpTutorialPosition.Length; i++) { tutorialElements[i] = (GameObject)Instantiate(elements[elementNumbers[i]], powerUpTutorialPosition[i], Quaternion.identity); tutorialElements[i].AddComponent <MoveElementDown>(); tutorialElements[i].GetComponent <MoveElementDown>().isAllowedToMove = false; tutorialElements[i].GetComponent <Collider>().enabled = false; if (tutorialElements[i].tag == GlobalVars.POWER_UP_TAG) { tutorialElements[i].GetComponent <ActivatePowerUp>().SetPowerUp(0); } // Adding the elements to ON_SCREEN_ELEMENTS so that we can register powerups and collection. ZoneCollisionDetection.ON_SCREEN_ELEMENTS.Add(tutorialElements[i]); } tutorialElements [0].name = "TutorialElement1"; tutorialElements [1].name = "TutorialElement2"; tutorialElements [4].name = "TutorialElement4"; tutorialElements [5].name = "TutorialElement5"; for (int i = 0; i < 3; i++) { tutorialElements[i].GetComponent <MoveElementDown>().isAllowedToMove = true; } tutorialElements [2].SetActive(true); tutorialElements [3].SetActive(true); this.GetComponent <PlayTutorial> ().SetTutorialElements(); }
//drops the elemnt into a lane after the player raises their finger from the screen. public void OnMouseUp() { if (this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_SECOND_ELEMENT_NAME && (transform.position.x >= (LanePositions.GetLanePositions(0)[3].x - LanePositions.GetLaneTolerance(0)) && transform.position.x <= (LanePositions.GetLanePositions(0)[3].x + LanePositions.GetLaneTolerance(0))) && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0) { isCorrectMove = true; secondSwipeTutorialElementMoved = true; // Let the PlayTutorial script know that the ring and arrow has to mvoe and that the first element has been moved into the correct position. controller.GetComponent <PlayTutorial>().ResetRingAndArrow(); controller.GetComponent <PlayTutorial>().MovedFirstElementOver(); } if (this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_ELEMENT_NAME && (transform.position.x >= (LanePositions.GetLanePositions(0)[1].x - LanePositions.GetLaneTolerance(0)) && transform.position.x <= (LanePositions.GetLanePositions(0)[1].x + LanePositions.GetLaneTolerance(0))) && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0) { isCorrectMove = true; firstSwipeTutorialElementsMoved = true; // Let the PlayTutorial script know that the ring and arrow has to mvoe and that the first element has been moved into the correct position. controller.GetComponent <PlayTutorial>().ResetRingAndArrow(); controller.GetComponent <PlayTutorial>().MovedFirstElementOver(); } // If the player drags the element to far to the right then reset the element position. if ((this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_ELEMENT_NAME || this.gameObject.name == GlobalVars.SWIPE_TUTORIAL_SECOND_ELEMENT_NAME) && (this.gameObject.tag == "Zone2" || this.gameObject.tag == "Zone4") && (transform.position.x >= -5.73f || transform.position.x <= 3.08f) && PlayerPrefs.GetInt(GlobalVars.GATHERING_TUTORIAL_WATCHED_SWIPE) == 0 && !isCorrectMove) { // Set the position of the element back to the location from which it was dragged. transform.position = new Vector3(-5.2f, 6.5f, 0); isCorrectMove = false; if (OnTutorialElementMouseAction != null) { OnTutorialElementMouseAction(false); } return; } // On mouse up set the x position of the element to that of it's closest lane. transform.position = new Vector3(lanes[controller.GetComponent <GenerationScript> ().whichLane(this.transform.position.x)].x, transform.position.y, transform.position.z); isMouseDragging = false; // Disable the ring after the player is finished swiping. myRing.enabled = false; //makes sure the element updates it lane when it settles in a lane GetComponent <MoveElementDown>().UpdateLane(); }
// Start is called before the first frame update void Start() { lanePositions = transform.parent.GetComponentInChildren <LanePositions>(); eventManager = transform.parent.GetComponent <Player>().EventManager; isCurve = false; }
public override void OnCreate() { LocationType = LaneLocationType.MIDDLE; lanePositions = transform.parent.GetComponentInChildren <LanePositions>(); lanePositions.Initialize(); }
// Use this for initialization void Start() { // ----- CHEATS ----- \\ //ActivatePowerUp.UnlockAllPowerups (); //Cheats.UnlockAllElements(); // ----- CHEATS ----- \\ animators[0] = animators[0].GetComponent <Animator>(); animators [1] = animators [1].GetComponent <Animator> (); animators [2] = animators [2].GetComponent <Animator> (); animators [3] = animators [3].GetComponent <Animator> (); animators [0].SetTrigger("finishedLoading"); arrayOfPlayerPrefs = new string[4]; arrayOfPlayerPrefs [0] = PlayerPrefs.GetString("ELEMENT1", "fire"); arrayOfPlayerPrefs [1] = PlayerPrefs.GetString("ELEMENT2", "water"); arrayOfPlayerPrefs [3] = PlayerPrefs.GetString("ELEMENT3", "earth"); arrayOfPlayerPrefs [2] = PlayerPrefs.GetString("ELEMENT4", "air"); //sets player prefs if they have not been set PlayerPrefs.SetString("ELEMENT1", PlayerPrefs.GetString("ELEMENT1", "fire")); PlayerPrefs.SetString("ELEMENT2", PlayerPrefs.GetString("ELEMENT2", "water")); PlayerPrefs.SetString("ELEMENT3", PlayerPrefs.GetString("ELEMENT3", "earth")); PlayerPrefs.SetString("ELEMENT4", PlayerPrefs.GetString("ELEMENT4", "air")); // Setting the player given sprites element1.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [0]); collectionPot1.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[0] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [0])); element2.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [1]); collectionPot2.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[1] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [1])); element3.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [3]); collectionPot3.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[3] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [2])); element4.transform.GetChild(0).GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [2]); collectionPot4.transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer> ().sprite = (elementSprites[2] = Resources.Load <Sprite> (GlobalVars.FILE_PATH + arrayOfPlayerPrefs [3])); // End of setting player given sprites elements[0] = element1; elements[1] = element2; elements[2] = element3; elements[3] = element4; if (elements.Length > 4) { elements [4] = powerUp; } // At the start assign the lanes but create a method to change the lanes positions lanes [0] = LanePositions.GetLanePositions(9f, -1)[0]; lanes [1] = LanePositions.GetLanePositions(9f, -1)[1]; lanes [2] = LanePositions.GetLanePositions(9f, -1)[2]; lanes [3] = LanePositions.GetLanePositions(9f, -1)[3]; scoreTexts[0] = elementText1; scoreTexts[1] = elementText2; scoreTexts[2] = elementText3; scoreTexts[3] = elementText4; //reset powerUpCounter (number of powerUps seen in a given round) powerUpCounter = 0; powerUpsPerRound = 3; //difficulty setting defaultSpawnModifier = defaultFallSpeedModifier = 1; //0.6f + (0.9f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); creationFrequency = 60f + (140f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); elementMovementSpeed = 2 + (0.3f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); // 0.6f + (0.9f * GlobalVars.NUMBER_ELEMENTS_UNLOCKED / ((float)GlobalVars.ELEMENTS.Count)); CollectionTimer.instance.setBaseCreationFrequency(creationFrequency); CollectionTimer.instance.setBaseMovementSpeed(elementMovementSpeed); fallSpeedModifiers = new float [GlobalVars.NUMBER_OF_LANES]; //sets the fallSpeedModifiers to default for (int i = 0; i < fallSpeedModifiers.Length; i++) { fallSpeedModifiers[i] = defaultFallSpeedModifier; } //sets the spawnRateModifiers to default values spawnRateModifier = defaultSpawnModifier; //saves the starting values of fall speed and spawn rate initialCreationFrequency = creationFrequency; initialElementMovementSpeed = elementMovementSpeed; #if DEBUG powerUp1 = new BucketShield(2); PowerUp.ResetPowerUpLevel(powerUp1); #endif // Bools for tutorial checks isElementGiven = false; isSecondElementGiven = false; hasTutorialElementSpawned = false; timeToPowerUp = false; GlobalVars.SWIPE_TUTORIAL_FIRST_SPAWNED = false; //generates the powerups ActivatePowerUp.GenerateAllPowerups(); ActivatePowerUp.GenerateUnlockedPowerups(); // Instantiating the arrays for the power up tutorial tutorialElements = new GameObject[6]; powerUpTutorialPosition = new Vector3[6]; elementNumbers = new int[6]; CheckForPowerUpTutorial(); }