예제 #1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag != PlayerNum + "Attack")
        {
            SpriteHandler.spriteHandler.SetAnimation(chrAnimation, 6);
            AttackParameters collisionParams = collision.GetComponent <AttackParameters>();
            //get frame character was hit on
            float hitFrame     = frame;
            float framesToWait = collisionParams.enemyStunFrames;

            stunned   = true;
            attacking = false;

            //remove all velocity to prevent sliding in air
            rb.velocity = Vector3.zero;

            currentHP = currentHP - collisionParams.damage;
            float hit = collision.transform.position.x;


            SoundHandler.soundHandler.PlaySound(SoundHandler.soundHandler.RandomSound(soundDB.hitSounds));

            if (hit > this.transform.position.x)
            {
                rb.AddForce(collisionParams.attackForceLeft * 50f);
            }
            else if (hit < this.transform.position.x)
            {
                rb.AddForce(collisionParams.attackForceRight * 50f);
            }

            StartCoroutine(resetStates(hitFrame, framesToWait));
        }
    }
예제 #2
0
    public IEnumerator fireAttack(GameObject attack)
    {
        //prevent slide attack
        rb.velocity  = new Vector3(0, rb.velocity.y, 0.0f);
        stunned      = true;
        attackParams = attack.GetComponent <AttackParameters>();

        float attackTime = attackParams.waitFrames;
        float stunTime   = attackParams.selfStunFrames;
        float startFrame = frame;

        //wait before attack is executed
        yield return(new WaitWhile(() => startFrame > frame - attackTime));

        //make sure character is still eligible to attack
        //in the instance character has been attacked before own attack is executed
        //attack is cancelled
        if (!attacking)
        {
            print("attack cancelled");
            yield break;
        }
        SoundHandler.soundHandler.PlaySound(SoundHandler.soundHandler.RandomSound(soundDB.attackSounds));

        print("starting attack");
        Vector3 playerpos = this.transform.position;
        //Vector3 spawnPos = new Vector3(playerpos.x + bound.bounds.extents.x, playerpos.y, playerpos.z);
        Vector3 spawnPos = AttackHandler.attackHandler.SetAttackPos(attack, this.gameObject);

        if (facingLeft)
        {
            //spawn pos at other side
            spawnPos.x = playerpos.x - bound.bounds.extents.x - 0.4f;
        }
        AttackHandler.attackHandler.CreateAttack(spawnPos, attack, PlayerNum + "Attack");
        rb.velocity = new Vector3(0.0f, rb.velocity.y, 0.0f);
        //set new start frame
        startFrame = frame;

        /*handled by autodestroy.cs
         *  all moves destroyed after 10 frames
         *  yield return new WaitWhile(() => startFrame > frame - 10);
         *  Destroy(move);
         */

        //wait before stun is removed
        StartCoroutine(resetStates(startFrame, stunTime));
    }
예제 #3
0
    void Start()
    {
        rb           = GetComponent <Rigidbody2D>();
        bound        = GetComponent <BoxCollider2D>();
        chrAnimation = GetComponent <Animator>();

        soundDB = GetComponent <SoundDB>();

        crouchSpeed = speed / 2;
        runSpeed    = speed;
        currentHP   = maxHealth;

        healthBar = GameObject.Find(PlayerNum + "HP").GetComponent <Slider>();

        atk1 = attack1.GetComponent <AttackParameters>();
        atk2 = attack2.GetComponent <AttackParameters>();
        atk3 = attack3.GetComponent <AttackParameters>();
    }
예제 #4
0
    public Vector3 SetAttackPos(GameObject attackPreFab, GameObject ch)
    {
        AttackParameters attackParams = attackPreFab.GetComponent <AttackParameters>();
        string           attackType   = attackParams.attackType.ToString();
        Vector3          playerPos    = ch.transform.position;
        BoxCollider2D    bound        = ch.GetComponent <BoxCollider2D>();

        if (attackType == "High")
        {
            attackPos = new Vector3(playerPos.x + bound.bounds.extents.x + 0.4f, playerPos.y + bound.bounds.extents.y, playerPos.z);
        }
        else if (attackType == "Mid")
        {
            attackPos = new Vector3(playerPos.x + bound.bounds.extents.x + 0.4f, playerPos.y, playerPos.z);
        }
        else if (attackType == "Low")
        {
            attackPos = new Vector3(playerPos.x + bound.bounds.extents.x + 0.4f, playerPos.y - bound.bounds.extents.y, playerPos.z);
        }

        return(attackPos);
    }