/// <summary> /// Get the next position after taking a direction from the current position. /// </summary> /// <param name="currentPosition">Position before taking direction.</param> /// <param name="direction">Direction to take from current position.</param> /// <returns>The position after taking direction from current position.</returns> public Vector2 NextPosition(Vector2 currentPosition, Globals.Direction direction) { int x = (int)currentPosition.x; int y = (int)currentPosition.y; switch (direction) { case Globals.Direction.North: y += 1; break; case Globals.Direction.East: x += 1; break; case Globals.Direction.South: y -= 1; break; case Globals.Direction.West: x -= 1; break; } return(new Vector2(x, y)); }
IEnumerator MoveCameraPath2(Globals.Direction[] dir) { int dist; Globals.Direction left = Globals.Direction.West; Globals.Direction right = Globals.Direction.East; Globals.Direction down = Globals.Direction.South; Globals.Direction up = Globals.Direction.North; for (int k = 0; k < dir.Length; k++) { dist = 178; //reset if (dir[k] == Globals.Direction.East || dir[k] == Globals.Direction.West) { dist = 250; } for (int i = 0; i < dist; i++) { this.Move(dir[k]); yield return(new WaitForFixedUpdate()); } } Globals.Direction[] dirs = { left, left, up, left, left, down, down, right, right, up, right, right }; this.gameObject.transform.position = new Vector3(0, 0, -2f); //back to beginning StartCoroutine(MoveCameraPath3(dirs)); }
public override void Move(Globals.Direction direction) { if (isRolling) { base.Move(direction); } }
// Direction: 0 = South, 1 = West, 2 = North, 3 = East public virtual void Move(Globals.Direction direction) { if (Globals.canvas == null || Globals.player == null) { return; } if ((!Globals.canvas.dialogue || !Globals.player != this) && !isDying) { Rotate(direction); if (direction == Globals.Direction.South && (!southCollider || !southCollider.isTriggered)) { Vector3 position = this.transform.position; position.y -= pixelSize; this.transform.position = position; } else if (direction == Globals.Direction.West && (!westCollider || !westCollider.isTriggered)) { Vector3 position = this.transform.position; position.x -= pixelSize; this.transform.position = position; } else if (direction == Globals.Direction.North && (!northCollider || !northCollider.isTriggered)) { Vector3 position = this.transform.position; position.y += pixelSize; this.transform.position = position; } else if (direction == Globals.Direction.East && (!eastCollider || !eastCollider.isTriggered)) { Vector3 position = this.transform.position; position.x += pixelSize; this.transform.position = position; } } }
public void Mover(Globals.Direction dir) { if (dir == Globals.Direction.South) { Vector3 position = this.transform.position; position.y -= Globals.pixelSize; this.transform.position = position; } else if (dir == Globals.Direction.West) { Vector3 position = this.transform.position; position.x -= Globals.pixelSize; this.transform.position = position; } else if (dir == Globals.Direction.North) { Vector3 position = this.transform.position; position.y += Globals.pixelSize; this.transform.position = position; } else if (dir == Globals.Direction.East) { Vector3 position = this.transform.position; position.x += Globals.pixelSize; this.transform.position = position; } }
public void StartRolling(Globals.Direction rollDirection) { direction = rollDirection; isRolling = true; animator.SetInteger("Direction", (int)direction); animator.SetTrigger("Roll"); GetComponent <Rigidbody2D>().WakeUp(); }
void RandomMovement() { if (Random.value < chanceToChangeDirection) { int m = Random.Range(0, 4); movementDirection = (Globals.Direction)m; } entity.Move(movementDirection); }
public Node(Tile tile, TileMap tileMap, Node parent, Globals.Direction directionTaken) { this.parent = parent; this.directionTaken = directionTaken; isPatheable = tile.isPatheable; worldPosition = tile.transform.position; gridPosition = tile.transform.position - tileMap.transform.position; gCost = tile.gCost; }
public Node(Node other) { parent = other.parent; directionTaken = other.directionTaken; isPatheable = other.isPatheable; worldPosition = other.worldPosition; gridPosition = other.gridPosition; gCost = other.gCost; hCost = other.hCost; }
//call to start bomb rolling public void Roll(Globals.Direction direction) { LightFuse(); if (!isRolling) //remove this if statement to allow bomb to change direction mid-roll { animator.SetInteger("Direction", (int)direction); animator.SetTrigger("Roll"); isRolling = true; rollDirection = direction; } }
void Punch(Collider2D other, Globals.Direction dir) { if (other.gameObject.GetComponent <Switch>()) { other.gameObject.GetComponent <Switch>().TakeDamage(0); //check how player switches the switch isAttacking = false; } if ((other.gameObject.CompareTag("Enemy") && !evil) || (other.gameObject.CompareTag("Player") && evil)) { StartCoroutine(punchAnimationWaiting(other, dir)); //changeable } }
public void changeDirection(Globals.Direction directionToMoveTo) { for (int i = 0; i < moveList.Count; i++) { if (moveList[i].CompareTag("Turbine")) { TurbinePlantObject plant = moveList[i].GetComponent <TurbinePlantObject>(); plant.direction = directionToMoveTo; plant.setDirection(); moveList.Remove(plant.gameObject); } } }
public void StartCutScene() { tm.player = this.gameObject; musicSource = tm.GetComponent <AudioSource>(); musicSource.clip = song; musicSource.Play(); player.gameObject.SetActive(false); es = FindObjectsOfType <EnemySpawner>(); foreach (EnemySpawner e in es) { e.gameObject.SetActive(false); } pl = FindObjectsOfType <PlantGridObject>(); foreach (PlantGridObject p in pl) { p.gameObject.SetActive(false); } eo = FindObjectsOfType <EnemyGridObject>(); foreach (EnemyGridObject e in eo) { e.gameObject.SetActive(false); } dnt = FindObjectsOfType <DialogueNPCTrigger>(); foreach (DialogueNPCTrigger d in dnt) { d.gameObject.SetActive(false); } dt = FindObjectsOfType <DialogueTrigger>(); foreach (DialogueTrigger d in dt) { d.gameObject.SetActive(false); } cutScene = true; Globals.Direction left = Globals.Direction.West; Globals.Direction right = Globals.Direction.East; Globals.Direction down = Globals.Direction.South; Globals.Direction up = Globals.Direction.North; Globals.Direction[] dirs = { up, up, right, right, up, right, down, down, right, up, right, right, left, up }; StartCoroutine(MoveCameraPath1(dirs)); StartCoroutine(changeNames()); }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.CompareTag("Player")) { moveList.Add(col.gameObject); PlayerGridObject player = col.GetComponent <PlayerGridObject>(); player.platforms++; hasPlayer = true; } if (col.gameObject.CompareTag("Enemy") || col.gameObject.CompareTag("EnemySpawner")) { //there's a bug where the platform is stuck in the middle of lava if it hits a firemonster /*if (col.gameObject.GetComponent<GenericMonsterBehaviour>()) * { * return; * }*/ KillableGridObject enemy = col.GetComponentInParent <KillableGridObject>(); enemy.TakeDamage(damage); } if (!pingPong && col.gameObject.CompareTag("Turbine") && !col.gameObject.GetComponent <TurbinePlantObject>().onPlatform) { col.gameObject.GetComponent <TurbinePlantObject>().onPlatform = true; //makes sure turbine can only be on one platform if (!turbineMove) { if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.West) { direction = Globals.Direction.East; } else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.East) { direction = Globals.Direction.West; } else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.North) { direction = Globals.Direction.South; } else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.South) { direction = Globals.Direction.North; } } plant = col.gameObject.GetComponent <PlantGridObject>(); moveList.Add(col.gameObject); hasTurbine = true; turbineMove = true; } }
public AttackCollider GetHitColliderFromDirection(Globals.Direction dir) { switch (dir) { case Globals.Direction.North: return(northHitCollider); case Globals.Direction.East: return(eastHitCollider); case Globals.Direction.South: return(southHitCollider); case Globals.Direction.West: return(westHitCollider); default: return(northHitCollider); } }
public Node NextNode(Node currentNode, Globals.Direction direction) { Vector2 nextPosition = NextPosition(currentNode.gridPosition, direction); // Check to see if position is valid in grid if (IsPatheable(nextPosition)) { Tile nextTile = grid[(int)nextPosition.x, (int)nextPosition.y]; // Convert tile into Node Node nextNode = new Node(nextTile, this, currentNode, direction); return(nextNode); } else { return(null); } }
IEnumerator punchAnimationWaiting(Collider2D other, Globals.Direction dir) { yield return(new WaitForSeconds(punchAnimationWait)); if (other.gameObject.GetComponent <EnemyGridObject>() && !evil) { other.gameObject.GetComponent <EnemyGridObject>().TakeDamage(damage); } else if (other.gameObject.GetComponent <PlayerGridObject>() && evil) { other.gameObject.GetComponent <PlayerGridObject>().TakeDamage(1); } audioSource.clip = attackSound; audioSource.Play(); for (int i = 0; i < knockBackPower; i++) { other.gameObject.GetComponent <MoveableGridObject>().Move(dir); } StartCoroutine(punchCD()); //changeable }
protected void Update() { if (!dialogue) { dialogue = Globals.canvas.dialogUI; } //NPC walking up to player before dialogue if (isPlaying) { if (pixelCounter >= 32) { directionCounter++; if (directionCounter >= npcDirections.Count) { isPlaying = false; npcSpawned.GetComponent <Animator>().SetInteger("Direction", 0); ShowDialog(); return; } else { pixelCounter = 0; currentDirection = npcDirections[directionCounter]; npcSpawned.GetComponent <Animator>().SetInteger("Direction", (int)currentDirection); switch (currentDirection) { case Globals.Direction.South: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 1); break; case Globals.Direction.North: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 2); break; default: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 0); break; } } } npcSpawned.GetComponent <MoveableGridObject>().Move(currentDirection); pixelCounter++; } //NPC walking away from player after dialogue if (isEnding) { if (pixelCounter >= 32) { directionCounter--; if (directionCounter < 0) { isEnding = false; playedAlready = true; saveBool(loadedSlot); Destroy(playerSpawned); Destroy(npcSpawned); Globals.player.gameObject.SetActive(true); Destroy(this.gameObject); return; } else { pixelCounter = 0; if (npcDirections[directionCounter] == Globals.Direction.North) { currentDirection = Globals.Direction.South; } else if (npcDirections[directionCounter] == Globals.Direction.South) { currentDirection = Globals.Direction.North; } else if (npcDirections[directionCounter] == Globals.Direction.East) { currentDirection = Globals.Direction.West; } else if (npcDirections[directionCounter] == Globals.Direction.West) { currentDirection = Globals.Direction.East; } npcSpawned.GetComponent <Animator>().SetInteger("Direction", (int)currentDirection); switch (currentDirection) { case Globals.Direction.South: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 1); break; case Globals.Direction.North: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 2); break; default: npcSpawned.GetComponent <Animator>().SetInteger("Direction", 0); break; } } } npcSpawned.GetComponent <MoveableGridObject>().Move(currentDirection); pixelCounter++; } }
public PlantData(Vector3 location, string scene, Globals.Direction direction) { PlantLocation = location; PlantScene = scene; PlantDirection = direction; }
// Changes direction and direction sprite public void Rotate(Globals.Direction facing) { direction = facing; }
void Update() { if (!uic.paused && !uic.dialogue) { if (pingPong) //includes miniBoss behavior { delayCounter++; pingPongPauseCounter--; if (delayCounter > delay && pingPongPauseCounter <= 0) { pingPongDistanceCounter += 2 * moveStep; //reverse direction if (pingPongDistanceCounter > pingPongDistance) { if (direction == Globals.Direction.North) { direction = Globals.Direction.South; } else if (direction == Globals.Direction.South) { direction = Globals.Direction.North; } else if (direction == Globals.Direction.East) { direction = Globals.Direction.West; } else if (direction == Globals.Direction.West) { direction = Globals.Direction.East; } pingPongDistanceCounter = 0; pingPongPauseCounter = pingPongPause; } //move forward Vector3 position = this.transform.position; if (direction == Globals.Direction.North) { position.y += 2 * moveStep; } else if (direction == Globals.Direction.South) { position.y -= 2 * moveStep; } else if (direction == Globals.Direction.East) { position.x += 2 * moveStep; } else if (direction == Globals.Direction.West) { position.x -= 2 * moveStep; } transform.position = position; if (hasPlayer) { Vector3 playerPosition = player.transform.position; if (direction == Globals.Direction.North) { playerPosition.y += 2 * moveStep; } else if (direction == Globals.Direction.South) { playerPosition.y -= 2 * moveStep; } else if (direction == Globals.Direction.East) { playerPosition.x += 2 * moveStep; } else if (direction == Globals.Direction.West) { playerPosition.x -= 2 * moveStep; } player.transform.position = playerPosition; } delayCounter = 0; } } else if (turbineMove) { delayCounter++; if (CheckStop()) { turbineMove = false; return; } if (delayCounter < delay) { bool foundTurbine = false; foreach (GameObject obj in moveList) { if (!obj) { moveList.Remove(obj); foundTurbine = true; break; } if (obj.CompareTag("Turbine") || obj.CompareTag("Player") || obj.CompareTag("Plant") || obj.CompareTag("Platform")) { if (obj.GetComponent <TurbinePlantObject>()) { foundTurbine = true; } if (direction == Globals.Direction.East) { Vector3 position = obj.transform.position; position.x += 2 * moveStep; obj.transform.position = position; } else if (direction == Globals.Direction.West) { Vector3 position = obj.transform.position; position.x -= 2 * moveStep; obj.transform.position = position; } else if (direction == Globals.Direction.North) { Vector3 position = obj.transform.position; position.y += 2 * moveStep; obj.transform.position = position; } else if (direction == Globals.Direction.South) { Vector3 position = obj.transform.position; position.y -= 2 * moveStep; obj.transform.position = position; } } } if (!foundTurbine) { hasTurbine = false; } //delayCounter = 0; } } else if (hasTurbine && CheckStart()) { turbineMove = true; } } }
//public BoxCollider2D face; // Use this for initialization protected virtual void Start() { direction = 0; }
protected int stuckCount = 0; //frames stuck public override void Move(Globals.Direction direction) { base.Move(direction); }
// functions indicates that whether there is wall on each direction public bool isWallOn(Globals.Direction dir) { return(wallStatus[(int)dir] != 0); }
protected override IEnumerator ExecuteActionWander() { Globals.Direction dir = (Globals.Direction)UnityEngine.Random.Range(0, 4); path.Add(dir); yield return(null); }
/* deleting this function as the killablegridobject function does the same thing * public override bool TakeDamage(int damage) * { * gameObject.GetComponent<Animation>().Play("Damaged"); * return base.TakeDamage(damage); * } */ public override void Move(Globals.Direction direction) { animator.SetInteger("Direction", (int)direction); base.Move(direction); }
/// <summary> /// Get the tile that is in the given direction starting from the current tile. /// </summary> /// <param name="currentTile">Tile to start looking from.</param> /// <param name="direction">The direction to take to find the next tile.</param> public Tile NextTile(Tile currentTile, Globals.Direction direction) { return(GetNearestTile(NextPosition(currentTile.transform.position, direction))); }
/// <summary> /// Returns true if the player is in the line of sight /// </summary> /// <param name="direction">Direction enum in which to look</param> /// <returns>Boolean if the player is in line of sight</returns> public bool CanSeePlayer(Globals.Direction direction) { return(CanSeePlayer(Globals.DirectionToVector(direction))); }
/// <summary> /// Returns all gameobjects within the line of sight /// </summary> /// <param name="direction">Direction enum in which to look</param> /// <returns>An array of gameobjects within the line of sight</returns> public GameObject[] LookInDirection(Globals.Direction direction) { return(LookInDirection(Globals.DirectionToVector(direction))); }
//MoveableGridObject's Move(), plus stops rolling on obstacle collision and explodes on enemy collision public override void Move(Globals.Direction direction) { if (!(Globals.player.canvas.dialogue)) { base.Move(direction); if (direction == Globals.Direction.North && northCollider.isTriggered && northCollider.other.GetComponent <WindBossAI>()) { Explode(); } else if (direction == Globals.Direction.South && southCollider.isTriggered && southCollider.other.GetComponent <WindBossAI>()) { Explode(); } else if (direction == Globals.Direction.West && westCollider.isTriggered && westCollider.other.GetComponent <WindBossAI>()) { Explode(); } else if (direction == Globals.Direction.South && eastCollider.isTriggered && eastCollider.other.GetComponent <WindBossAI>()) { Explode(); } //this code makes the bomb explode automatically when an enemy is range /*if (direction == Globals.Direction.South) { * killList = southHitCollider.GetKillList(); * foreach (KillableGridObject other in killList) { * if (other.gameObject.GetComponent<KillableGridObject>() != null) { * if (other.gameObject.GetComponent<KillableGridObject>().faction == Globals.Faction.Enemy) { * Explode(); * break; * } * } * } * if (southCollider.isTriggered) * isRolling = false; * } * else if (direction == Globals.Direction.West) { * killList = westHitCollider.GetKillList(); * foreach (KillableGridObject other in killList) { * if (other.gameObject.GetComponent<KillableGridObject>() != null) { * if (other.gameObject.GetComponent<KillableGridObject>().faction == Globals.Faction.Enemy) { * Explode(); * break; * } * } * } * if (westCollider.isTriggered) * isRolling = false; * } * else if (direction == Globals.Direction.North) { * killList = northHitCollider.GetKillList(); * foreach (KillableGridObject other in killList) { * if (other.gameObject.GetComponent<KillableGridObject>() != null) { * if (other.gameObject.GetComponent<KillableGridObject>().faction == Globals.Faction.Enemy) { * Explode(); * break; * } * } * } * if (northCollider.isTriggered) * isRolling = false; * } * else if (direction == Globals.Direction.East) { * killList = eastHitCollider.GetKillList(); * foreach (KillableGridObject other in killList) { * if (other.gameObject.GetComponent<KillableGridObject>() != null) { * if (other.gameObject.GetComponent<KillableGridObject>().faction == Globals.Faction.Enemy) { * Explode(); * break; * } * } * } * if (eastCollider.isTriggered) * isRolling = false; * } */ } }