Beispiel #1
0
 /// <summary>
 /// Checks hitbox collisions with enemies
 /// ***AND applies damage***
 /// </summary>
 /// <param name="hitbox">Hitbox to check</param>
 /// <param name="enemies">List of enemies to attack</param>
 /// <returns>Whether or not they hit</returns>
 protected bool CheckCollisionsWithEnemies(Rect hitbox)
 {
     //Don't bother with any of this if we hit an enemy this attack
     if (!hitPlayer)
     {
         Rect  newHB = hitbox;
         Enemy e;
         if (hitBoxDirectionMove < 0)
         {
             newHB = new Rect((hitbox.x + hitbox.width) * -1, hitbox.y, hitbox.width, hitbox.height);
         }
         //Loop through all enemies
         for (int i = 0; i < enemyMan.encounterEnemies.Count; ++i)
         {
             e = enemyMan.encounterEnemies[i].GetComponent <Enemy>();
             //Only bother with ones that aren't allied with the player
             if (!e.alliedWithPlayer)
             {
                 //See if our hitbox hit them
                 if (Helper.AABB(Helper.LocalToWorldRect(newHB, this.transform.position), e.HitBoxRect))
                 {
                     hitPlayer = true;
                     e.TakeDamage(atDamage, PlayerCombat.Attacks.Slash);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
    protected override void Update()
    {
        // stay a purplish hue, Ponyboy
        if (base.lightTimer <= 0)
        {
            //base.enemyLight = gameObject.AddComponent<Light>();
            //base.enemyLight.range = 3.5f;
            base.enemyLight.intensity = 3;
            base.enemyLight.color     = Color.magenta;
        }

        //BASE UPDATE
        base.Update();

        //Check shine hit
        if (shinedCooldown > 0 && playerCombat.CurrentAttack == PlayerCombat.Attacks.Shine)
        {
            List <Rect> shineHitboxes = playerCombat.GetActiveAttackHitboxes();
            for (int i = 0; i < shineHitboxes.Count; ++i)
            {
                if (Helper.AABB(this.HitBoxRect, shineHitboxes[i]))
                {
                    //Increment times shined but stay within range
                    if (++shinedIncrements > shinedMaxIncrements)
                    {
                        shinedIncrements = shinedMaxIncrements;
                    }
                    //Cooldown for 1 sec so we don't register this multiple times
                    shinedCooldown = 1f;
                }
            }
            shinedCooldown -= Time.deltaTime;
        }
    }
Beispiel #3
0
    /// <summary>
    /// Performs the shine and resolves hitbox collisions
    /// </summary>
    /// <param name="hitbox">Hitbox of the shine to test</param>
    protected void Shine(Rect hitbox)
    {
        ///TODO: collision detection for projectiles, once projectiles are implemented
        //Get enemy active hitboxes
        Rect[]       hitboxes = new Rect[3];
        List <Enemy> enemies  = new List <Enemy>();

        for (int i = 0; i < enemyMan.encounterEnemies.Count; ++i)
        {
            enemies.Add(enemyMan.encounterEnemies[i].GetComponent <Enemy>());
        }
        //Update hitbox direction
        Rect newHB = hitbox;

        if (hitBoxDirectionMove < 0)
        {
            newHB = new Rect((hitbox.x + hitbox.width) * -1, hitbox.y, hitbox.width, hitbox.height);
        }
        //Loop through 'em
        for (int i = 0; i < enemies.Count; ++i)
        {
            //Check for collision
            hitboxes[0] = enemies[i].atHB1;
            hitboxes[1] = enemies[i].atHB2;
            hitboxes[2] = enemies[i].atHB3;
            for (int j = 0; j < 3; ++j)
            {
                if (Helper.AABB(Helper.LocalToWorldRect(newHB, this.transform.position), Helper.LocalToWorldRect(hitboxes[j], enemies[i].transform.position)))
                {
                    //Check to see if they're attacking to determine if hit is a counter or not
                    if (enemies[i].IsAttacking)
                    {
                        Debug.Log("Shine counter");
                        enemies[i].BreakGuard(6f);
                        enemies[i].SetLightTime(5);
                        shRecovery = 1;
                        break;
                    }
                    else // hit is not a counter
                    {
                        enemies[i].SetLightTime(1.5f);
                    }
                }
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Returns true if the enemy hit the player
    /// </summary>
    /// <param name="hitbox">Hitbox to check with</param>
    /// <returns>Whether or not the player was hit</returns>
    protected bool CheckCollisionsWithPlayer(Rect hitbox)
    {
        Rect newHB = hitbox;

        if (hitBoxDirectionMove < 0)
        {
            newHB = new Rect((hitbox.x + hitbox.width) * -1, hitbox.y, hitbox.width, hitbox.height);
        }
        // check if the enemy has hit the player before the hitPlayer variable was returned to false.
        // IF THIS METHOD IS EVER USED TO CHECK COLLISIONS WITH ANYTHING BESIDES THE PLAYER, ENSURE THE CHECK ONLY HAPPENS IF THE TARGET IS THE PLAYER
        bool hit = (hitPlayer == false && (Helper.AABB(Helper.LocalToWorldRect(newHB, this.transform.position), player.GetComponent <PlayerCombat>().HitBoxRect)));

        if (hit == true)
        {
            hitPlayer = true;              // set hitPlayer to true so this attack can't hit more than once
        }
        return(hit);
    }
Beispiel #5
0
    /// <summary>
    /// Tests collisions with all enemies
    /// </summary>
    /// <param name="hitbox">Hitbox to compare with enemies</param>
    /// <returns>A list of all enemies collided with</returns>
    protected List <Enemy> CheckCollisions(Rect hitbox)
    {
        List <Enemy> hit   = new List <Enemy>();
        Rect         newHB = GetHitboxSided(hitbox);

        for (int i = 0; i < hittableEnemies.Count; ++i)
        {
            Enemy e = hittableEnemies[i].GetComponent <Enemy>();
            if (Helper.AABB(Helper.LocalToWorldRect(newHB, this.transform.position), e.HitBoxRect))
            {
                hit.Add(e);
                //Remove enemies we hit so we don't hit them again this frame
                hittableEnemies.RemoveAt(i);
                --i;
                //e.TakeDamage(slDamage);
            }
        }
        return(hit);
    }