public void SetupState(FreeParallax p, Camera c, int index) { // add a second object if we need one to wrap properly if (RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOffScreen && RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOnScreen && GameObjects.Count == 1) { GameObject obj = GameObject.Instantiate(GameObjects[0]) as GameObject; obj.transform.parent = GameObjects[0].transform.parent; GameObjects.Add(obj); } if (GameObjectRenderers.Count == 0) { foreach (GameObject obj in GameObjects) { Renderer r = obj.GetComponent <Renderer>(); if (r == null) { Debug.LogError("Null renderer found at element index " + index.ToString() + ", each game object in the parallax must have a renderer"); return; } GameObjectRenderers.Add(r); } } }
void Start() { getSpeedRatio = FindObjectOfType <FreeParallax>(); player = FindObjectOfType <Player>(); spawn = FindObjectOfType <Spawner>(); highScoreCount = PlayerPrefs.GetFloat("HighScoree", 0); //TODO: !This should always be on START, this LOADS up the data, hence the "GetFloat()" }
// Start is called before the first frame update void Start() { if (camera == null) { camera = FindObjectOfType <Camera>(); } if (backgroundParallax == null) { backgroundParallax = FindObjectOfType <FreeParallax>(); } moveVector = new Vector3(moveAmount, 0f); climbVector = new Vector3(0f, ladderClimbSpeed); //TODO: calculate based on sprite size jumpNudge = new Vector3(0f, 1.0f); playerRB = this.GetComponent <Rigidbody2D>(); playerRB.gravityScale = gravAmt; glideGravAmt = gravAmt * glideGravModifier; glideDelayTimerCount = glideDelayTimer; playerAnim = this.GetComponent <Animator>(); isDashing = false; isGliding = false; isClimbing = false; startDashCd = false; isJumping = false; isDead = false; dashTime = startDashTime; dashCd = dashCooldown; canDash = true; num_jumps = 0; currJumpForce = jumpForce; groundedFilter = LayerMask.GetMask("Level"); playerSprite = this.GetComponent <SpriteRenderer>(); BoxCollider2D playerCol = this.GetComponent <BoxCollider2D>(); collHeight = (float)playerCol.bounds.size.y / 2; //note: can add a float offset after dividing by 2 here for more leeway on jumps widthOffset = new Vector3(playerCol.bounds.size.x / 2 + 0.3f, 0, 0); jumpTimerCount = jumpTimer; ResetAllAnimTriggers(""); audioMgr = FindObjectOfType <AudioManager>(); }
// Use this for initialization void Start() { parallax = GameObject.FindWithTag("Parallax").GetComponent <FreeParallax>(); if (currentScene.name == "Air Particles") { parallaxParticles = GameObject.FindWithTag("Parallax Particles").GetComponent <FreeParallax>(); } // Set the platform position to where it's tied to on the pipe. transform.position = slingBand.transform.position; LineRendererSetup(); rayToMouse = new Ray(pipe.position, Vector3.zero); pipeToPlatformRay = new Ray(slingBand.transform.position, Vector3.zero); maxStretchSqr = maxStretch * maxStretch; CircleCollider2D circle = GetComponent <Collider2D>() as CircleCollider2D; //circleRadius = circle.radius; }
void Awake() { if (parallax == null) { parallax = GetComponentInChildren <FreeParallax>(); } if (lanes.Length > 0) { lanesWithPlayer = new List <GameObject>(); for (int i = 0; i < lanes.Length; i++) { lanesWithPlayer.Insert(i, null); } if (player != null) { lanesWithPlayer[0] = player; } } }
/// <summary> /// Update the element given a distance of parallax move, t /// </summary> /// <param name="p">Parallax container</param> /// <param name="t">Total amount the parallax moved. Elements will move a percetage of this distance.</param> public void Update(FreeParallax p, float t, Camera c) { if (GameObjects == null || GameObjects.Count == 0 || GameObjects.Count != GameObjectRenderers.Count) { // cannot update, something went wrong in setup return; } // move everything first if (p.IsHorizontal) { foreach (GameObject obj in GameObjects) { obj.transform.Translate(t * SpeedRatio, 0.0f, 0.0f); } } else { foreach (GameObject obj in GameObjects) { obj.transform.Translate(0.0f, t * SpeedRatio, 0.0f); } } bool wrap = RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOffScreen && RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOnScreen; // if it's an individual object we let it go an extra screen width in case the player changes direction float padding = (wrap ? 0.0f : 1.0f); float minEdge, maxEdge; if (p.IsHorizontal) { minEdge = c.rect.x - padding; maxEdge = c.rect.width + padding; } else { minEdge = c.rect.y - padding; maxEdge = c.rect.height + padding; } int end = GameObjects.Count; // now check for wrapping and stuff going off screen for (int i = 0; i < end; i++) { GameObject obj = GameObjects[i]; Renderer r = GameObjectRenderers[i]; Bounds b = r.bounds; Vector3 screenEdge = (t > 0 ? c.WorldToViewportPoint(b.min) : c.WorldToViewportPoint(b.max)); float screenEdgeValue = (p.IsHorizontal ? screenEdge.x : screenEdge.y); if (wrap) { if (t > 0 && screenEdgeValue >= maxEdge) { if (p.IsHorizontal) { // move to the back of the line at far left float newX = (GameObjectRenderers[0].bounds.min.x - r.bounds.size.x) + p.WrapOverlap; FreeParallax.SetPosition(obj, r, newX, r.bounds.min.y); } else { // move to the back of the line at far bottom float newY = (GameObjectRenderers[0].bounds.min.y - r.bounds.size.y) + p.WrapOverlap; FreeParallax.SetPosition(obj, r, r.bounds.min.x, newY); } GameObjects.RemoveAt(i); GameObjects.Insert(0, obj); GameObjectRenderers.RemoveAt(i); GameObjectRenderers.Insert(0, r); } else if (t < 0 && screenEdgeValue <= minEdge) { if (p.IsHorizontal) { // move to the front of the line at far right float newX = (GameObjectRenderers[GameObjects.Count - 1].bounds.max.x) - p.WrapOverlap; FreeParallax.SetPosition(obj, r, newX, r.bounds.min.y); } else { // move to the front of the line at far top float newY = (GameObjectRenderers[GameObjects.Count - 1].bounds.max.y) - p.WrapOverlap; FreeParallax.SetPosition(obj, r, r.bounds.min.x, newY); } GameObjects.RemoveAt(i); GameObjects.Add(obj); GameObjectRenderers.RemoveAt(i--); GameObjectRenderers.Add(r); end--; } } else if (p.IsHorizontal) { if (t > 0 && (screenEdge.y >= c.rect.height || screenEdgeValue >= maxEdge)) { if (RepositionLogicFunction != null) { RepositionLogicFunction(p, this, t, obj, r); } else { Vector3 leftEdge = c.ViewportToWorldPoint(Vector3.zero); float randX = UnityEngine.Random.Range(RepositionLogic.MinXPercent, RepositionLogic.MaxXPercent); float randY = UnityEngine.Random.Range(RepositionLogic.MinYPercent, RepositionLogic.MaxYPercent); Vector3 newWorldPoint = c.ViewportToWorldPoint(new Vector3(randX, randY)); FreeParallax.SetPosition(obj, r, leftEdge.x - newWorldPoint.x, newWorldPoint.y); } } else if (t < 0 && (screenEdge.y >= c.rect.height || screenEdge.x < minEdge)) { if (RepositionLogicFunction != null) { RepositionLogicFunction(p, this, t, obj, r); } else { Vector3 rightEdge = c.ViewportToWorldPoint(Vector3.one); float randX = UnityEngine.Random.Range(RepositionLogic.MinXPercent, RepositionLogic.MaxXPercent); float randY = UnityEngine.Random.Range(RepositionLogic.MinYPercent, RepositionLogic.MaxYPercent); Vector3 newWorldPoint = c.ViewportToWorldPoint(new Vector3(randX, randY)); FreeParallax.SetPosition(obj, r, rightEdge.x + newWorldPoint.x, newWorldPoint.y); } } } else { if (t > 0 && (screenEdge.x >= c.rect.width || screenEdgeValue >= maxEdge)) { if (RepositionLogicFunction != null) { RepositionLogicFunction(p, this, t, obj, r); } else { Vector3 bottomEdge = c.ViewportToWorldPoint(Vector3.zero); float randX = UnityEngine.Random.Range(RepositionLogic.MinXPercent, RepositionLogic.MaxXPercent); float randY = UnityEngine.Random.Range(RepositionLogic.MinYPercent, RepositionLogic.MaxYPercent); Vector3 newWorldPoint = c.ViewportToWorldPoint(new Vector3(randX, randY)); FreeParallax.SetPosition(obj, r, newWorldPoint.x, bottomEdge.y - newWorldPoint.y); } } else if (t < 0 && (screenEdge.x >= c.rect.width || screenEdge.y < minEdge)) { if (RepositionLogicFunction != null) { RepositionLogicFunction(p, this, t, obj, r); } else { Vector3 topEdge = c.ViewportToWorldPoint(Vector3.one); float randX = UnityEngine.Random.Range(RepositionLogic.MinXPercent, RepositionLogic.MaxXPercent); float randY = UnityEngine.Random.Range(RepositionLogic.MinYPercent, RepositionLogic.MaxYPercent); Vector3 newWorldPoint = c.ViewportToWorldPoint(new Vector3(randX, randY)); FreeParallax.SetPosition(obj, r, newWorldPoint.x, topEdge.y + newWorldPoint.y); } } } } }
public void SetupPosition(FreeParallax p, Camera c, int index) { Vector3 screenLeft = c.ViewportToWorldPoint(Vector3.zero); Vector3 screenTop = c.ViewportToWorldPoint(Vector3.one); float start, offset; if (p.IsHorizontal) { start = screenTop.y + 1.0f; offset = screenLeft.x + GameObjectRenderers[0].bounds.size.x; } else { start = screenTop.x + 1.0f; offset = screenLeft.y + GameObjectRenderers[0].bounds.size.y; } for (int i = 0; i < GameObjects.Count; i++) { GameObject obj = GameObjects[i]; Renderer r = GameObjectRenderers[i]; if (RepositionLogic.SortingOrder != 0) { r.sortingOrder = RepositionLogic.SortingOrder; } if (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOffScreen || RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen) { float x, y; if (p.IsHorizontal) { x = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.x : 0); y = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.y : start + r.bounds.size.y); } else { x = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.x : start + r.bounds.size.x); y = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.y : 0); } FreeParallax.SetPosition(obj, r, x, y); } else { // position in the next spot in line if (p.IsHorizontal) { offset -= (r.bounds.size.x - p.WrapOverlap); } else { offset -= (r.bounds.size.y - p.WrapOverlap); } obj.transform.rotation = Quaternion.identity; // anchor to the top of the screen if (RepositionLogic.PositionMode == FreeParallaxPositionMode.WrapAnchorTop) { if (p.IsHorizontal) { Vector3 topWorld = c.ViewportToWorldPoint(new Vector3(0.0f, 1.0f, 0.0f)); FreeParallax.SetPosition(obj, r, offset, topWorld.y - r.bounds.size.y); } else { Vector3 topWorld = c.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f)); FreeParallax.SetPosition(obj, r, topWorld.x - r.bounds.size.x, offset + r.bounds.size.y); } } else { if (p.IsHorizontal) { FreeParallax.SetPosition(obj, r, offset, screenLeft.y); } else { FreeParallax.SetPosition(obj, r, screenLeft.x, offset); } } GameObjects.RemoveAt(i); GameObjects.Insert(0, obj); GameObjectRenderers.RemoveAt(i); GameObjectRenderers.Insert(0, r); } } }
public void SetupScale(FreeParallax p, Camera c, int index) { Vector3 worldBottom = c.ViewportToWorldPoint(Vector3.zero); for (int i = 0; i < GameObjects.Count; i++) { GameObject obj = GameObjects[i]; Renderer r = GameObjectRenderers[i]; Bounds b = r.bounds; if (RepositionLogic.ScaleHeight > 0.0f) { float percent; obj.transform.localScale = Vector3.one; if (p.IsHorizontal) { Vector3 maxPoint = c.WorldToViewportPoint(new Vector3(0.0f, worldBottom.y + b.size.y, 0.0f)); percent = RepositionLogic.ScaleHeight / maxPoint.y; } else { Vector3 maxPoint = c.WorldToViewportPoint(new Vector3(worldBottom.x + b.size.x, 0.0f, 0.0f)); percent = RepositionLogic.ScaleHeight / maxPoint.x; } obj.transform.localScale = new Vector3(percent, percent, 1); b = r.bounds; } if (RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOffScreen && RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOnScreen && SpeedRatio > 0.0f) { if (p.IsHorizontal) { // if we aren't at least a viewport width * 1.1, resize in x only (a little stretching and we'll log a warning) float objWidth = c.WorldToViewportPoint(new Vector3(worldBottom.x + b.size.x, 0, 0)).x; if (objWidth < 1.1f) { Debug.LogWarning("Game object in element index " + index.ToString() + " did not fit the screen width but was asked to wrap, so it was stretched. This can be fixed " + "by making sure any parallax graphics that wrap are at least 1.1x times the largest width resolution you support."); Vector3 scale = obj.transform.localScale; scale.x = (scale.x * (1.0f / objWidth)) + 0.1f; obj.transform.localScale = scale; } } else { // if we aren't at least a viewport height * 1.1, resize in y only (a little stretching and we'll log a warning) float objHeight = c.WorldToViewportPoint(new Vector3(0.0f, worldBottom.y + b.size.y, 0.0f)).y; if (objHeight < 1.1f) { Debug.LogWarning("Game object in element index " + index.ToString() + " did not fit the screen height but was asked to wrap, so it was stretched. This can be fixed " + "by making sure any parallax graphics that wrap are at least 1.1x times the largest height resolution you support."); Vector3 scale = obj.transform.localScale; scale.y = (scale.y * (1.0f / objHeight)) + 0.1f; obj.transform.localScale = scale; } } } } }
public void SetupPosition(FreeParallax p, Camera c, int index) { Vector3 screenLeft = c.ViewportToWorldPoint(Vector3.zero); Vector3 screenTop = c.ViewportToWorldPoint(Vector3.one); float start, offset; if (p.IsHorizontal) { start = screenTop.y + 1.0f; offset = screenLeft.x + GameObjectRenderers[0].bounds.size.x; } else { start = screenTop.x + 1.0f; offset = screenLeft.y + GameObjectRenderers[0].bounds.size.y; } for (int i = 0; i < GameObjects.Count; i++) { GameObject obj = GameObjects[i]; Renderer r = GameObjectRenderers[i]; if (RepositionLogic.SortingOrder != 0) { r.sortingOrder = RepositionLogic.SortingOrder; } if (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOffScreen || RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen) { float x, y; if (p.IsHorizontal) { x = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.x : 0); y = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.y : start + r.bounds.size.y); } else { x = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.x : start + r.bounds.size.x); y = (RepositionLogic.PositionMode == FreeParallaxPositionMode.IndividualStartOnScreen ? r.bounds.min.y : 0); } FreeParallax.SetPosition(obj, r, x, y); } else { // position in the next spot in line if (p.IsHorizontal) { offset -= (r.bounds.size.x - p.WrapOverlap); } else { offset -= (r.bounds.size.y - p.WrapOverlap); } obj.transform.rotation = Quaternion.identity; // anchor to the top of the screen if (RepositionLogic.PositionMode == FreeParallaxPositionMode.WrapAnchorTop) { if (p.IsHorizontal) { Vector3 topWorld = c.ViewportToWorldPoint(new Vector3(0.0f, 1.0f, 0.0f)); FreeParallax.SetPosition(obj, r, offset, topWorld.y - r.bounds.size.y); } else { Vector3 topWorld = c.ViewportToWorldPoint(new Vector3(1.0f, 0.0f, 0.0f)); FreeParallax.SetPosition(obj, r, topWorld.x - r.bounds.size.x, offset + r.bounds.size.y); } } else if (RepositionLogic.PositionMode == FreeParallaxPositionMode.WrapAnchorBottom) { if (p.IsHorizontal) { FreeParallax.SetPosition(obj, r, offset, screenLeft.y); } else { FreeParallax.SetPosition(obj, r, screenLeft.x, offset); } } else { // no anchor, maintain position if (p.IsHorizontal) { FreeParallax.SetPosition(obj, r, offset, r.bounds.min.y); } else { FreeParallax.SetPosition(obj, r, r.bounds.min.x, offset); } } GameObjects.RemoveAt(i); GameObjects.Insert(0, obj); GameObjectRenderers.RemoveAt(i); GameObjectRenderers.Insert(0, r); } } }
public void SetupState(FreeParallax p, Camera c, int index) { // add a second object if we need one to wrap properly if (RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOffScreen && RepositionLogic.PositionMode != FreeParallaxPositionMode.IndividualStartOnScreen && GameObjects.Count == 1) { GameObject obj = GameObject.Instantiate(GameObjects[0]) as GameObject; obj.transform.parent = GameObjects[0].transform.parent; obj.transform.position = GameObjects[0].transform.position; GameObjects.Add(obj); } if (GameObjectRenderers.Count == 0) { foreach (GameObject obj in GameObjects) { Renderer r = obj.GetComponent<Renderer>(); if (r == null) { Debug.LogError("Null renderer found at element index " + index.ToString() + ", each game object in the parallax must have a renderer"); return; } GameObjectRenderers.Add(r); } } }