Exemplo n.º 1
0
    public void ConstructFlat()
    {
        GameObject plat1 = GameObject.CreatePrimitive(PrimitiveType.Cube);

        plat1.tag   = "Stage";
        plat1.layer = 10;
        plat1.transform.position   = new Vector3(0, -5, 0);
        plat1.transform.localScale = new Vector3(30, 2, 1);
        plat1.GetComponent <Renderer>().material = platMat;

        //TODO: add formula based on player size for ledgegrabposition

        LedgeNode ledge1 = Instantiate(GameData.ledgePrefab).GetComponent <LedgeNode>();

        ledge1.ledgePosition     = new Vector3(15.25F, -5F);
        ledge1.ledgeGrabPosition = ledge1.ledgePosition + (Vector3.right * 0.5F);
        ledge1.ledgeGrabLeft     = false;

        LedgeNode ledge2 = Instantiate(GameData.ledgePrefab).GetComponent <LedgeNode>();

        ledge2.ledgePosition     = new Vector3(-15.25F, -5F);
        ledge2.ledgeGrabPosition = ledge2.ledgePosition + (Vector3.left * 0.5F);
        ledge2.ledgeGrabLeft     = true;



        StageData.activePlatforms.Add(new Platform(0, plat1));

        GameData.stageHeight = flatStageHeight;
        GameData.stageBottom = flatStageBottom;
        GameData.stageWidth  = flatStageWidth;
    }
Exemplo n.º 2
0
 //called when the player grabs a ledge
 public void GrabLedge(LedgeNode ledge)
 {
     currLedge    = ledge;
     isFacingLeft = ledge.ledgeGrabLeft;
     moveState    = PlayerController.MoveStates.LEDGEGRAB;
     lagCount     = 12;
     isInvincible = true;
     airMomentum  = Vector3.zero;
     jumpUsed     = 0;
     upBUsed      = 0;
     sideBUsed    = 0;
     fastFalling  = false;
 }
