public void SetUp(Entity e1, Entity e2) { if (line != null) { line.gameObject.SetActive(true); line.startWidth = 0; line.endWidth = 0; Vector3[] a = GetPos(Vector2.Distance(e1.center, e2.center)).ToArray(); line.positionCount = a.Length; line.SetPositions(a); if (render1 != null) { render1.enabled = true; render1.transform.localPosition = Vector3.zero; render1.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))); } if (render2 != null) { render2.enabled = true; render2.transform.localPosition = a[a.Length - 1]; render2.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0, 360))); } transform.position = e1.center; transform.rotation = Quaternion.Euler(MathQ.DirectionToRotation((e2.center - e1.center).normalized)); StartCoroutine(UpdateSize(0.3f)); } else { Destroy(gameObject); return; } }
public RaycastHit2D GetResult(out bool hasTarget) { RaycastHit2D[] rays = Physics2D.RaycastAll(laserFirePoint.position, MathQ.QuaternionToDirection(transform.rotation), MaxDistance, layerTarget); lastMaxDistance = MaxDistance; hasTarget = false; RaycastHit2D rayss = new RaycastHit2D(); if (rays == null || rays.Length == 0) { } else { foreach (RaycastHit2D ray in rays) { if (ray.collider.GetComponent <ITakeHit>() != null) { lastMaxDistance = Vector2.Distance(ray.point, laserFirePoint.position); hasTarget = true; rayss = ray; break; } } } if (!showed) { ShowVFXHit(); showed = true; } UpdateVFXHit(); return(rayss); }
public override void Shoot(DamageData damageData) { if (nextAmountbullet == 1) { Vector3 DirShoot = damageData.Direction; BulletBase bull = pool.Spawn(id_pool_bullet, PositionStartAttack, MathQ.DirectionToQuaternion(DirShoot)) as BulletBase; SetUpDamageData(damageData); bull.StartUp(damageData); nextAmountbullet = 2; } else if (nextAmountbullet == 2) { vitriTren = true; DamageData dam = damageData.Clone; SetUpDamageData(dam); BulletBase bull = pool.Spawn(id_pool_bullet, PositionStartAttack, MathQ.DirectionToQuaternion(dam.Direction)) as BulletBase; bull.StartUp(dam); vitriTren = false; dam = damageData.Clone; SetUpDamageData(dam); bull = pool.Spawn(id_pool_bullet, PositionStartAttack, MathQ.DirectionToQuaternion(dam.Direction)) as BulletBase; bull.StartUp(dam); nextAmountbullet = 1; } }
void UpdateDirection() { if (follow != null && follow as UnityEngine.Object != null) { Vector3 targetFollow = follow.center; Vector2 Direct2 = (targetFollow - transform.position).normalized; float zx = MathQ.DirectionToRotation(Direct2).z; float zc = MathQ.DirectionToRotation(damage.Direction).z; float zz; float z = SpeedRotate * 360 * Time.deltaTime; if (!isLeft(damage.Direction, follow.center)) { zz = zc - z; } else { zz = zc + z; } if ((zz - zx) * (zc - zx) <= 0) { zz = zx; } damage.Direction = MathQ.RotationToDirection(zz); } }
protected virtual Vector3 GiatSung(Vector3 direction) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); }
private void Rotate() { if (Host == null) { return; } transform.rotation = MathQ.DirectionToQuaternion(Host.DirectFire); }
public virtual void Shoot(DamageData damageData) { Vector3 DirShoot = damageData.Direction; BulletBase bull = pool.Spawn(id_pool_bullet, PositionStartAttack, MathQ.DirectionToQuaternion(DirShoot)) as BulletBase; SetUpDamageData(damageData); bull.StartUp(damageData); }
public static void ThreeSumClosest() { List <int> list = new List <int>() { -1, 2, 1, -4 }; Assert.That(MathQ.ThreeSumClosest(list, 1) == 2); }
public static void MaxProduct() { List <int> list = new List <int>() { -2, -3, -3, 0, 1 }; Assert.That(MathQ.MaxProduct(list) == 9); }
private void OnDrawGizmos() { Gizmos.color = Color.red; for (int i = 0; i < Amount; i++) { float z = 360 * i / Amount; Gizmos.DrawLine(GetPositionSpawn(MathQ.RotationToDirection(z)), MathQ.RotationToDirection(z) * 10 + transform.position); } }
protected Vector3 GetRotationByDirection(Vector3 Direction) { if (Direction.x < 0) { Direction.x = -Direction.x; Direction.y = -Direction.y; } return(MathQ.DirectionToRotation(Direction)); }
public void StartUp(float speed, Vector2 DirectMove, int hp) { this.speedAdd = speed; this.DirectMove = DirectMove.normalized; this.hp = hp; transform.rotation = MathQ.DirectionToQuaternion(DirectMove); levelScale = (int)(hp / HpPerLevel) + 1; maxScale = levelScale; UpdateScale(); }
// Được gọi mỗi lần Update private void RotationGun() { if (Host == null) { return; } transform.rotation = MathQ.DirectionToQuaternion(Host.DirectFire); isLeftDir = Host.DirectFire.x < 0; render.flipY = isLeftDir; }
protected override void OnDrawGizmos() { base.OnDrawGizmos(); Gizmos.color = Color.red; Vector2 dir = MathQ.RotationToDirection(OffsetAngleAttack); Gizmos.DrawLine(PositionSpawnBullet, PositionSpawnBullet + dir * 10); dir = MathQ.RotationToDirection(-OffsetAngleAttack); Gizmos.DrawLine(PositionSpawnBullet, PositionSpawnBullet + dir * 10); }
protected override void OnDrawGizmos() { base.OnDrawGizmos(); Gizmos.color = Color.green; Gizmos.DrawLine(PositionStartAttack, PositionStartAttack + MathQ.RotationToDirection(transform.rotation.eulerAngles.z + OffsetA) * 5f); Gizmos.DrawLine(PositionStartAttack, PositionStartAttack + MathQ.RotationToDirection(transform.rotation.eulerAngles.z - OffsetA) * 5f); Gizmos.DrawLine(PositionStartAttack, PositionStartAttack + MathQ.RotationToDirection(transform.rotation.eulerAngles.z + OffsetB) * 5f); Gizmos.DrawLine(PositionStartAttack, PositionStartAttack + MathQ.RotationToDirection(transform.rotation.eulerAngles.z - OffsetB) * 5f); }
protected virtual void OnBeginAttack() { Vector2 dirAttack = getRotationToPlayer((TargetFire.center - PositionSpawnBullet).normalized, OffsetAngleAttack); BulletEnemy bullet = pool.Spawn(id_bul, PositionSpawnBullet, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); SetNewAction(Action.Idle); OnBeginIdle(); }
protected Vector2 getRotationToPlayer(Vector2 dir, int offset) { if (offset < 0) { offset = -offset; } offset = offset % 90; Vector3 Do = MathQ.DirectionToRotation(dir); Do += new Vector3(0, 0, Random.Range(-offset, offset)); return(MathQ.RotationToDirection(Do.z).normalized); }
public virtual void SpawnBui(int Amount, int DirZ, int Off) { if (pooling == null) { Debug.Log("Dust need Prefab"); return; } for (int i = 0; i < Amount; i++) { Vector3 pos = new Vector3(Random.Range(-RangeSpawn.x, RangeSpawn.x), Random.Range(-RangeSpawn.y, RangeSpawn.y), 0) + (Vector3)Center + Offset; Vector3 dir = MathQ.RotationToDirection(DirZ + Random.Range(-Off, Off)); (pooling.Spawn(id_dust, pos, MathQ.DirectionToQuaternion(new Vector3(0, 0, Random.Range(0, 360)))) as Dust) .SetUp(1, dir, Random.Range(RangeSpeed.x, RangeSpeed.y), Random.Range(RangeSize.x, RangeSize.y), color); } }
protected virtual void OnBeginAttack() { float z = MathQ.DirectionToRotation(DirectFire).z; for (int i = -1; i <= 1; i++) { Vector2 dirAttack = MathQ.RotationToDirection(z + OffsetAngleAttack * i); BulletEnemy bullet = pool.Spawn(id_bul, PositionSpawnBullet, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); } SetNewAction(Action.Idle); OnBeginIdle(); }
IEnumerator SpawnMeteorites(Vector2 Node1, Vector2 Node2, Vector2 Direction, bool isVer, Vector3 posZone, Vector2 posColliderEnd, Vector2 sizeColliderEnd) { yield return(new WaitForSeconds(3f)); if (colliderEnd != null) { colliderEnd.gameObject.SetActive(true); colliderEnd.transform.position = posColliderEnd; colliderEnd.size = sizeColliderEnd; } CameraMove.Instance.AddPosition(new TaretVector3("Round Hail", ((Vector2)posZone + Data.position) / 2)); PlayerController.PlayerCurrent.DirectFire = -Direction; PlayerController.PlayerCurrent.LocKDirectFire = true; WaveHail waveCurrent = Data.WavesHail[idcurrent]; float timeSpawned = 0; float timeWait = 0; float AmountPerSecond = waveCurrent.Density * (isVer ? Data.Size.x : Data.Size.y); float timeDelayPerMeteorite = 1 / AmountPerSecond; if (timeDelayPerMeteorite == 0) { Debug.Log("Timedelay = 0 nen fix lai 0.1f"); timeDelayPerMeteorite = 0.1f; } spawning = true; while (timeSpawned < waveCurrent.Time) { yield return(null); timeSpawned += Time.deltaTime; timeWait += Time.deltaTime; while (timeWait > timeDelayPerMeteorite) { Vector2 pos = GetRandomPositionInLine(Node1, Node2); Meteorite a = pool.Spawn(idMeteo, pos, MathQ.DirectionToQuaternion(Direction)) as Meteorite; a.StartUp(waveCurrent.Speed, Direction, Random.Range(waveCurrent.RangeHp.x, waveCurrent.RangeHp.y)); meteos.Add(a); a.OnDead += CheckAmountMeteorite; timeWait -= timeDelayPerMeteorite; } } if (zoneSpawn != null) { zoneSpawn.gameObject.SetActive(false); } spawning = false; }
public static void Pow() { Assert.That(MathQ.Pow(2, 5) == 32); Assert.That(MathQ.Pow(2, 6) == 64); Assert.That(MathQ.PowWithoutRecursion(2, 0) == 1); Assert.That(MathQ.PowWithoutRecursion(2, 1) == 2); Assert.That(MathQ.PowWithoutRecursion(2, 2) == 4); Assert.That(MathQ.PowWithoutRecursion(2, 3) == 8); Assert.That(MathQ.PowWithoutRecursion(2, 4) == 16); Assert.That(MathQ.PowWithoutRecursion(2, 5) == 32); Assert.That(MathQ.PowWithoutRecursion(2, 6) == 64); Assert.That(MathQ.PowMod(2, 4, 2) == 0); Assert.That(MathQ.PowMod(2, 3, 3) == 2); Assert.That(MathQ.PowMod(2, 7, 5) == 3); }
protected override void OnDrawGizmos() { base.OnDrawGizmos(); Gizmos.color = Color.green; float startAngle = 0; for (int i = 0; i < AmountBulletExtra; i++) { float angle = startAngle + 360 / AmountBulletExtra * i; if (angle > 180) { angle -= 360; } Vector3 dir = MathQ.RotationToDirection(angle); Gizmos.DrawLine(transform.position, transform.position + dir * 3f); } }
public virtual void SpawnBui(DamageData damage) { if (pooling == null) { Debug.Log("Dust need Prefab"); } Vector3 DirZ = MathQ.DirectionToRotation(damage.Direction); int Amount = damage.Damage / 2 * MutiDus; float Off = 15; for (int i = 0; i < Amount; i++) { Vector3 pos = new Vector3(Random.Range(-RangeSpawn.x, RangeSpawn.x), Random.Range(-RangeSpawn.y, RangeSpawn.y), 0) + Offset; Vector3 dir = MathQ.RotationToDirection(DirZ.z + Random.Range(-Off, Off)); pos = transform.TransformPoint(pos); (pooling.Spawn(id_dust, pos, MathQ.DirectionToQuaternion(new Vector3(0, 0, Random.Range(0, 360)))) as Dust) .SetUp(1, dir, Random.Range(RangeSpeed.x, RangeSpeed.y), Random.Range(RangeSize.x, RangeSize.y), color); } }
private void Attacking() { if (!attacked && Time.time - time_start_action > 7 * time_action / 12) { float z = Random.Range(0, 60); for (int i = 0; i < 6; i++) { float zz = z + 60 * i; Vector2 dirAttack = MathQ.RotationToDirection(zz); Vector2 vitriradan = center + dirAttack * DistancePositonSpawnBull; BulletEnemy bullet = pool.Spawn(id_bul, vitriradan, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); } attacked = true; } }
public override void Shoot(DamageData damageData) { base.Shoot(damageData); for (int i = -1; i <= 1; i += 2) { int am = (int)Random.Range(RangeAmount.x, RangeAmount.y + 1); for (int j = 0; j < am; j++) { int dolec = i * (Random.Range(OffsetA, OffsetB + 1)); Vector3 DirShoot = damageData.Direction; float z = MathQ.DirectionToRotation(DirShoot).z; z += dolec; DirShoot = MathQ.RotationToDirection(z); SetUpDamageDataExtra(damageData, DirShoot); BulletBase bullet = pool.Spawn(id_pool_bullet_extra, PositionStartAttack, Quaternion.identity) as BulletBase; bullet.StartUp(damageData); } } }
public virtual void Dead() { if (pooling == null) { Debug.Log("Dust need Prefab"); return; } float DirZ = 0; int Amount = 60; float Off = 180; for (int i = 0; i < Amount; i++) { Vector3 pos = new Vector3(Random.Range(-RangeSpawn.x, RangeSpawn.x), Random.Range(-RangeSpawn.y, RangeSpawn.y), 0) + Offset; Vector3 dir = MathQ.RotationToDirection(DirZ + Random.Range(-Off, Off)); pos = transform.TransformPoint(pos); (pooling.Spawn(id_dust, pos, MathQ.DirectionToQuaternion(new Vector3(0, 0, Random.Range(0, 360)))) as Dust) .SetUp(1, dir, Random.Range(RangeSpeed.x, RangeSpeed.y), Random.Range(RangeSize.x, RangeSize.y), color); } }
private void Attacking2() { float startAngle = MathQ.DirectionToRotation(DirectFire).z - 20; startAngle = startAngle < -180 ? startAngle + 360 : startAngle; for (int i = 0; i < 2; i++) { float angle = startAngle + i * 20; if (angle >= 180) { angle -= 360; } Vector3 Direction = MathQ.RotationToDirection(angle); DamageData damage = new DamageData(); SetUpDamageData(damage); damage.Direction = Direction; BulletFollow bul = pool.Spawn(id_bull, positionSpawnBullet, MathQ.DirectionToQuaternion(Direction)) as BulletFollow; bul.SetTarget(Find.FindTargetNearest(center, 7f, targetFolow)); bul.StartUp(damage); } }
protected override Vector3 GiatSung(Vector3 direction) { if (nextAmountbullet == 1) { return(base.GiatSung(direction)); } else { if (vitriTren) { if (isLeftDir) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, 0)); return(MathQ.RotationToDirection(Do.z).normalized); } else { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(0, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); } } else { if (isLeftDir) { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(0, DoGiat / 2)); return(MathQ.RotationToDirection(Do.z).normalized); } else { Vector3 Do = MathQ.DirectionToRotation(direction); Do += new Vector3(0, 0, Random.Range(-DoGiat / 2, 0)); return(MathQ.RotationToDirection(Do.z).normalized); } } } }
void Spawn() { if (bulletPrefab == null || !spawning) { return; } float z = Random.Range(0, 360 / Amount); for (int i = 0; i < Amount; i++) { float newZ = z + 360 * i / Amount; if (newZ > 180) { newZ -= 360; } Vector3 dir = MathQ.RotationToDirection(newZ); BulletBase bul = pool.Spawn(id_bul, GetPositionSpawn(dir), Quaternion.Euler(MathQ.DirectionToRotation(dir)), null) as BulletBase; DamageData damage = SetUpDamageData(); damage.Direction = dir; bul.StartUp(damage); } }
private void Spawn() { if (pooling == null) { return; } float startAngle = MathQ.DirectionToRotation(damage.Direction).z + Random.Range(0, 360 / AmountBulletExtra); for (int i = 0; i < AmountBulletExtra; i++) { DamageData damage = this.damage.Clone; float angle = startAngle + 360 / AmountBulletExtra * i; if (angle > 180) { angle -= 360; } Vector3 dir = MathQ.RotationToDirection(angle); damage.Direction = dir; BulletExtraBoring bull = pooling.Spawn(id_pooling, transform.position, Quaternion.identity) as BulletExtraBoring; bull.StartUp(damage); bull.skipGameobject = targetHit; } }