public void EnemyMovementLogic_shouldNotDamageIfNotPlayer() { bool isDying = false; bool shouldDamage = EnemyMovementLogic.shouldDamageHappen("NotShadowTed", "NotPlayer", isDying); Assert.AreEqual(shouldDamage, false); }
private void FixedUpdate() { // set a position relative to me where my line casts should start Vector2 myVec2Position = myTransform.position.toVector2(); Vector2 lineCastPos = myVec2Position - myTransform.right.toVector2() * myWidth + Vector2.up * myHeight; // determine if something is in front of me Debug.DrawLine(lineCastPos, lineCastPos - myTransform.right.toVector2() * lookAhead); bool isBlocked = Physics2D.Linecast(lineCastPos, lineCastPos - myTransform.right.toVector2() * lookAhead, enemyMask); // determine if I am about to fall off an edge. bool GroundInFrontOfMe = Physics2D.Linecast(lineCastPos, lineCastPos + Vector2.down * 2, enemyMask); Debug.DrawLine(lineCastPos, lineCastPos + Vector2.down); // if he is blocked he will aways turn, he will turn on an edge if avoidFalling is true if (EnemyMovementLogic.shouldTurnHappen(GroundInFrontOfMe, avoidFalling, isBlocked)) { Vector3 currentRotation = myTransform.eulerAngles; currentRotation.y += 180; myTransform.eulerAngles = currentRotation; } Vector2 myVel = myBody.velocity; myVel.x = -myTransform.right.x * speed; myBody.velocity = myVel; }
public void EnemyMovementLogic_shouldTurnIfBlocked() { bool cliffAproaching = false; bool avoidFalling = true; bool isBlocked = true; bool shouldTurn = EnemyMovementLogic.shouldTurnHappen(cliffAproaching, avoidFalling, isBlocked); Assert.AreEqual(shouldTurn, true); }
public void EnemyMovementLogic_shouldNotTurnIfCliffButNotAvoidFalling() { bool groundInFrontOfMe = true; bool avoidFalling = false; bool isBlocked = false; bool shouldTurn = EnemyMovementLogic.shouldTurnHappen(groundInFrontOfMe, avoidFalling, isBlocked); Assert.AreEqual(shouldTurn, false); }
/// <summary> /// CollisionEnter is used to determine if the Enemy is Hurting Ted /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionEnter2D(Collision2D other) { if (EnemyMovementLogic.shouldDamageHappen(this.tag, other.gameObject.tag, isDying)) { FindObjectOfType <GameManager>().takeDamage(1); soundManager.PlaySound("ouch"); other.gameObject.GetComponent <Animator>().SetTrigger("ouch"); } }
/// <summary> /// TriggerEnter is used to determine if Ted is stomping the enemy. /// </summary> /// <param name="other">The other Collider2D involved in this collision.</param> void OnTriggerEnter2D(Collider2D other) { if (EnemyMovementLogic.shouldStompHappen(this.tag, other.tag)) { isDying = true; anim.SetTrigger("die"); other.GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, 2000f)); other.GetComponent <Animator>().SetTrigger("jump"); soundManager.PlaySound("stomp"); Destroy(this.gameObject, .3f); ScoreScript.scoreValue += 5; } }