Exemplo n.º 3
0
    //Update is called once per frame
    void Update()
    {
        if (playerNum == 1)
        {
            //For debugging
        }

        if (CheckBlastZones())
        {
            Death();
        }

        hurtBox.enabled = !isInvincible;

        //checks at the beginning and end of Update()
        pgh.UpdatePlatform();

        //= groundLevel = platHeight    +    ( height      / 2) - 4
        groundLevel = pgh.platHeight + ((basePlayerScale.y / 2) - 4F);

        if (frameCancel == true)
        {
            frameCancel = false;
        }

        GetInputs();
        CheckFastFall();

        if (moveState != MoveStates.LEDGEHOLD && moveState != MoveStates.LEDGEGRAB)
        {
            framesSinceLedgeGrab++;
            currLedge = null;
        }
        else
        {
            framesSinceLedgeGrab = 0;
        }
        if (moveState == MoveStates.LEFTRUN || moveState == MoveStates.RIGHTRUN || moveState == MoveStates.SKID)
        {
            runFrames++;
        }
        else
        {
            runFrames = 0;
        }


        //flips character model when facing left
        if (isFacingLeft)
        {
            transform.localScale = new Vector3(-basePlayerScale.x, basePlayerScale.y, 1);
        }
        else
        {
            transform.localScale = new Vector3(basePlayerScale.x, basePlayerScale.y, 1);
        }

        //Checks Grounded state
        if (transform.position.y > groundLevel)
        {
            //currently no support for moving platforms
            //transform.parent = null;
            groundMomentum.x = 0;
            if (moveState == MoveStates.STILL || moveState == MoveStates.LEFTWALK || moveState == MoveStates.RIGHTWALK)
            {
                moveState = MoveStates.AIRBORNE;
            }
            isGrounded = false;
        }
        else
        {
            if (isGrounded == false && airMomentum.y <= 0 && knockbackMomentum.y <= 0)
            {
                Land();
            }
            canGrabLedge = false;
            //transform.parent = pgh.nextPlat.plat.transform;
        }

        if (isGrounded && moveState != MoveStates.SPECIALMOVE)
        {
            jumpUsed  = 0;
            upBUsed   = 0;
            sideBUsed = 0;
        }

        //MOVESTATE = HITLAG
        if (moveState == MoveStates.HITLAG)
        {
            if (isGrounded)
            {
                transform.position += new Vector3(Random.Range(-0.02F, 0.02F), transform.position.y);
            }
            else
            {
                transform.position += new Vector3(Random.Range(-0.02F, 0.02F), Random.Range(-0.02F, 0.02F));
            }
            if (PreventClipping())
            {
                Land();
            }
        }

        //MOVESTATE = HITSTUN
        else if (moveState == MoveStates.HITSTUN)
        {
            if (!inHitstun)
            {
                try
                {
                    StopCoroutine(HitManager.playersInHitstun[this]);
                    HitManager.playersInHitstun[this] = null;
                } catch { }

                HitManager.playersInHitstun[this] = Hitstun();
                inHitstun = true;
                StartCoroutine(HitManager.playersInHitstun[this]);
            }
            HitStunControl();
        }

        //MOVESTATE = JUMPSQUAT, LANDINGLAG, SHIELDDROP, SHIELDSTUN, LEDGEGRAB, SKID, OR TURN
        else if (moveState == MoveStates.JUMPSQUAT || moveState == MoveStates.TURN || moveState == MoveStates.LANDINGLAG ||
                 moveState == MoveStates.SHIELDDROP || moveState == MoveStates.LEDGEGRAB || moveState == MoveStates.SKID)
        {
            ApplyTraction();
            if (lagCount > 1)
            {
                lagCount--;
                bufferedOption = BufferMove();

                if (moveState == MoveStates.SKID)
                {
                    if (yPress || xPress)
                    {
                        StartJumpsquat();
                    }
                    else

                    if (lagCount >= 11)
                    {
                        RunControl();
                    }
                }
            }
            else
            {
                if (moveState == MoveStates.JUMPSQUAT)
                {
                    Jump();
                }
                else
                if (moveState == MoveStates.LEDGEGRAB)
                {
                    moveState = MoveStates.LEDGEHOLD;
                }
                else
                {
                    moveState = MoveStates.STILL;
                }

                if (bufferedOption != null)
                {
                    pam.UseBufferedOption(this, bufferedOption);
                }
            }
        }

        //MOVESTATE = SHIELD
        else if (moveState == MoveStates.SHIELD)
        {
            ShieldControl();
        }

        //MOVESTATE = LEDGEHOLD
        else if (moveState == MoveStates.LEDGEHOLD)
        {
            LedgeControl();
        }

        //MOVESTATE = ATTACK
        else if (moveState == MoveStates.ATTACK)
        {
            pam.RunAttackFrame(this, currAttack, currAttackFrame);
            currAttackFrame++;
            if (groundMomentum.x < 0)
            {
                groundMomentum.x += traction;
                if (groundMomentum.x > 0)
                {
                    groundMomentum.x = 0;
                }
            }

            if (groundMomentum.x > 0)
            {
                groundMomentum.x -= traction;
                if (groundMomentum.x < 0)
                {
                    groundMomentum.x = 0;
                }
            }
        }

        //MOVESTATE = AERIAL
        else if (moveState == MoveStates.AERIAL)
        {
            AerialAttackControl();
        }

        //MOVESTATE == SPECIALMOVE
        else if (moveState == MoveStates.SPECIALMOVE)
        {
            SpecialMoveControl();
        }

        //MOVESTATE = AIRBORNE, STILL, LEFTWALK, RIGHTWALK, LEFTRUN, RIGHTRUN
        else
        {
            //if the player is grounded, utilize grounded controls
            if (isGrounded)
            {
                if (moveState == MoveStates.LEFTRUN || moveState == MoveStates.RIGHTRUN)
                {
                    RunControl();

                    if (moveState == MoveStates.RIGHTRUN)
                    {
                        if (groundMomentum.x > -runSpeed)
                        {
                            groundMomentum.x -= runAccel;
                        }

                        if (groundMomentum.x < -runSpeed)
                        {
                            groundMomentum.x += runAccel;
                        }
                    }
                    else if (moveState == MoveStates.LEFTRUN)
                    {
                        if (groundMomentum.x < runSpeed)
                        {
                            groundMomentum.x += runAccel;
                        }

                        if (groundMomentum.x > runSpeed)
                        {
                            groundMomentum.x -= runAccel;
                        }
                    }
                }
                else
                {
                    moveState = MoveStates.STILL;
                    GroundControl();
                    walkSpeed = baseWalkSpeed * (Mathf.Abs(hori) / 1);
                    //Change ground momentum per frame
                    if (moveState == MoveStates.RIGHTWALK)
                    {
                        if (groundMomentum.x > -walkSpeed)
                        {
                            groundMomentum.x -= walkAccel;
                        }

                        if (groundMomentum.x < -walkSpeed)
                        {
                            groundMomentum.x += walkAccel;
                        }
                    }
                    else if (moveState == MoveStates.LEFTWALK)
                    {
                        if (groundMomentum.x < walkSpeed)
                        {
                            groundMomentum.x += walkAccel;
                        }

                        if (groundMomentum.x > walkSpeed)
                        {
                            groundMomentum.x -= walkAccel;
                        }
                    }
                    else if (moveState == MoveStates.STILL)
                    {
                        ApplyTraction();
                    }
                }
            }
            else
            {
                AirControl();
            }
        }

        //MOVESTATE = STILL, LEFTWALK, RIGHTWALK, TURN, JUMPSQUAT, ATTACK, AERIAL, SPECIALMOVE, SHIELD, SHIELDDROP, LANDINGLAG, AIRBORNE, SPECIALFALL
        //This causes the player to move according to their ground/air momentum
        if (moveState != MoveStates.HITLAG && moveState != MoveStates.HITSTUN && moveState != MoveStates.LEDGEGRAB &&
            moveState != MoveStates.LEDGEHOLD)
        {
            if (isGrounded)
            {
                transform.Translate(groundMomentum);
            }
            else
            {
                if (moveState == MoveStates.SPECIALMOVE)
                {
                    //only translates x or y depending on move properties
                    if (currAttack.frameData[currAttackFrame].canControl)
                    {
                        transform.Translate(new Vector3(airMomentum.x, 0));
                    }

                    if (currAttack.frameData[currAttackFrame].canFall)
                    {
                        transform.Translate(new Vector3(0, airMomentum.y));
                    }

                    if (PreventClipping())
                    {
                        Land();
                    }
                }
                else
                {
                    transform.Translate(airMomentum);
                    if (PreventClipping())
                    {
                        Land();
                    }
                }
            }
        }

        //updates platform again to allow for sliding off edges
        pgh.UpdatePlatform();
        groundLevel = pgh.platHeight;

        //Allows for sliding off edges to keep momentum/cancel lag
        if (transform.position.y > groundLevel)
        {
            //works in MoveStates ATTACK, LANDINGLAG, LEFTWALK, RIGHTWALK, STILL
            if (isGrounded && (moveState == MoveStates.ATTACK || moveState == MoveStates.LANDINGLAG || moveState == MoveStates.LEFTWALK ||
                               moveState == MoveStates.RIGHTWALK || moveState == MoveStates.STILL))
            {
                airMomentum = groundMomentum;

                moveState  = MoveStates.AIRBORNE;
                isGrounded = false;

                if (currAttack != null)
                {
                    InterruptAttack();
                }
            }
        }
        CheckAnimation();
    }