protected override Vector3 GetDestination() { isFalling = false; Collider2D down = Physics2D.OverlapBox(transform.position + ApplicationController.gravity, new Vector2(.9f, .9f), 0f); if (down == null) { isFalling = true; return(ApplicationController.gravity); } MovingObjectController movingObject = down.gameObject.GetComponent <MovingObjectController>(); if (movingObject != null && movingObject.IsMoving == true) { return(Vector3.zero); } if (movingObject != null) { Collider2D left = Physics2D.OverlapBox(transform.position + ApplicationController.Left, new Vector2(.9f, .9f), 0f); if (left == null) { Collider2D leftDown = Physics2D.OverlapBox(transform.position + ApplicationController.DownLeft, new Vector2(.9f, .9f), 0f); if (leftDown == null) { Collider2D upleft = Physics2D.OverlapBox(transform.position + ApplicationController.UpLeft, new Vector2(.9f, .9f), 0f); if (upleft == null || upleft.gameObject.GetComponent <MovingObjectController>() == null) { if (!movingObject.WillYouMove()) { return(ApplicationController.Left); } } } } Collider2D right = Physics2D.OverlapBox(transform.position + ApplicationController.Right, new Vector2(.9f, .9f), 0f); if (right == null) { Collider2D rightDown = Physics2D.OverlapBox(transform.position + ApplicationController.DownRight, new Vector2(.9f, .9f), 0f); if (rightDown == null) { Collider2D upright = Physics2D.OverlapBox(transform.position + ApplicationController.UpRight, new Vector2(.9f, .9f), 0f); if (upright == null || upright.gameObject.GetComponent <MovingObjectController>() == null) { if (!movingObject.WillYouMove()) { return(ApplicationController.Right); } } } } } return(Vector3.zero); }
public bool WillYouMove() { if (IsMoving) { return(true); } Collider2D down = Physics2D.OverlapBox(transform.position + ApplicationController.gravity, new Vector2(.9f, .9f), 0f); if (down == null) { return(true); } MovingObjectController MOCDown = down.gameObject.GetComponent <MovingObjectController>(); if (MOCDown == null) { return(false); } if (MOCDown.WillYouMove()) { return(true); } Collider2D left = Physics2D.OverlapBox(transform.position + ApplicationController.Left, new Vector2(.9f, .9f), 0f); if (left == null) { Collider2D leftDown = Physics2D.OverlapBox(transform.position + ApplicationController.DownLeft, new Vector2(.9f, .9f), 0f); if (leftDown == null) { Collider2D leftUp = Physics2D.OverlapBox(transform.position + ApplicationController.UpLeft, new Vector2(.9f, .9f), 0f); if (leftUp == null || leftUp.gameObject.GetComponent <MovingObjectController>() == null) { return(true); } } } Collider2D right = Physics2D.OverlapBox(transform.position + ApplicationController.Right, new Vector2(.9f, .9f), 0f); if (right == null) { Collider2D rightDown = Physics2D.OverlapBox(transform.position + ApplicationController.DownRight, new Vector2(.9f, .9f), 0f); if (rightDown == null) { Collider2D rightUp = Physics2D.OverlapBox(transform.position + ApplicationController.UpRight, new Vector2(.9f, .9f), 0f); if (rightUp == null || rightUp.gameObject.GetComponent <MovingObjectController>() == null) { return(true); } } } return(false); }
// Use this for initialization void Awake() { animator = GetComponentInChildren <Animator>(); // if(animator==null) animator = GetComponent<Animator>(); rb2D = GetComponent <Rigidbody2D>(); // BC2D = GetComponent<BoxCollider2D>(); MOC = GetComponent <MovingObjectController>(); SpriteRenderer sr = GetComponentInChildren <SpriteRenderer>(); if (sr != null) { sr.sortingOrder = ApplicationController.BombExplosionSortValue; } }
protected override Vector3 GetDestinationInMovement(Vector3 calculatedNewPosition) { float horizontalInput = ApplicationController.inputCTRL.HorizontalMovement(); float verticalInput = ApplicationController.inputCTRL.VerticalMovement(); Vector3 newDirection; if (horizontalInput != 0) { newDirection = new Vector2(horizontalInput, 0f); } else if (verticalInput != 0) { newDirection = new Vector2(0f, verticalInput); } else { newDirection = Vector2.zero; } bool space = ApplicationController.inputCTRL.PlantBomb(); bool control = ApplicationController.inputCTRL.ActionWithoutMoving(); if (switcher != control) { switcher = control; } if (control || (space && bombs > 0)) { return(Vector2.zero); } if ((calculatedNewPosition == destVect / 2 || (calculatedNewPosition - destVect / 2).sqrMagnitude <= float.Epsilon) && newDirection == destVect) { Collider2D directionObject = Physics2D.OverlapBox(end + newDirection, new Vector2(.9f, .9f), 0); if (directionObject == null || directionObject.gameObject.CompareTag("Ground")) { end += newDirection; transform.position += newDirection; return(Vector3.MoveTowards(childSprite.transform.localPosition - newDirection, destVect / 2, inverseMoveTime * Time.deltaTime)); } else if (directionObject != null && directionObject.gameObject.layer == LayerMask.NameToLayer("PickUp")) { MovingObjectController dirMOC = directionObject.gameObject.GetComponent <MovingObjectController>(); if (dirMOC != null && dirMOC.IsMoving) { } else { end += newDirection; transform.position += newDirection; return(Vector3.MoveTowards(childSprite.transform.localPosition - newDirection, destVect / 2, inverseMoveTime * Time.deltaTime)); } } } return(calculatedNewPosition); }
protected override Vector3 GetDestination() { float horizontalInput = ApplicationController.inputCTRL.HorizontalMovement(); float verticalInput = ApplicationController.inputCTRL.VerticalMovement(); Vector3 direction; bool control = ApplicationController.inputCTRL.ActionWithoutMoving(); bool space = ApplicationController.inputCTRL.PlantBomb(); if (space) { SetBomb(); } if (switcher != control) { switcher = control; } if (horizontalInput != 0) { direction = new Vector2(horizontalInput, 0f); } else if (verticalInput != 0) { direction = new Vector2(0f, verticalInput); } else { direction = Vector2.zero; } Vector3 endDir = transform.position + direction; Collider2D directionObject = Physics2D.OverlapBox(endDir, new Vector2(.9f, .9f), 0); if (directionObject != null && 1 << directionObject.gameObject.layer == blockingLayer.value) { MovingObjectController MOCStone = directionObject.gameObject.GetComponent <MovingObjectController>(); if (MOCStone == null) { return(Vector3.zero); } if (!MOCStone.Push(direction)) { return(Vector3.zero); } else if (control) { return(Vector3.zero); } } if (directionObject != null && 1 << directionObject.gameObject.layer == pickUpLayer.value) { if (direction == ApplicationController.gravity && directionObject.gameObject.GetComponent <MovingObjectController>().IsMoving) { return(Vector3.zero); } if (direction == -ApplicationController.gravity && directionObject.gameObject.GetComponent <MovingObjectController>().IsMoving) { return(Vector3.zero); } if ((direction == directionObject.gameObject.GetComponent <MovingObjectController>().DestVect || -direction == directionObject.gameObject.GetComponent <MovingObjectController>().DestVect) && directionObject.gameObject.GetComponent <MovingObjectController>().IsMoving) { return(Vector3.zero); } if (directionObject.gameObject.GetComponent <PickUp>().TryPickUp(transform.position)) { if (control) { if (directionObject.gameObject.CompareTag("Ballon")) { PickUpOxygen(); } else if (directionObject.gameObject.CompareTag("BombPickUp")) { PickUpBomb(); } else if (directionObject.gameObject.CompareTag("Crystal")) { PickUpCrystals(); } else if (directionObject.gameObject.CompareTag("Mineral")) { PickUpMinerals(); } Destroy(directionObject.gameObject); return(Vector3.zero); } } else { return(Vector3.zero); } } if (directionObject != null && directionObject.gameObject.layer == LayerMask.NameToLayer("Ground")) { if (control) { Destroy(directionObject.gameObject); return(Vector3.zero); } } return(direction); }
private void Start() { animator = GetComponent <Animator>(); movingObject = GetComponent <MovingObjectController>(); }
private void Start() { _controller = GetComponentInParent <MovingObjectController>(); }
private void Awake() { ApplicationController.levelBuilder = this; randomLevelGenerator = ApplicationController.instance.randomLevelGenerator; BackgroundController bc = background.GetComponent <BackgroundController> (); bc.speed = ApplicationController.startingParams.background.speed; MovingObjectController ballonMOC = ballon.GetComponent <MovingObjectController> (); ballonMOC.canRoll = ApplicationController.startingParams.ballon.canRoll; ballonMOC.rotationSpeed = ApplicationController.startingParams.ballon.rotationSpeed; ballonMOC.moveTime = ApplicationController.startingParams.ballon.moveTime; ballonMOC.canKill = ApplicationController.startingParams.ballon.canKill; MovingObjectController BombMOC = activeBomb.GetComponent <MovingObjectController> (); BombMOC.canRoll = ApplicationController.startingParams.bomb.canRoll; BombMOC.rotationSpeed = ApplicationController.startingParams.bomb.rotationSpeed; BombMOC.moveTime = ApplicationController.startingParams.bomb.moveTime; BombMOC.canKill = ApplicationController.startingParams.bomb.canKill; BombController bombCtrl = activeBomb.GetComponent <BombController> (); bombCtrl.destroyDelayTime = ApplicationController.startingParams.bomb.destroyDelayTime; bombCtrl.explosionLengthTime = ApplicationController.startingParams.bomb.explosionLenghtTime; BombMOC = deactiveBomb.GetComponent <MovingObjectController>(); BombMOC.canRoll = ApplicationController.startingParams.bomb.canRoll; BombMOC.rotationSpeed = ApplicationController.startingParams.bomb.rotationSpeed; BombMOC.moveTime = ApplicationController.startingParams.bomb.moveTime; BombMOC.canKill = ApplicationController.startingParams.bomb.canKill; bombCtrl = deactiveBomb.GetComponent <BombController>(); bombCtrl.destroyDelayTime = ApplicationController.startingParams.bomb.destroyDelayTime; bombCtrl.explosionLengthTime = ApplicationController.startingParams.bomb.explosionLenghtTime; MovingObjectController crystalMOC = crystal.GetComponent <MovingObjectController> (); crystalMOC.canRoll = ApplicationController.startingParams.crystal.canRoll; crystalMOC.rotationSpeed = ApplicationController.startingParams.crystal.rotationSpeed; crystalMOC.moveTime = ApplicationController.startingParams.crystal.moveTime; crystalMOC.canKill = ApplicationController.startingParams.crystal.canKill; //MovingObjectController mineralMOC = mineral.GetComponent<MovingObjectController> (); //mineralMOC.canRoll = ApplicationController.startingParams.mineral.canRoll; //mineralMOC.rotationSpeed = ApplicationController.startingParams.mineral.rotationSpeed; //mineralMOC.moveTime = ApplicationController.startingParams.mineral.moveTime; //mineralMOC.canKill = ApplicationController.startingParams.mineral.canKill; PlayerController playerCtrl = player.GetComponent <PlayerController> (); playerCtrl.moveTime = ApplicationController.startingParams.player.moveTime; playerCtrl.secondsForBallon = ApplicationController.startingParams.player.secondsForBallon; playerCtrl.startingSecondsOfOxygen = ApplicationController.startingParams.player.startingSecondsOfOxygen; MovingObjectController stoneMOC = stone.GetComponent <MovingObjectController> (); stoneMOC.canRoll = ApplicationController.startingParams.stone.canRoll; stoneMOC.rotationSpeed = ApplicationController.startingParams.stone.rotationSpeed; //stoneMOC.sideMoveTime = ApplicationController.startingParams.stone.moveTime; stoneMOC.moveTime = ApplicationController.startingParams.stone.moveTime; stoneMOC.canKill = ApplicationController.startingParams.stone.canKill; if (ApplicationController.levelToLoad == ApplicationController.Level.selectedLevel) { ReadFile(); } else if (ApplicationController.levelToLoad == ApplicationController.Level.random) { GenerateRandom(); } Build(); }
//public bool StopFlag //{ // set // { // stopFlag = StopFlag; // } // get // { // return stopFlag; // } //} protected override Vector3 GetDestination() { // if (stopFlag) return Vector3.zero; Collider2D leftNeighbour = null; Collider2D rightNeighbour = null; Collider2D upNeighbour = null; Collider2D downNeighbour = null; Collider2D upLeftNeighbour = null; Collider2D upRightNeighbour = null; Collider2D downLeftNeighbour = null; Collider2D downRightNeighbour = null; Vector2 tileSize = new Vector2(0.9f, 0.9f); leftNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(-1f, 0f), tileSize, 0f); rightNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(1f, 0f), tileSize, 0f); upNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(0f, 1f), tileSize, 0f); downNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(0f, -1f), tileSize, 0f); upLeftNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(-1f, 1f), tileSize, 0f); upRightNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(1f, 1f), tileSize, 0f); downLeftNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(-1f, -1f), tileSize, 0f); downRightNeighbour = Physics2D.OverlapBox(transform.position + new Vector3(1f, -1f), tileSize, 0f); GameObject[] neighboursGO = new GameObject[8]; if (isLeftSideMove) { if (upNeighbour != null) { neighboursGO[0] = upNeighbour.gameObject; } if (upRightNeighbour != null) { neighboursGO[1] = upRightNeighbour.gameObject; } if (rightNeighbour != null) { neighboursGO[2] = rightNeighbour.gameObject; } if (downRightNeighbour != null) { neighboursGO[3] = downRightNeighbour.gameObject; } if (downNeighbour != null) { neighboursGO[4] = downNeighbour.gameObject; } if (downLeftNeighbour != null) { neighboursGO[5] = downLeftNeighbour.gameObject; } if (leftNeighbour != null) { neighboursGO[6] = leftNeighbour.gameObject; } if (upLeftNeighbour != null) { neighboursGO[7] = upLeftNeighbour.gameObject; } } else { if (upNeighbour != null) { neighboursGO[0] = upNeighbour.gameObject; } if (upRightNeighbour != null) { neighboursGO[7] = upRightNeighbour.gameObject; } if (rightNeighbour != null) { neighboursGO[6] = rightNeighbour.gameObject; } if (downRightNeighbour != null) { neighboursGO[5] = downRightNeighbour.gameObject; } if (downNeighbour != null) { neighboursGO[4] = downNeighbour.gameObject; } if (downLeftNeighbour != null) { neighboursGO[3] = downLeftNeighbour.gameObject; } if (leftNeighbour != null) { neighboursGO[2] = leftNeighbour.gameObject; } if (upLeftNeighbour != null) { neighboursGO[1] = upLeftNeighbour.gameObject; } } for (int i = 0; i < neighboursGO.Length; i++) { if (neighboursGO[i] == null) { continue; } if (neighboursGO[i].CompareTag("Player") || neighboursGO[i].CompareTag("Enemy")) { neighboursGO[i] = null; continue; } MovingObjectController moc = neighboursGO[i].GetComponent <MovingObjectController>(); if (moc != null && !moc.CanBeUsed(transform.position)) { neighboursGO[i] = null; } } //Debug.Log("new line***************"); //Debug.Log(isLeftSideMove); // foreach (var neoghbour in neighboursGO) Debug.Log(neoghbour); return(CalculateVector(neighboursGO)); }