private IEnumerator LoadLevelAfterImportantEventsAreDone(LevelEntrance level) { while (!State.Instance.AllImportantSequencesAreDone()) { yield return new WaitForEndOfFrame(); } LevelLoader.Instance.LoadLevel(level); }
public void StartLevelTransitionOut(Transform walkTarget, LevelEntrance level) { // Walk to target Debug.Log(string.Format("Walk to {0}", walkTarget.position)); // Disable rigid body // Set animation to walking // Move toward walkTarget _control.Disabled = true; SceneFadeInOut.Instance.EndScene(); transform .DOMove(walkTarget.position, .5f) .OnComplete(() => { StartCoroutine(LoadLevelAfterImportantEventsAreDone(level)); }); // Start a timer // Load level once camera fade occurs }
private void OnEnable() { carrots = GetComponentsInChildren <Carrot>(); foreach (Carrot carrot in carrots) { carrot.level = this; carrot.SetFrozen(!hidden); } entrance = GetComponentInChildren <LevelEntrance>(); if (entrance) { entrance.level = this; } GameplayManager.instance.AddLevel(this); GameplayManager.OnEnterLevel += OnEnterLevel; GameplayManager.OnExitLevel += OnExitLevel; }
private void SetupMovement(LevelEntrance selectedLevel, LevelEntrance.Direction directionOfMovement) { if (directionOfMovement == LevelEntrance.Direction.Forward && selectedLevel != null && selectedLevel.NextLevelDirections.Count > 0) { movingDirections = selectedLevel.NextLevelDirections; direction = 1; movingIndex = 0; IsMoving = true; } else if (directionOfMovement == LevelEntrance.Direction.Backward && levelIndex > 0 && levelIndex <= levels.Count && levels[levelIndex - 1].NextLevelDirections.Count > 0) { levelIndex--; selectedLevel = levels[levelIndex]; movingDirections = selectedLevel.NextLevelDirections; direction = -1; movingIndex = movingDirections.Count - 1; IsMoving = true; } }
void Start() { entrance = transform.parent.GetComponent<LevelEntrance>(); leaving = false; }
// Update is called once per frame void Update() { if (levelIndex < 0 || levelIndex >= levels.Count) { return; } LevelEntrance selectedLevel = levels[levelIndex]; if (!IsMoving) { float verticalInput = Input.GetAxis("Vertical"); float horizontalInput = Input.GetAxis("Horizontal"); float spacebarInput = Input.GetAxis("Jump"); if (spacebarInput > .5 && !string.IsNullOrEmpty(selectedLevel.sceneName)) { SceneManager.LoadScene(selectedLevel.sceneName); } if (verticalInput > BUTTON_FORCE && selectedLevel.up != LevelEntrance.Direction.None) { SetupMovement(selectedLevel, selectedLevel.up); } else if (verticalInput < -BUTTON_FORCE && selectedLevel.down != LevelEntrance.Direction.None) { SetupMovement(selectedLevel, selectedLevel.down); } else if (horizontalInput > BUTTON_FORCE && selectedLevel.right != LevelEntrance.Direction.None) { SetupMovement(selectedLevel, selectedLevel.right); } else if (horizontalInput < -BUTTON_FORCE && selectedLevel.left != LevelEntrance.Direction.None) { SetupMovement(selectedLevel, selectedLevel.left); } } else { transform.localPosition = Vector2.MoveTowards(transform.localPosition, movingDirections[movingIndex], MOVEMENT_SPEED * Time.deltaTime); if (Vector2.Distance(transform.localPosition, movingDirections[movingIndex]) < .1) { movingIndex += direction; } if (movingIndex == -1) { IsMoving = false; if (selectedLevel.IsWorldTransition) { SceneManager.LoadScene(selectedLevel.sceneName); } } else if (movingIndex == movingDirections.Count) { levelIndex++; IsMoving = false; if (levels[levelIndex].IsWorldTransition) { SceneManager.LoadScene(levels[levelIndex].sceneName); } } } }
void Start() { if (GameLogic.instance != null) { if (!GameLogic.instance.playedTutorial) { GameLogic.instance.FinishTutorial(); } } particleMustDo = new bool[3]; interacted = false; brotherScript = brotherObject.GetComponent <LevelEntrance>(); if (levelToLoad - 1 == 2) { GameLogic.instance.levelsData[2].completed = true; } timeForSequence = 500; spriteTime.SetActive(false); spriteLevelNumb.SetActive(true); /////////////// interactionSprite.SetActive(false); InitTransformable(); isPunchable = false; isBreakable = false; interactuableBySmash = false; offset = GameLogic.instance.worldOffset; if (worldAssignation == world.DAWN) { GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic; //GetComponent<SpriteRenderer>().sprite = imagenDawn; } else { //GetComponent<SpriteRenderer>().sprite = imagenDusk; } //float randomVal = Random.Range(1, 4); //Debug.Log(randomVal); //GetComponentInChildren<MeshRenderer>().gameObject.transform.rotation *= Quaternion.AngleAxis(randomVal * 90, new Vector3(0, 0, 1)); if (GameLogic.instance.levelsData[levelToLoad - 1].completed) { //Debug.Log(GameLogic.instance.completedLevels); activated = true; //Debug.Log("Activating Door"); } else { //Debug.Log("DoorShouldBeDisabled"); } rb = GetComponent <Rigidbody2D>(); rb.mass = 5000; rb.gravityScale = 0; for (int i = 0; i < particleSystems.Length; i++) { if (particleSystems[i] != null) { particleSystems[i].Stop(); } } }
public override bool EndMove(Vector3 direction) { Vector3 pos = my.position; Suspended = false; RaycastHit hit; bool onGround = Physics.Raycast(pos, -yAxis, out hit, 1, layerMask); if (StandingUp() && onGround) { LevelEntrance entry = hit.transform.GetComponent <LevelEntrance>(); if (entry) { entry.EnterLevel(); } } if (SameDirection(my.forward, -yAxis)) { if (Eating) { JustAte = true; eatParticles.Play(); currentlyEating.Eat(pos - yAxis); } else if (onGround) { MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); if (movable) { if (CollideWithMovableObject(movable, -yAxis) && Eating) { HandleFalling(pos); } } } } if (!onGround) { // there's a hole OnEars = UpsideDown() && Physics.Raycast(pos, -yAxis, 2, layerMask); if (OnEars) { return(true); // on tient sur les oreilles tout va bien } if (Eating && !Colinear(my.forward, yAxis) && Physics.Raycast(pos + my.forward, -yAxis, 1, layerMask)) { if (Physics.Raycast(pos + my.forward, yAxis, 1, layerMask)) { Suspended = true; return(true);// a ceiling holds the carrot, wer'e suspended } currentlyEating.transform.parent = my; Vector3 axis = new Vector3(-my.forward.z, 0, my.forward.x); Quaternion initialRotation = my.rotation; Quaternion finalRotation = Quaternion.AngleAxis(90, axis) * initialRotation; finalRotation = RoundRotation(finalRotation); ChangeRotation(initialRotation, finalRotation, timeToMove, -my.forward); } HandleFalling(pos); return(false); } if (StandingUp() && Physics.Raycast(pos, yAxis, out hit, 1, layerMask)) { MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); if (movable) { if (movable.CanMove(direction)) { movable.Push(direction); } else if (movable.CanMove(yAxis)) { movable.Push(yAxis); } return(false); } } if (UpsideDown() && !OnEars && !Eating) { OnHead = true; ExecuteMove(direction); } else { OnEars = OnHead = false; if (Physics.Raycast(pos, my.up, out hit, 1, layerMask)) { //mes oreilles sont dans un mur MovableEntity movable = hit.transform.GetComponent <MovableEntity>(); if (movable && movable.CanMove(my.up)) { movable.Push(my.up); } else { if (Physics.Raycast(my.position, -my.up, out hit, 1, layerMask)) { movable = hit.transform.GetComponent <MovableEntity>(); if (movable && movable.CanMove(-my.up)) { movable.Push(-my.up); // should check if not eating first (carrot could be stuck under ceiling) //carrying = movable; } else { return(true); } } else if (Eating && Physics.Raycast(my.position + my.forward, -my.up, out hit, 1, layerMask)) { movable = hit.transform.GetComponent <MovableEntity>(); if (movable && movable.CanMove(-my.up)) { movable.Push(-my.up); //carrying = movable; } else { return(true); } } ChangePosition(pos, RoundPosition(pos - my.up), timeToMove, -my.up); return(false); } } } return(true); }
public static void DispatchRenderLevels() { ReceivedActions.Enqueue(() => { // fill saves foreach (KeyValuePair <string, LevelAsset> entry in DataManager.Instance.AllSaves) { LevelAsset levelData = null; if (DataManager.Instance.AllLevels.TryGetValue(entry.Key, out levelData)) { // love first if (DataManager.Instance.LoveLevels.Contains(entry.Key)) { if (!self.FavoriteViewObjects.HasLoad(entry.Key)) { GameObject go = Instantiate(self.LevelEntrancePrefab); LevelEntrance le = go.GetComponent <LevelEntrance>(); le.SetData(levelData, entry.Value); le.beloved = true; self.FavoriteViewObjects.AddChild(go, entry.Key); } } else { if (!self.TrendingViewObjects.HasLoad(entry.Key)) { GameObject go = Instantiate(self.LevelEntrancePrefab); LevelEntrance le = go.GetComponent <LevelEntrance>(); le.SetData(levelData, entry.Value); self.TrendingViewObjects.AddChild(go, entry.Key); } } } else { Debug.LogWarning("Has save data without level data"); } } // fill all levels foreach (KeyValuePair <string, LevelAsset> entry in DataManager.Instance.AllLevels) { if (!DataManager.Instance.AllSaves.ContainsKey(entry.Key)) { if (DataManager.Instance.LoveLevels.Contains(entry.Key)) { if (!self.FavoriteViewObjects.HasLoad(entry.Key)) { GameObject go = Instantiate(self.LevelEntrancePrefab); LevelEntrance le = go.GetComponent <LevelEntrance>(); le.SetData(entry.Value, null); le.beloved = true; self.FavoriteViewObjects.AddChild(go, entry.Key); } } else { if (!self.TrendingViewObjects.HasLoad(entry.Key)) { GameObject go = Instantiate(self.LevelEntrancePrefab); LevelEntrance le = go.GetComponent <LevelEntrance>(); le.SetData(entry.Value, null); self.TrendingViewObjects.AddChild(go, entry.Key); } } } } if (DataManager.Instance.LoveLevels.Count == 0) { self.TrendingToggle.OnClicked(); self.OnClickedTrending(); } self.TrendingViewObjects.transform.parent.GetComponent <TrendingContents>().CompleteLoad(); }); }