Exemplo n.º 1
0
 private void OnDrawGizmos()
 {
     GetComponent <SpriteRenderer>().sprite = fighterObject.GetFrame().sprite;
     if (drawHitbox)
     {
         fighterObject.GetMove().Draw(transform.localToWorldMatrix);
     }
 }
Exemplo n.º 2
0
        // Update is called once per frame
        void Update()
        {
            if (!fighter.running || !running)
            {
                fighter.UpdateObject(Time.deltaTime);
                if (fighter.GetMove().Compute(Time.deltaTime))
                {
                    fighter.SetMove(fighter.GetMove().defaultNext);
                }
                return;
            }
            ///Block
            if (controller.GetBlockDown())
            {
                blocking = true;
            }
            else if (controller.GetBlockUp())
            {
                blocking = false;
            }
            if (!blocking)
            {
                blocked = false;
            }

            float h      = controller.GetHorizontal();
            float v      = -controller.GetVertical();
            float deltaT = Time.deltaTime * FightManager.timeModifier;
            float dT     = deltaT;

            fighter.UpdateObject(deltaT);
            if (fighter.currentState == fighter.Walk && h < 0.0f)
            {
                dT *= -1;
            }
            if (fighter.GetMove().Compute(dT))
            {
                fighter.SetMove(fighter.GetMove().defaultNext);
            }
            //clamp to 1
            if (h < -0.5)
            {
                h = -1;
            }
            else if (h > 0.5)
            {
                h = 1;
            }
            if (v < -0.5)
            {
                v = -1;
            }
            else if (v > 0.5)
            {
                v = 1;
            }
            else
            {
                v = 0;
            }
            //Crouch
            if (v <= 0 && fighter.jumped)
            {
                fighter.jumped = false;
            }
            if (v < 0 && fighter.Grounded && fighter.Standing())
            {
                //fighter.SetMove(fighter.Crouch);
            }
            else if (controller.GetJumpDown() && fighter.Grounded && (fighter.currentState == fighter.Stand || fighter.currentState == fighter.Walk) && !fighter.jumped) //Jump
            {
                fighter.Grounded = false;
                //fighter.velocity.y = fighter.jumpStrength;
                fighter.jumped = true;
                fighter.SetMove(fighter.JumpStart);
                lastJumpState = true;
                jumpTimer     = 0;
            }
            else
            {
                //SetMove(Stand);
            }
            if (!fighter.Grounded && jumpTimer > 1.25f && lastJumpState && !fighter.GetMove().attack)
            {
                fighter.SetMove(fighter.JumpFall);
                lastJumpState = false;
            }
            if (fighter.Grounded)
            {
                fighter.velocity = Vector3.zero;
            }
            //Movement
            if ((fighter.currentState == fighter.Stand || fighter.currentState == fighter.Walk) && fighter.Grounded)
            {
                float modif = 1.0f;
                if ((h < 0.0f && sens.x > 0.0f) || (h > 0.0f && sens.x < 0.0f))
                {
                    modif = 0.7f;
                }
                fighter.velocity += h * fighter.speed * modif * Vector3.right * Mathf.Abs(transform.lossyScale.x);
                if (fighter.currentState != fighter.Walk && h != 0)
                {
                    fighter.SetMove(fighter.Walk);
                }
                if (fighter.currentState == fighter.Walk && h == 0)
                {
                    fighter.SetMove(fighter.Stand);
                }
            }
            //Direction
            if (opponent)
            {
                if (opponent.transform.position.x < transform.position.x)
                {
                    sens = new Vector3(-1, 1, 1);
                }
                else
                {
                    sens = new Vector3(1, 1, 1);
                }
                transform.localScale = sens;
                controller.SetSens(sens.x);
            }
            //Attack
            int curState = fighter.currentState;

            if (curState == fighter.Walk)
            {
                curState = fighter.Stand;
            }
            Node node = fighter.moveSet.nodes.Find((Node n) => n.moveId == curState);

            if (node != null)
            {
                foreach (Action a in node.actions)
                {
                    if (controller.GetKeyDown(a.input) && fighter.GetFrame().frameType == FighterState.Type.RecoveryFrame)
                    {
                        fighter.SetMove(a.state);
                    }
                }
            }

            //Parry
            if (controller.GetBlockDown())
            {
                fighter.Parry();
            }

            //Confirm
            if (curState == fighter.Taunt && opponent.ComboStrength > 0)
            {
                HitBox hb = fighter.GetAttackHitbox();
                if (hb != null)
                {
                    if (opponent.ComboStrength < 0.3)
                    {
                        particleLaunch(confirmSuccess, new Vector3((hb._position.x + hb._size.x / 2f), (hb._position.y + hb._size.y / 2f), 0));
                    }
                    else
                    {
                        particleLaunch(confirmBigSuccess, new Vector3((hb._position.x + hb._size.x / 2f), (hb._position.y + hb._size.y / 2f), 0));
                    }
                    opponent.Confirm();
                }
            }

            //Apply gravity
            float g = FightManager.gravity;

            addedVelocity -= addedVelocity * (Time.deltaTime / 0.1f);
            //fighter.velocity += (fighter.velocity.y*fighter.velocity.y+1)/(fighter.jumpStrength*fighter.jumpStrength) * Vector3.down * g;
            fighter.velocity   += ((Vector3)fighter.GetMove().GetVelocity() * sens.x) * Mathf.Abs(transform.lossyScale.x);
            fighter.velocity   += addedVelocity;
            transform.position += fighter.velocity * deltaT;
            if (jumpTimer < 2f)
            {
                float curvePosition = jumpTimer - 1f;
                Debug.Log(jumpTimer);
                float added = fighter.jumpStrength * (-(curvePosition * curvePosition) + 1);
                Debug.Log("added:" + added);
                transform.position = new Vector3(transform.position.x, FightManager.groundHeight + added, transform.position.z);
                jumpTimer         += (Time.deltaTime * 2) / fighter.jumpSpeed;
            }
            else
            {
                transform.position += Vector3.down * FightManager.gravity;
            }

            //Players pushing each other
            if (transform.position.x < maxPosition.x)
            {
                transform.position = new Vector3(maxPosition.x, transform.position.y, transform.position.z);
            }
            if (transform.position.x > maxPosition.y)
            {
                transform.position = new Vector3(maxPosition.y, transform.position.y, transform.position.z);
            }

            //Floor
            if (transform.position.y < FightManager.groundHeight)
            {
                transform.position = new Vector3(transform.position.x, FightManager.groundHeight, transform.position.z);
                if (!fighter.Grounded)
                {
                    fighter.SetMove(fighter.JumpRecovery);
                }
                fighter.Grounded = true;
            }
        }