Exemplo n.º 1
0
        private void Awake()
        {
            // Setup dictionary from ScriptableObject data
            foreach (FighterData data in FighterDataList)
            {
                data.SetupDictionary();
            }

            Fighter1 = new Fighter();
            Fighter2 = new Fighter();

            Fighters.Add(Fighter1);
            Fighters.Add(Fighter2);

            debugP2Attack = false;
            debugP2Guard  = false;

            if (roundUI != null)
            {
                RoundUIAnimator = roundUI.GetComponent <Animator>();
            }

            stateMachine = new StateMachine();
            stateMachine.AddState(new StopState(this));
            stateMachine.AddState(new IntroState(this));

            FightState fightState = new FightState(this);

            fightState.DamageOccurred += (damaged, damagePos, damageResult) => DamageOccurred?.Invoke(damaged, damagePos, damageResult);             // TODO refactor this
            stateMachine.AddState(new FightState(this));
            stateMachine.AddState(new KOState(this));
            stateMachine.AddState(new EndState(this));

            stateMachine.SetState <StopState>();
        }
Exemplo n.º 2
0
        private void UpdateHitboxHurtboxCollision()
        {
            foreach (Fighter attacker in battleCore.Fighters)
            {
                Vector2 damagePos   = Vector2.zero;
                bool    isHit       = false;
                bool    isProximity = false;
                int     hitAttackID = 0;

                foreach (Fighter damaged in battleCore.Fighters)
                {
                    if (attacker == damaged)
                    {
                        continue;
                    }

                    foreach (Hitbox hitbox in attacker.Hitboxes)
                    {
                        // continue if attack already hit
                        if (!attacker.CanAttackHit(hitbox.AttackID))
                        {
                            continue;
                        }

                        foreach (Hurtbox hurtbox in damaged.Hurtboxes)
                        {
                            if (hitbox.Overlaps(hurtbox))
                            {
                                if (hitbox.Proximity)
                                {
                                    isProximity = true;
                                }
                                else
                                {
                                    isHit       = true;
                                    hitAttackID = hitbox.AttackID;
                                    float x1 = Mathf.Min(hitbox.XMax, hurtbox.XMax);
                                    float x2 = Mathf.Max(hitbox.XMin, hurtbox.XMin);
                                    float y1 = Mathf.Min(hitbox.YMax, hurtbox.YMax);
                                    float y2 = Mathf.Max(hitbox.YMin, hurtbox.YMin);
                                    damagePos.x = (x1 + x2) / 2;
                                    damagePos.y = (y1 + y2) / 2;
                                    break;
                                }
                            }
                        }

                        if (isHit)
                        {
                            break;
                        }
                    }

                    if (isHit)
                    {
                        attacker.NotifyAttackHit(damaged, damagePos);
                        DamageResult damageResult =
                            damaged.NotifyDamaged(attacker.GetAttackData(hitAttackID), damagePos);

                        int hitStunFrame = attacker.GetHitStunFrame(damageResult, hitAttackID);
                        attacker.SetHitStun(hitStunFrame);
                        damaged.SetHitStun(hitStunFrame);
                        damaged.SetSpriteShakeFrame(hitStunFrame / 3);

                        DamageOccurred?.Invoke(damaged, damagePos, damageResult);
                    }
                    else if (isProximity)
                    {
                        damaged.NotifyInProximityGuardRange();
                    }
                }
            }
        }