private LevelBounds CalculateLevelRect(LevelBounds currentRect, Transform parent) { foreach (Transform child in parent) { Collider2D c = child.GetComponent <Collider2D>(); if (c != null) { bool newRect = false; if (currentRect.left == 0 && currentRect.right == 0 && currentRect.top == 0 && currentRect.bottom == 0) { newRect = true; } if (c.bounds.min.x < currentRect.left || newRect) { currentRect.left = c.bounds.min.x; } if (c.bounds.max.y > currentRect.top || newRect) { currentRect.top = c.bounds.min.y; } if (c.bounds.max.x > currentRect.right || newRect) { currentRect.right = c.bounds.max.x; } if (c.bounds.min.y < currentRect.bottom || newRect) { currentRect.bottom = c.bounds.min.y; } } currentRect = CalculateLevelRect(currentRect, child); } return(currentRect); }
void Awake() { levelBounds = new LevelBounds(); levelBoundary = transform.Find("Playable Boundary"); enemies = transform.Find("Enemies"); environment = transform.Find("Environment"); AccquireLevelBounds(); }
void Awake() { //FindPlayers(); instance = this; bounds = GetComponent <BoxCollider2D>().bounds; objects = new List <GameObject>(); cloneList = new List <WrapClones>(); Instance = this; }
void Start() { controllerStartPosition = Vector3.zero; objectToMove = GetObjects.instance.getMovingObjectsContainer().gameObject; bounds = GetObjects.instance.GetLevelBounds(); playerCharacter = GetObjects.instance.getControllableUnit(); player = GetObjects.instance.getPlayer(); startingMoveSpeed = moveSpeed; }
private void Start() { m_farmerSpawnTimer = farmerSpawnTime; m_levelXMax = LevelBounds.LevelWidth() * 0.5f; m_levelZMax = LevelBounds.LevelHeight() * 0.5f; SpawnFarmer(); }
public void SetColor(int playerid, SheetAnimation.PlayerColor color) { this.playerid = playerid; SpriteRenderer spriteR = gameObject.AddComponent <SpriteRenderer>(); spriteR.sprite = Resources.Load <Sprite>("Menu/Cursor_" + color.ToString().ToUpper()[0]); buttons = FindObjectsOfType <Button>(); spriteR.sortingOrder = 5; levelBounds = FindObjectOfType <LevelBounds>(); }
void Update() { if (Ghost) { return; } if (CheckPlayerInput() && GameManager.Instance.State != GameManager.GameState.Attractor) { Control.Rotate = !Control.Rotate; } if (_point == null) { BecomeBoat(); } else { BecomeMonster(); } //Try wrap Vector3 wrappedPos = transform.position; if (LevelBounds.Hit(ref wrappedPos)) { Lightning.Instance.Strike(); transform.position = wrappedPos; BreakTrail(); } if (Time.time - _lastBoatTrailSpawn > BoatTrailParticleSpawnInterval) { GameObject instance = Instantiate(BoatTrailParticle.gameObject); instance.transform.position = transform.position; instance.GetComponent <BoatTrail>().PlayerId = playerID; _lastBoatTrailSpawn = Time.time; } if (isMonster) { Control.TrailBoost = Mathf.Min(0, Control.TrailBoost + (Time.deltaTime * Control.TrailBoostDecrese)); } else { Control.TrailBoost = Mathf.Max(0, Control.TrailBoost - Time.deltaTime * Control.TrailBoostDecrese); } }
private void Awake() { levelBounds = GameManager.Instance.LevelBounds; var playerInput = GetComponent <PlayerInput>(); #if UNITY_ANDROID && !UNITY_EDITOR touchAction = playerInput.actions.FindAction("Touch", true); #endif moveAction = playerInput.actions.FindAction("Movement", true); animator = GetComponent <Animator>(); renderer = GetComponent <SpriteRenderer>(); particleSystem = GetComponent <ParticleSystem>(); mainModule = particleSystem.main; shapeModule = particleSystem.shape; }
//A couroutine to smoothly lerp the camera towards the target level public IEnumerator MoveTo(LevelBounds target, bool lerp = true, bool moveCamera = false) { nextLevel = target; nextLevel.gameObject.SetActive(true); if (!nextLevel.startLevel) { gameManager.ShowTutorial(false); } Debug.Log("Moving camera"); hasMovedCamera = true; if (lerp) { while ((Vector2)pos != target.pos) { gameManager.SetMultiplier(0); pos = Vector2.MoveTowards(pos, target.pos, 50 * Time.deltaTime); pos.z = -10; transform.position = pos; yield return(null); } } hasMovedCamera = false; this.moveCamera = moveCamera; if (currentLevel != null) { currentLevel.gameObject.SetActive(false); } currentLevel = nextLevel; pos = target.pos; pos.z = -10; transform.position = pos; if (currentLevel.startLevel) { gameManager.ShowTutorial(true); } else { gameManager.ShowTutorial(false); } if (currentLevel.endLevel) { gameManager.GameOver(true, false); } gameManager.SetMultiplier(1); }
private void Awake() { var gm = GameManager.Instance; score = gm.Score; coins = gm.Coins; levelBounds = gm.LevelBounds; player = gm.Player.transform; spawnPool = new SpawnPool(2, coinSettings.Value.CoinPrefab); spawnPool.EnqueueAll(); var queue = spawnPool.QueuedObjects; for (int i = 0; i < queue.Length; i++) { InitializeCoin(queue[i]); } }
private void Awake() { var gm = GameManager.Instance; goal = gm.Goal; levelBounds = gm.LevelBounds; rigidbody = GetComponent <Rigidbody2D>(); renderer = GetComponent <SpriteRenderer>(); collider2D = GetComponent <Collider2D>(); fixedDeltaTime = Time.fixedDeltaTime; var player = gm.Player.transform; var box = player.GetChild(0); var bounds = box.GetComponent <Collider2D>().bounds; Vector2 scale = (Vector2)box.localScale * player.localScale; playerHeight = bounds.center.y + bounds.extents.y * scale.y; }
public void LoadContent(ContentManager contentManager) { CollisionWorld = new World(new Vector2(0, 10)); debugView = new DebugView(CollisionWorld); debugView.LoadContent(DemoGame.graphics.GraphicsDevice, contentManager); foreach (var layer in Layers) { layer.level = this; layer.LoadContent(contentManager); if (layer.Name == "Mountains") { layer._postProcessors.Add(new WaterReflectionPostProcessor(context)); } foreach (var item in layer.Items) { if (item is SpriteObject sprite) { sprite.context = context; } item.layer = layer; item.LoadContent(contentManager); item.Initialize(); } } render_target = new RenderTarget2D(context.graphics, context.graphics.Viewport.Width, context.graphics.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); this._postProcessors.Add(new FogPostProcessor(context)); context.camera.Bounds = LevelBounds; LevelBounds.Inflate((int)(0.05 * LevelBounds.Width), (int)(0.05 * LevelBounds.Height)); var song = "level" + Rand.GetRandomInt(1, 4); AudioManager.PlaySoundTrack(song, true, false); AudioManager.MusicVolume = 0.1f; }
private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; if (Difficulty != null) { Difficulty.ApplyDifficulty(); } Goal = GameObject.Find("goal").transform; LevelBounds = new LevelBounds(GameObject.Find("minBound").transform, GameObject.Find("maxBound").transform); Player = GameObject.Find("Hero"); RockThrower = GameObject.Find("RockThrower"); GameTime.Value = gameLength; }
void Start() { cameraFollowsPlayer = true; // player and level bounds initialization target = GameObject.FindGameObjectWithTag("Player").transform; levelBounds = GameObject.FindGameObjectWithTag("LevelBounds").GetComponent <LevelBounds>(); lastTargetPosition = target.position; offsetZ = (transform.position - target.position).z; transform.parent = null; // camera size calculation (orthographicSize is half the height of what the camera sees. float cameraHeight = Camera.main.orthographicSize * 2f; float cameraWidth = cameraHeight * Camera.main.aspect; // we get the levelbounds coordinates to lock the camera into the level xMin = levelBounds.boundsXMin + (cameraWidth / 2); xMax = levelBounds.boundsXMax - (cameraWidth / 2); yMin = levelBounds.boundsYMin + (cameraHeight / 2); yMax = levelBounds.boundsYMax - (cameraHeight / 2); }
public static bool Hit(ref Vector3 position) { if (Instance == null) { //yolo Instance = FindObjectOfType <LevelBounds>(); } Vector3 localPos = position - Instance.transform.position; bool hit = false; if (localPos.x > Instance.RectSize.x) { hit = true; localPos = new Vector3(localPos.x * -1 + Instance.Offset, localPos.y, localPos.z); } else if (localPos.x < -Instance.RectSize.x) { hit = true; localPos = new Vector3(localPos.x * -1 - Instance.Offset, localPos.y, localPos.z); } else if (localPos.z > Instance.RectSize.y) { hit = true; localPos = new Vector3(localPos.x, localPos.y, localPos.z * -1 + Instance.Offset); } else if (localPos.z < -Instance.RectSize.y) { hit = true; localPos = new Vector3(localPos.x, localPos.y, localPos.z * -1 - Instance.Offset); } position = Instance.transform.position + localPos; return(hit); }
private void Awake() { m_Bounds = FindObjectOfType <LevelBounds>(); m_Target = FindObjectOfType <PlayerInformation>().transform; m_Camera = GetComponent <Camera>(); }
void Update() { m_animator.SetBool("hasEgg", (m_egg != null)); if (!m_agent.hasPath) { //If inside the level, if (LevelBounds.InsideLevel(transform.position)) { if (!m_scared && !m_egg) { Nest closestNest = ClosestNest(); //If there is a nest with an egg if (closestNest != null) { bool closerThanCoop = Vector3.Distance(closestNest.transform.position, transform.position) < Vector3.Distance(m_coop.transform.position, transform.position); if (closerThanCoop) { //If at the nest, if (Vector3.Distance(closestNest.transform.position, transform.position) < m_pickupDistance) { m_egg = closestNest.TakeEgg(); if (m_egg != null) { m_agent.SetDestination(FleePosition()); m_egg.SetActive(false); m_animator.SetTrigger("pickup"); eggPickupSound.Play(); } else { m_agent.SetDestination(NestPosition(closestNest.transform)); } } //If not at the nest else { m_agent.SetDestination(NestPosition(closestNest.transform)); } } //If the coop is closer, else { //If at the coop, if (Vector3.Distance(m_coop.transform.position, transform.position) < m_pickupDistance) { m_egg = m_coop.TakeEgg(); if (m_egg != null) { m_agent.SetDestination(FleePosition()); m_egg.SetActive(false); m_animator.SetTrigger("pickup"); eggPickupSound.Play(); } else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } //If not at the coop, else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } } //If there is no nest with an egg, else { //If at the coop, if (Vector3.Distance(m_coop.transform.position, transform.position) < m_pickupDistance) { m_egg = m_coop.TakeEgg(); if (m_egg != null) { m_agent.SetDestination(FleePosition()); m_egg.SetActive(false); m_animator.SetTrigger("pickup"); eggPickupSound.Play(); } else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } //If not at the coop, else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } } //If scared or have an egg, else { m_agent.SetDestination(FleePosition()); } } //If outside the level, else { if (m_scared) { //aaaaaa Destroy(gameObject); } //If have an egg, else if (m_egg != null) { //hehehehe stole the egg Destroy(gameObject); } //If don't have an egg else { //go on the hunt Nest closestNest = ClosestNest(); if (closestNest != null) { bool closerThanCoop = Vector3.Distance(closestNest.transform.position, transform.position) < Vector3.Distance(m_coop.transform.position, transform.position); if (closerThanCoop) { m_agent.SetDestination(NestPosition(closestNest.transform)); } else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } else { m_agent.SetDestination(NestPosition(m_coop.transform)); } } } } }
public void CalculateLevelRect(Transform parent) { player.GetComponent <Player>().currentLevel = parent; levelBounds = CalculateLevelRect(new LevelBounds(), parent); levelBounds.top += 100f; //There is no top limit so make the number bigger than the highest object. }