/// <summary> /// Adds a step to the queue internally. /// </summary> /// <param name="x">X coordinate of step.</param> /// <param name="y">Y coordinate of step.</param> private void AddStepInternal(short x, short y) { // Check to see if the current count of queues overflows the capacity limit. if (this.writePosition >= WalkingQueue.Capacity) { /* * The character most likely is a bot, cause * normal characters cannot reach this limit. */ return; } // Get differences. short diffX = (short)(x - this.points[this.writePosition - 1].X); short diffY = (short)(y - this.points[this.writePosition - 1].Y); // Caclulate direction from differences. sbyte direction = DirectionUtilities.CalculateDirection(diffX, diffY); // We only need to enqueue the point if the direction is valid. if (direction > -1) { // Enqueue the calculated point. this.points[this.writePosition++] = new MovementPoint(x, y, direction); } }
// Token: 0x060000CA RID: 202 RVA: 0x00004E74 File Offset: 0x00003074 public virtual void PlayAttackSlash(Vector3 target, HitInfo hit) { Player.NailStrikePool.Instantiate(target, Quaternion.identity); GameObject gameObject = Player.SlashImpactPool.Instantiate(target, Quaternion.identity); switch (DirectionUtilities.DegreesToDirection(hit.Direction)) { case CardinalDirection.Up: this.SetRotation2D(gameObject.transform, (float)UnityEngine.Random.Range(70, 110)); gameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1f); break; case CardinalDirection.Down: this.SetRotation2D(gameObject.transform, (float)UnityEngine.Random.Range(70, 110)); gameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1f); break; case CardinalDirection.Left: this.SetRotation2D(gameObject.transform, (float)UnityEngine.Random.Range(340, 380)); gameObject.transform.localScale = new Vector3(-1.5f, 1.5f, 1f); break; case CardinalDirection.Right: this.SetRotation2D(gameObject.transform, (float)UnityEngine.Random.Range(340, 380)); gameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1f); break; } }
public void RecoilByDamage(HitInfo hit) { int attackDirection = 0; CardinalDirection cardinalDirection = DirectionUtilities.DegreesToDirection(hit.Direction); if (cardinalDirection != CardinalDirection.Up) { if (cardinalDirection != CardinalDirection.Down) { if (cardinalDirection == CardinalDirection.Left) { attackDirection = 2; } } else { attackDirection = 3; } } else { attackDirection = 1; } base.RecoilByDirection(attackDirection, hit.AttackStrength); }
// FOR TESTING ONLY //protected void OnMouseUp() //{ // TestLevelManager.Instance.GoToLevel(1 - TestLevelManager.Instance.CurrentLevel); //} // protected virtual void StartAttacking(PlayerController player) { _isAttacking = true; _animator.AnimateAttack(); // Attacking will also change our direction. CurrentDirection = DirectionUtilities.DirectionFromVector(player.transform.position - transform.position); _animator.AnimateDirection(CurrentDirection); }
private void Animate(Vector2 direction) { if (!_isAttacking) { if (direction == Vector2.zero) { _animator.AnimateIdle(); } else { CurrentDirection = DirectionUtilities.DirectionFromVector(direction); _animator.AnimateMove(CurrentDirection); } } }
public GameObject Instantiate(float damage, int aliveFrames, Direction direction) { Vector2 translation = DirectionUtilities.VectorFromDirection(direction); // Scale the translation to make it spawn closer or farther. translation *= HitBoxDistance; GameObject spawned = Instantiate(_hitBox, transform.position + (Vector3)translation, Quaternion.identity); // Set the hitbox settings. TempHitBox hb = spawned.GetComponent <TempHitBox>(); hb.Damage = damage; hb.AliveFrames = aliveFrames; return(spawned); }
private void SpawnEnemyInFront() { // We need to see how far in front to spwan the enemy. // This will be done by straight up casting a ray in front of us and spawning an enemy in between us and the collider we detect, if any. Vector2 rayDir = DirectionUtilities.VectorFromDirection(CurrentDirection); const float rayDist = 2; float spawnDist = rayDist / 2; // I have to do the raycast in this janky way because my own collider gets in the way. // This way has the ray persist. RaycastHit2D[] hits = new RaycastHit2D[2]; int numHits = Physics2D.Raycast(transform.position, rayDir, new ContactFilter2D(), hits, rayDist); if (numHits > 1) { // Adjust the spawn distance for the collider we hit. spawnDist *= hits[1].fraction; } else if (numHits == 1 && hits[0].fraction == 0) { // I know you are not supposed to check equality with floats, but the Unity docs said the fraction will ALWAYS be 0 when colliding with itself. // Makes sense. spawnDist *= hits[0].distance; } // We cannot spawn the enemy too close to us. if (spawnDist > 0.2) { SkullSwordsman enemy = EnemiesManager.Instance.SpawnEnemy <SkullSwordsman>((Vector2)transform.position + rayDir * spawnDist); // This enemy is going to track the same player. enemy.Target = Target; // We do not want these enemies to re-appear when reloading the game. enemy.IsPersistent = false; // Have this enemy wander around waypoints if some were provided. if (_waypoints != null && _waypoints.Length >= 2) { enemy.Waypoints = _spawnWaypoints.OrderBy(wp => Vector2.Distance(wp.position, enemy.transform.position)).Take(2).ToArray(); } // To prevent to many enemies, we will kill this guy after some time. KillEnemyAfter(enemy, SpawnedEnemyAliveTimeSeconds); } }
public void TryParseCanHandleArbitraryCharacters(char input) { Direction?expectedResult = (input) switch { 'N' => Direction.N, 'n' => Direction.N, 'E' => Direction.E, 'e' => Direction.E, 'S' => Direction.S, 's' => Direction.S, 'W' => Direction.W, 'w' => Direction.W, _ => null }; var actualResult = DirectionUtilities.TryParse(input); actualResult.ShouldBe(expectedResult); }
public void PlayHitEffect(HitInfo hit, Vector3 effectsOffset = default(Vector3)) { if (!firedOnCurrentFrame) { firedOnCurrentFrame = true; WeaverAudio.PlayAtPoint(DamageSound, transform.position, channel: AudioChannel.Sound); if (doFlashEffects) { flasher.FlashNormalHit(); } GameObject hitParticles = Instantiate(Assets.EffectAssets.UninfectedHitPrefab, transform.position + effectsOffset, Quaternion.identity); //GameObject hitParticles = Pooling.Instantiate(Assets.EffectAssets.UninfectedHitPrefab, transform.position + effectsOffset, Quaternion.identity); var direction = DirectionUtilities.DegreesToDirection(hit.Direction); switch (direction) { case CardinalDirection.Up: SetRotation2D(hitParticles.transform, 45f); break; case CardinalDirection.Down: SetRotation2D(hitParticles.transform, 225f); break; case CardinalDirection.Left: SetRotation2D(hitParticles.transform, -225f); break; case CardinalDirection.Right: SetRotation2D(hitParticles.transform, -45f); break; } Flings.SpawnFlings(NormalFlings, transform.position + effectsOffset, direction); } }
/// <summary> /// Gets the next point. /// </summary> /// <returns>Returns the point's direction.</returns> private sbyte GetNextPoint() { // Nothing to read. if (this.readPosition == this.writePosition) { return(-1); } MovementPoint mp = points[this.readPosition++]; sbyte dir = DirectionUtilities.CalculateDirection(this.npc.Location.X, this.npc.Location.Y, mp.X, mp.Y); /* * You cannot search though an array with a negative number, * so we must check if the direction is higher than -1. */ if (dir != -1) { dir >>= 1; this.npc.Location = Location.Create(mp.X, mp.Y, this.npc.Location.Z); } return(dir); }
public void PlayHitEffect(HitInfo hit, Vector3 effectsOffset = default(Vector3)) { if (!firedOnCurrentFrame) { firedOnCurrentFrame = true; var audio = WeaverAudio.PlayAtPoint(DamageSound, transform.position, channel: AudioChannel.Sound); audio.AudioSource.pitch = UnityEngine.Random.Range(audioPitchMin, audioPitchMax); //DamageFlashPool.Instantiate(transform.position + effectsOffset, Quaternion.identity); Pooling.Instantiate(DamageFlash, transform.position + effectsOffset, Quaternion.identity); if (doFlashEffects) { flasher.flashInfected(); } switch (DirectionUtilities.DegreesToDirection(hit.Direction)) { case CardinalDirection.Up: if (doBlood) { Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Up); } //HitPuffPool.Instantiate(transform.position, Quaternion.Euler(270f, 90f, 270f)); Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(270f, 90f, 270f)); break; case CardinalDirection.Down: if (doBlood) { Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Down); } Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(-72.5f, -180f, -180f)); break; case CardinalDirection.Left: if (doBlood) { Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Left); } Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(180f, 90f, 270f)); break; case CardinalDirection.Right: if (doBlood) { Blood.SpawnDirectionalBlood(transform.position + effectsOffset, CardinalDirection.Right); } Pooling.Instantiate(HitPuff, transform.position, Quaternion.Euler(0f, 90f, 270f)); break; } //GameObject hitParticles = Instantiate(Assets.EffectAssets.UninfectedHitPrefab, transform.position + effectsOffset, Quaternion.identity); //GameObject hitParticles = InfectedHitPool.Instantiate(transform.position + effectsOffset, Quaternion.identity); /*var direction = DirectionUtilities.DegreesToDirection(hit.Direction); * * switch (direction) * { * case CardinalDirection.Up: * SetRotation2D(hitParticles.transform, 45f); * break; * case CardinalDirection.Down: * SetRotation2D(hitParticles.transform, 225f); * break; * case CardinalDirection.Left: * SetRotation2D(hitParticles.transform, -225f); * break; * case CardinalDirection.Right: * SetRotation2D(hitParticles.transform, -45f); * break; * } * * Flings.SpawnFlings(NormalFlings, transform.position + effectsOffset, direction);*/ } }