protected void SetActorDepth() { Vector3 NewPos = transform.position; NewPos.z = ZDGameRule.WorldDepth(NewPos.y) + ActorTypeDepth; transform.position = NewPos; }
public override void AttackEventA(int Phase) { List <List <ZDObject> > AllHitObject = new List <List <ZDObject> >(); // Really do attack switch (Phase) { case 0: AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(1, 1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(1, -1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-1, 1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-1, -1), AttackRad), this, EObjectType.ADamage)); break; case 1: AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(1, 1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(1, -1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-1, 1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-1, -1), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(2, 2), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(2, -2), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-2, 2), AttackRad), this, EObjectType.ADamage)); AllHitObject.Add(ZDMap.HitAt(ZDGameRule.RotateVector2(new Vector2(-2, -2), AttackRad), this, EObjectType.ADamage)); break; } ApplyDamage(AllHitObject, EAttackType.A); }
Vector2 GetValidDest(Vector2 Destination) { Vector2 PosInUnit = ZDGameRule.WorldToUnit(transform.position); Vector2 DesInUnit = ZDGameRule.WorldToUnit(ZDGameRule.QuadrifyDirection(Destination, transform.position)); for (int i = 0; i < 2; ++i) { if (!PosInUnit[i].Equals(DesInUnit[i])) { int Delta = (PosInUnit[i] < DesInUnit[i] ? 1 : -1); Vector2 CurPos = PosInUnit; while (true) { //Move To Currently Checking Position. CurPos[i] += Delta; if (!ZDMap.IsUnitInMap(CurPos) || ZDMap.HitAtUnit(CurPos, EObjectType.Obstacle) != null) { //Return To Last Position. CurPos[i] -= Delta; return(ZDGameRule.UnitToWorld(CurPos)); } if (CurPos[i].Equals(DesInUnit[i])) { break; } } return(ZDGameRule.UnitToWorld(DesInUnit)); } } return(transform.position); }
protected new void Start() { ActorCustomDepthShift = (int)ZDGameRule.WorldToUnit(transform.position).x % 2 == 0 ? -1e-5f :1e-5f; base.Start(); animator = GetComponent <Animator>(); audioSource = GetComponent <AudioSource>(); ZDAudioSource.SetupAudioSource(audioSource); //StartCoroutine(PauseAndPlay()); }
// Start is called before the first frame update void Start() { //Setup Effect Vector3 NewPos = transform.position; NewPos.z = ZDGameRule.WorldActorDepth(NewPos.y, EActorType.Effect); transform.position = NewPos; //Disable Update Loop For This Scripts enabled = false; }
protected override void Sprint(Vector2 Destination) { base.Sprint(Destination); if (photonView.IsMine && TrackAvailable) { float SprintAngle = ZDGameRule.QuadAngle(SprintDestination - (Vector2)transform.position); if (TrackAngles[0].Equals(SprintAngle)) { TrackFullFilled(); } } }
protected override void Sprint(Vector2 Destination) { NewDestination = true; //Save Destination SprintDestination = ZDGameRule.WorldUnify(ZDGameRule.QuadrifyDirection(Destination, transform.position)); //PlaySound if (MoveSound && audioSource) { audioSource.PlayOneShot(MoveSound); } }
void AttackInPosition(float Damage) { Vector3 UnitPos = ZDGameRule.WorldToUnit(transform.position); List <ZDObject> HitList = ZDMap.HitAtUnit(UnitPos, EObjectType.ADamage); if (HitList != null) { foreach (var obj in HitList) { ((IADamageObject)obj).Hurt(Damage); } } }
static public void RevisePosition(ZDObject Caller) { Vector3 UnitLoc = ZDGameRule.WorldToUnit(Caller.transform.position); if (Mathf.Abs(UnitLoc.x) > ZDGameRule.MAP_WIDTH_UNIT / 2) { UnitLoc.x = (UnitLoc.x > 0 ? 1 : -1) * ZDGameRule.MAP_WIDTH_UNIT / 2; } if (Mathf.Abs(UnitLoc.y) > ZDGameRule.MAP_HEIGHT_UNIT / 2) { UnitLoc.y = (UnitLoc.y > 0 ? 1 : -1) * ZDGameRule.MAP_HEIGHT_UNIT / 2; } Caller.transform.position = ZDGameRule.UnitToWorld(UnitLoc); }
protected void Start() { InitializeTerrain(); ZDMap.Register(this); if (!IsRegistered()) { Debug.LogError("Error! Cannot Register ZDObject, Object Out of Bound!"); } //Cache ActorTypeDepth ActorTypeDepth = ZDGameRule.ActorDepth(ActorType) + ActorCustomDepthShift; //Forced Update to set object depth with type depth; SetActorDepth(); }
void FaceTo(Vector2 Direction) { //Save Attack Direction AttackRad = ZDGameRule.QuadRadius(Direction); // Set Scale Direction if (!Direction.x.Equals(0)) { sprite.flipX = Direction.x > 0 ? true: false; } Direction = ZDGameRule.QuadrifyDirection(Direction); // Set Animation Direction animator.SetInteger("AtkVertical", (int)Direction.y); animator.SetInteger("AtkHorizontal", (int)Direction.x); Debug.Log("Direction" + new Vector2(Direction.x, Direction.y)); }
public override void InputAttack(Vector2 AttackDirection, EAttackType Type) { switch (Type) { case EAttackType.N: break; default: if (Soul == (int)EAttackType.A && !ZDGameRule.QuadrifyDirection(AttackDirection).y.Equals(0)) { return; } break; } base.InputAttack(AttackDirection, Type); }
private void SpawnNewTrackMission() { if (GetSoul() < GetMaxSoul()) { TrackAvailable = true; TrackDurationTime = (GetMaxSoul() - GetSoul()) * ZDGameRule.CrossTrack.TrackDurationConst; TrackRemainTime = TrackDurationTime; TrackAngles.Clear(); for (int i = 0, _i = (int)Mathf.Pow(ZDGameRule.CrossTrack.TrackCountsConst, GetSoul() + 1); i < _i; ++i) { TrackAngles.Add(ZDGameRule.QuadAngle(Random.Range(0, 359))); } TrackInfoChanged?.Invoke(this, new TrackInfoChangeArgs(TrackAvailable, TrackAngles[0])); } }
IEnumerator CreateThunder() { int i = Random.Range(10, 15); int x, y; while (i > 0) { --i; yield return(new WaitForSeconds(Random.Range(0.05f, 0.2f))); do { x = Random.Range(-RusoAttackRRangeWidth, RusoAttackRRangeWidth + 1); y = Random.Range(-RusoAttackRRangeHeight, RusoAttackRRangeHeight + 1); } while (x == 0 && x == y); Vector2 UnitPos = (Vector2)ZDGameRule.WorldToUnit(transform.position) + new Vector2(x, y); photonView.RPC("CreateAttackREffect", RpcTarget.All, UnitPos); } }
protected void Update() { if (transform.hasChanged) { if (ZDMap.UpdateLocation(this)) { //Update Z axis to correct the in block layers. SetActorDepth(); Vector3 NewUnitLocation = ZDGameRule.WorldToUnit(transform.position); LocationChanged?.Invoke(this, new LocationChangeArgs(new Vector2Int((int)NewUnitLocation.x, (int)NewUnitLocation.y))); if (InShelter != (ZDMap.HitAtObject(this, EObjectType.Shelter) != null)) { InShelter = !InShelter; ShelterStateChanged?.Invoke(this, new ShelterStateChangeArgs(InShelter)); } } transform.hasChanged = false; } }
void AttackEvent(int eventNum) { //Initial Values Vector2Int[] HitOffsets = { new Vector2Int(0, 0) }; float HitDamage = 0; Vector2 HitOrigin = ZDGameRule.WorldToUnit(transform.position); if (eventNum < AttackDamages.Length) { HitDamage = AttackDamages[eventNum]; } if (HitOffsetsConfig != null && eventNum < HitOffsetsConfig.Length) { HitOffsets = HitOffsetsConfig[eventNum]; } List <ZDObject> HitList = new List <ZDObject>(); //Get Hitten Objects foreach (var offset in HitOffsets) { Vector2 HitPos = offset + HitOrigin; List <ZDObject> HitResult = ZDMap.HitAtUnit(HitPos, EObjectType.ADamage); if (HitResult != null) { HitList.AddRange(HitResult); } } //Apply Damages if (!HitDamage.Equals(0)) { foreach (var obj in HitList) { ((IADamageObject)obj).Hurt(HitDamage); } } }
void Update() { if (ZDGameManager.GetGameState() == ZDGameState.Play) { if (IsPhoneTest) { #region Touch Input for Single Touch if (Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { if (BagClass.GetFrameBlock()) { BagClass.SetBlockFrame(false); return; } Touch TouchTemp = Input.GetTouch(0); // TouchPos is world Position Vector2 TouchPos = Camera.main.ScreenToWorldPoint(TouchTemp.position); // UnitTouchPos is Unit Position Vector2 UnitTouchPos = ZDGameRule.WorldToUnit(TouchPos); Vector2 CharactorPos = new Vector2(TargetCharacter.transform.position.x, TargetCharacter.transform.position.y); List <ZDObject> HitObjects; if (IsMovingCharacter) { Vector2 Direction = TouchPos - CharactorPos; float Degree = ZDGameRule.QuadAngle(Direction); Vector3 Distance = ZDGameRule.WorldToUnit(TouchPos) - ZDGameRule.WorldToUnit(CharactorPos); ZDUIClass.SetMoveIndicator(TargetCharacter.transform.position, Degree, Distance.magnitude); } if (TouchTemp.phase == TouchPhase.Began) { if ((TouchPos - (Vector2)TargetCharacter.transform.position).magnitude < ZDGameRule.UNIT_IN_WORLD * ClickOnFix) { IsMovingCharacter = true; return; } else if ((HitObjects = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.ACollect)) != null) { List <ZDObject> HitCharacter = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.Character); if (HitCharacter != null) { return; } foreach (var obj in HitObjects) { if (obj is IACollectObject) { if (TargetCharacter.GetInventory().Count < TargetCharacter.GetInventoryMax()) { ((IACollectObject)obj).Collect(TargetCharacter); IsCollectItem = true; } else { break; } } } return; } else { // Activate Attack System IsMovingCharacter = false; if ((HitObjects = ZDMap.HitAtUnit(UnitTouchPos, EObjectType.ACollect)) == null && !BagClass.GetHover()) { IsSelectingAttack = true; TouchPosRecord = TouchPos; } } } else if (TouchTemp.phase == TouchPhase.Moved || TouchTemp.phase == TouchPhase.Stationary) { IsDidMovePhase = true; } else if (TouchTemp.phase == TouchPhase.Ended) { ZDUIClass.CancelMoveIndicator(); if (IsCollectItem) { IsCollectItem = false; return; } // DoMove if ((TouchTemp.deltaPosition.magnitude >= TouchMoveFix) && IsDidMovePhase) { IsTouchMove = true; } else { IsTouchMove = false; } if (IsMovingCharacter && IsTouchMove) { TargetCharacter.InputSprint(TouchPos); IsTouchMove = false; IsMovingCharacter = false; IsDidMovePhase = false; return; } else if (IsSelectingAttack) { IsSelectingAttack = false; Vector2 TouchDelta = TouchPos - TouchPosRecord; // Tap Normal Attack or Slide Skill Attack if (TouchDelta.magnitude < TapOrSlide) // This Distance is to judge how is "Tap" { TargetCharacter.InputAttack(TouchPos - (Vector2)TargetCharacter.transform.position, EAttackType.N); } else { TargetCharacter.InputAttack(TouchDelta, EAttackType.Skill); } } } } #endregion } } }
static public (uint, uint) WorldToMap(float x, float y) { return(UnitToMap(ZDGameRule.WorldToUnit(x, y, 0))); }