private Vector3 GetPositionOnHoleEntry(HoleEntry holeEntry) { if (holeEntry.facing == Border.Facing.Top) { return(new Vector3(holeEntry.position.x, holeEntry.position.y + 1, 0)); } if (holeEntry.facing == Border.Facing.Bottom) { return(new Vector3(holeEntry.position.x, holeEntry.position.y - 1, 0)); } if (holeEntry.facing == Border.Facing.Left) { return(new Vector3(holeEntry.position.x - 1, holeEntry.position.y, 0)); } if (holeEntry.facing == Border.Facing.Right) { return(new Vector3(holeEntry.position.x + 1, holeEntry.position.y + 1, 0)); } return(Vector3.zero); }
private Vector3 GetEulerAnglesOnHoleEntry(HoleEntry holeEntry) { if (holeEntry.facing == Border.Facing.Top) { return(new Vector3(0, -180, 0)); } if (holeEntry.facing == Border.Facing.Bottom) { return(new Vector3(0, -180, 180)); } if (holeEntry.facing == Border.Facing.Left) { return(new Vector3(0, -180, -90)); } if (holeEntry.facing == Border.Facing.Right) { return(new Vector3(0, -180, 90)); } return(Vector3.zero); }
public HoleEntry GetFurthestHoleEntry(params Vector2[] positions) { HoleEntry furthestHoleEntry = null; float furthestHoleEntryDistance = 0; foreach (HoleEntry holeEntry in this.HoleEntries) { float holeEntryDistance = 0; foreach (Vector2 position in positions) { holeEntryDistance += Vector2.Distance(position, holeEntry.position); } if (furthestHoleEntry == null || holeEntryDistance > furthestHoleEntryDistance) { furthestHoleEntry = holeEntry; furthestHoleEntryDistance = holeEntryDistance; } } return(furthestHoleEntry); }
public HoleEntry GetClosestHoleEntry(params Vector2[] positions) { HoleEntry closestHoleEntry = null; float closestHoleEntryDistance = 0; foreach (HoleEntry holeEntry in this.HoleEntries) { float holeEntryDistance = 0; foreach (Vector2 position in positions) { holeEntryDistance += Vector2.Distance(position, holeEntry.position); } if (closestHoleEntry == null || holeEntryDistance < closestHoleEntryDistance) { closestHoleEntry = holeEntry; closestHoleEntryDistance = holeEntryDistance; } } return(closestHoleEntry); }
private Vector3 GetPositionInHoleEntry(HoleEntry holeEntry) { return(new Vector3(holeEntry.position.x, holeEntry.position.y, 0)); }
private void TeleportToHoleEntry(HoleEntry holeEntry) { this.transform.position = holeEntry.position; this.model.localPosition = new Vector3(0, -1.1f, 0); }
IEnumerator State_Attack1() { if (this.previousState == State.DigOut) { this.musicController.FadeToVolume(0.2f, 1, 1); this.musicController.PlayJumpOut(); } HoleEntry holeEntry = this.GetHoleEntryBehindTarget(); Vector3 targetPosition = this.GetPositionOnHoleEntry(holeEntry); Vector3 targetEulerAngles = this.GetEulerAnglesOnHoleEntry(holeEntry); float distanceToTarget = Vector2.Distance(this.transform.position, targetPosition); float jumpTime = distanceToTarget / this.jumpSpeed; iTween.MoveTo(this.gameObject, iTween.Hash("position", targetPosition, "time", jumpTime, "easeType", this.jumpMoveEaseType)); //iTween.RotateTo(this.gameObject, iTween.Hash("rotation", targetEulerAngles, "time", jumpTime, "easeType", this.jumpRotateEaseType)); iTween.LookTo(this.gameObject, iTween.Hash("lookTarget", targetPosition, "time", 0.15f * jumpTime, "easeType", this.jumpRotateStartEaseType)); //this.transform.eulerAngles = halfTargetEulerAngles; this.Invoke(() => iTween.RotateTo(this.gameObject, iTween.Hash("rotation", targetEulerAngles, "time", 0.15f * jumpTime, "easeType", this.jumpRotateEndEaseType)), 0.95f * jumpTime); yield return(new WaitForSeconds(0.05f)); bool attacked = false; for (float time = 0; time < jumpTime; time += Time.deltaTime) { float distanceToPlayer = Vector2.Distance(this.transform.position, this.target.transform.position); if (!attacked && distanceToPlayer < this.attackRange) { attacked = true; this.target.ReceiveDamage(3); this.gameController.ScreenShake(); } yield return(new WaitForEndOfFrame()); } this.transform.localEulerAngles = this.GetEulerAnglesOnHoleEntry(holeEntry); yield return(new WaitForSeconds(1f)); this.attackCounter += 1; // Next state if (this.attackCounter < this.maxAttackAttempts) { if (this.forcePoisonAttack) { this.forcePoisonAttack = false; if (Random.Range(0, 2) == 0) { this.SetState(State.Attack2); } else { this.SetState(State.Attack1); } } else { if (Random.Range(0, 4) == 0) { this.SetState(State.Attack2); } else { this.SetState(State.Attack1); } } } else { this.SetState(State.DigIn); } }