Esempio n. 1
0
 internal bool IsVisibleBy(Slasher slasher, char[,] map)
 {
     if (this.Position.y == slasher.Position.y)
     {
         for (int i = (int)(this.Position.x < slasher.Position.x?this.Position.x:slasher.Position.x); i < (int)(this.Position.x > slasher.Position.x?this.Position.x:slasher.Position.x); i++)
         {
             if (map[i, (int)this.Position.y] != '.')
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         for (int i = (int)(this.Position.y < slasher.Position.y?this.Position.y:slasher.Position.y); i < (int)(this.Position.y > slasher.Position.y?this.Position.y:slasher.Position.y); i++)
         {
             if (map[(int)this.Position.x, i] != '.')
             {
                 return(false);
             }
         }
         return(true);
     }
 }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.GetComponent <SpikeScript>() != null && canGetHurt && !dead)
        {
            //ground is spikes
            HurtPlayer(8, 5);
        }
        else if (collision.gameObject.tag == "Pit")
        {
            //hit a pit, fall
            FallInPit();
        }
        else if (collision.gameObject.tag == "SavePoint")
        {
            MultiplayerRunManager.Instance.player2RespawnPoint = collision.gameObject.transform.position;
        }
        //check to see if hit a person with our axe
        Slasher      slash  = collision.gameObject.GetComponentInParent <Slasher>();
        SlasherLocal lslash = collision.gameObject.GetComponentInParent <SlasherLocal>();

        if ((slash || lslash) && collision.gameObject.transform.parent != transform && canGetHurt && !collision.gameObject.CompareTag("Hurtbox"))
        {
            //TODO: BOTH trigger and RigidBody2D receive this message. Check here to see if the trigger involved is ours or not (if so, this is our hit, do nothing, else, we were hit by someone else, get hurt)
            Vector2 dir   = (transform.position - collision.gameObject.transform.parent.position).normalized;
            float   angle = Vector2.SignedAngle(Vector2.right, dir);
            print("DIRECTION: " + dir + "ANGLE: " + angle);
            HurtPlayer(0, -1, true, angle);
        }
    }
Esempio n. 3
0
 /// <summary>
 /// Handles collision logic
 ///
 /// SERVER: handles collisions
 /// </summary>
 /// <param name="collision"></param>
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (isServer)
     {
         //if weapon, decrease health
         if (collision.gameObject.CompareTag("Weapons"))
         {
             Slasher      sl  = collision.gameObject.GetComponentInParent <Slasher>();
             SlasherLocal lsl = null;
             if (!sl)
             {
                 lsl = collision.gameObject.GetComponentInParent <SlasherLocal>();
                 if (lsl)
                 {
                     //notify server
                     DamageBoss(lsl.damagePerSwing);
                     //increment that player's score
                     int scoringPlayer = collision.gameObject.GetComponentInParent <LocalPlayerIdentity>().ID;
                     BossManager.Instance.UpdateScore(scoringPlayer, lsl.damagePerSwing);
                 }
             }
             if (sl)
             {
                 //notify server
                 DamageBoss(sl.damagePerSwing);
                 //increment that player's score
                 NetworkConnection scoringPlayer = collision.gameObject.GetComponentInParent <NetworkIdentity>().connectionToClient;
                 BossManager.Instance.UpdateScore(scoringPlayer.connectionId, sl.damagePerSwing);
             }
         }
     }
 }
Esempio n. 4
0
    public void UpdateAttack()
    {
        Slasher slasher = GetComponent <Slasher>();

        slasher.AttackNow();

        Vector3 attackDirection = transform.position - attackTarget.transform.position;

        attackDirection = VectorUtil.Set2DLength(attackDirection, attackDistance);
        moveTarget      = attackTarget.transform.position + attackDirection;
        StepTowards(moveTarget);
    }
Esempio n. 5
0
 // Start is called before the first frame update
 void Start()
 {
     mvr = GetComponent <PlayerMovement>();
     if (!mvr)
     {
         lmvr = GetComponent <PlayerMovementLocal>();
     }
     slash = GetComponent <Slasher>();
     if (!slash)
     {
         lslash = GetComponent <SlasherLocal>();
     }
     colHand = GetComponent <CollisionHandler>();
     if (!colHand)
     {
         lcolHand = GetComponent <CollisionHandlerLocal>();
     }
     rb           = GetComponent <Rigidbody2D>();
     anim         = GetComponent <Animator>();
     achievements = AcheivementScript.Instance;
 }
Esempio n. 6
0
    /// <summary>
    /// Toggles collision and movement logic for pits
    /// </summary>
    public void ToggleInteractivity(bool toggle)
    {
        //toggle movement
        PlayerMovement m = GetComponent <PlayerMovement>();

        if (toggle)
        {
            m.SetMove();
        }
        else
        {
            m.DisableMove();
        }
        //toggle all triggers/hitboxes in system, toggle weapons off but never on
        foreach (BoxCollider2D col in GetComponentsInChildren <BoxCollider2D>())
        {
            if (!col.gameObject.CompareTag("Weapons") || !toggle)
            {
                col.enabled = toggle;
            }
        }
        GetComponent <BoxCollider2D>().enabled = toggle;
        //toggle velocity
        if (!toggle)
        {
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
        }
        else
        {
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
        }

        Slasher sl = GetComponent <Slasher>();

        if (sl.isSwinging)
        {
            sl.EndSlash();
        }
    }