//Here we check if the player is jumping or moving away from the wall or ground.
    void OnCollisionExit2D(Collision2D coll)
    {
        animatorController.SetBool("Pushing", false);
        OnCollisionStayCounter = 0;
        foreach (ContactPoint2D contact in coll.contacts)
        {
            int CountHappenings     = 0;
            int CountHappeningsWALL = 0;
            foreach (GameObject GroundedObject in GroundedToObjectsList)
            {
                if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                {
                    CountHappenings += 1;
                }
            }
            foreach (GameObject WalledObject in WalledToObjectsList)
            {
                if (contact.collider.gameObject.GetInstanceID() == WalledObject.GetInstanceID())
                {
                    CountHappeningsWALL += 1;
                }
            }

            //was the object one of the grounded to objects?
            if (CountHappenings > 0)
            {
                GroundedToObjectsList.Remove(contact.collider.gameObject);
                if (GroundedToObjectsList.Count == 0)
                {
                    DJ_available          = true;
                    isGrounded            = false;
                    this.transform.parent = null;
                    FixStateTimer         = 0;
                }
            }

            //was the object one of the wall?
            if (CountHappeningsWALL > 0)
            {
                WalledToObjectsList.Remove(contact.collider.gameObject);
                if (WalledToObjectsList.Count == 0)
                {
                    if (NoNeedForSafeJump_bool == false)
                    {
                        //This makes the walljump a bit easier. Player is able to do the wall jump even few miliseconds after he let go of the wall.
                        walljump_count = 0.16f;
                    }
                    NoNeedForSafeJump_bool         = false;
                    DJ_available                   = true;
                    this.transform.parent          = null;
                    isWallSliding                  = false;
                    WallGripParticles.emissionRate = 0;
                    FixStateTimer                  = 0;
                }
            }
        }
    }
예제 #2
0
    void OnCollisionStay2D(Collision2D coll)
    {
        OnCollisionStayCounter += 1;
        UpInTheAir_Counter      = 0;

        //This is making sure that when Ninja is colliding with something it is always registered.
        if (IsGrounded == false && WallTouch == false)
        {
            FixStateTimer += 1;
            if (FixStateTimer > 4)
            {
                foreach (ContactPoint2D contact in coll.contacts)
                {
                    if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
                    {
                        JumpForceCount = 0f;
                    }
                    else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
                    {
                        FixStateTimer = 0;
                        DJ_available  = false;
                        GroundedToObjectsList.Add(contact.collider.gameObject);
                        IsGrounded = true;
                    }
                    else
                    {
                        if (this.GetComponent <Rigidbody2D>().velocity.y < 0f)
                        {
                            FixStateTimer = 0;
                            DJ_available  = false;
                            WalledToObjectsList.Add(contact.collider.gameObject);
                            WallTouch = true;

                            this.transform.parent = null;
                            NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                            NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                            this.transform.parent = NinjaPlatformRoot.transform;

                            if (contact.normal.x > 0)
                            {
                                PlayerLooksRight = true;
                                MySpriteOBJ.transform.localScale = MySpriteOriginalScale;
                            }
                            else
                            {
                                PlayerLooksRight = false;
                                MySpriteOBJ.transform.localScale = new Vector3(-MySpriteOriginalScale.x, MySpriteOriginalScale.y, MySpriteOriginalScale.z);
                            }

                            //Start emiting smoke particles when touching the wall
                            WallGripParticles.emissionRate = WallGripEmissionRate;
                        }
                    }
                }
            }
        }


        //OnStay Ground Events:
        else if (IsGrounded == true)
        {
            Vector2 NinjaStandDirection = Vector2.zero;
            foreach (ContactPoint2D contact in coll.contacts)
            {
                int CountHappenings = 0;
                foreach (GameObject GroundedObject in GroundedToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                    {
                        NinjaStandDirection += contact.normal;
                        CountHappenings     += 1;
                    }
                }
                if (CountHappenings > 0)
                {
                    NinjaStandDirection = NinjaStandDirection / CountHappenings;
                    //This makes sure that Ninja doesn't walk on the walls.
                    if ((NinjaStandDirection.x > Ground_X_MAX || NinjaStandDirection.x < Ground_X_MIN) && (NinjaStandDirection.y > Ground_Y_MAX || NinjaStandDirection.y < Ground_Y_MIN))
                    {
                        this.GetComponent <Rigidbody2D>().AddForce(NinjaStandDirection * 100f);
                    }
                    else
                    {
                        //this Rotates the Ninja to allign with platform.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);
                        float   TorqueTo        = Vector2.Angle(NinjaStandDirection, RealDirectionV2);
                        if (NinjaStandDirection.normalized.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-NinjaStandDirection.normalized.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.GetComponent <Rigidbody2D>().AddTorque(TorqueTo * 1000f * Time.deltaTime);

                        this.GetComponent <Rigidbody2D>().AddForce(NinjaStandDirection * (-300f));
                    }
                }
            }


            //OnStay Wall Events:
        }
        else if (WallTouch == true)
        {
            foreach (ContactPoint2D contact in coll.contacts)
            {
                Vector2 NinjaWallDirection = Vector2.zero;
                int     CountHappenings    = 0;
                foreach (GameObject WallObject in WalledToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == WallObject.GetInstanceID())
                    {
                        NinjaWallDirection += contact.normal;
                        CountHappenings    += 1;
                    }
                }

                if (CountHappenings > 0)
                {
                    NinjaWallDirection = NinjaWallDirection / CountHappenings;
                    if ((NinjaWallDirection.x > Ground_X_MAX || NinjaWallDirection.x < Ground_X_MIN) && (NinjaWallDirection.y > Ground_Y_MAX || NinjaWallDirection.y < Ground_Y_MIN))
                    {
                        if ((Btn_Left_bool == false && PlayerLooksRight == false) || (Btn_Right_bool == false && PlayerLooksRight == true))
                        {
                            this.GetComponent <Rigidbody2D>().AddForce(NinjaWallDirection * -100f);
                        }
                        //this Rotates the Ninja to allign with the wall.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);

                        if (PlayerLooksRight == false)
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, 1.35f);
                        }
                        else
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, -1.35f);
                        }

                        float TorqueTo = Vector2.Angle(NinjaWallDirection, RealDirectionV2);
                        if (contact.normal.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-contact.normal.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.GetComponent <Rigidbody2D>().AddTorque(TorqueTo * 450f * Time.deltaTime);
                    }
                    else
                    {
                        if ((Btn_Left_bool == false && PlayerLooksRight == false) || (Btn_Right_bool == false && PlayerLooksRight == true))
                        {
                            this.GetComponent <Rigidbody2D>().AddForce(NinjaWallDirection * 100f);
                        }
                    }
                }
            }
        }
    }
예제 #3
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.CompareTag("Enemy"))
        {
            return;
        }

        //This makes sure Ninja doesn't slide from previous force when hitting platform. Unless player is holding Left or Right button.
        if (IsGrounded == false && Btn_Left_bool == false && Btn_Right_bool == false)
        {
            this.GetComponent <Rigidbody2D>().velocity = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x * 0.25f, -0.01f);
        }
        else if (IsGrounded == false)
        {
            this.GetComponent <Rigidbody2D>().velocity = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, -0.01f);
        }

        OnCollisionStayCounter += 1;
        OnCollisionBugThreshold = 0;
        UpInTheAir_Counter      = 0;

        foreach (ContactPoint2D contact in coll.contacts)
        {
            //If Ninja hits his head to the roof. Stop Jump Force.
            if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
            {
                JumpForceCount = 0f;
            }

            //If it wasn't the roof. Was it a ground perhaps?
            else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
            {
                int CountHappenings = 0;
                foreach (GameObject GroundedObject in GroundedToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                    {
                        CountHappenings += 1;
                    }
                }

                //Is the platform already listed in GroundedObjects? If not Add it to the list.
                if (CountHappenings == 0)
                {
                    DJ_available = false;
                    GroundedToObjectsList.Add(contact.collider.gameObject);
                    //Move NinjaPlatformRoot to the new platform.
                    this.transform.parent = null;
                    NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                    NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                    this.transform.parent = NinjaPlatformRoot.transform;

                    IsGrounded = true;

                    this.GetComponent <Rigidbody2D>().AddForce(contact.normal * (-300f));

                    if (WallTouch == true)
                    {
                        WallGripParticles.emissionRate = 0;
                        FixStateTimer = 0;
                    }
                }

                //If it wasnt a roof or a ground it must have been wall. No need for Normal check anymore.
            }
            else
            {
                //Ninja must be faling downwards to grab the wall.
                if (this.GetComponent <Rigidbody2D>().velocity.y < 0f && IsGrounded == false)
                {
                    this.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                    //is the Object already listed in WalledObjects?
                    int CountHappenings = 0;
                    foreach (GameObject WalledObject in WalledToObjectsList)
                    {
                        if (contact.collider.gameObject.GetInstanceID() == WalledObject.GetInstanceID())
                        {
                            CountHappenings += 1;
                        }
                    }
                    //if not. Lets list it.
                    if (CountHappenings == 0)
                    {
                        DJ_available = false;
                        WalledToObjectsList.Add(contact.collider.gameObject);
                        this.transform.parent = null;
                        NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                        NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                        this.transform.parent = NinjaPlatformRoot.transform;

                        WallTouch = true;

                        //Check that the player is facing to the right direction
                        if (contact.normal.x > 0)
                        {
                            PlayerLooksRight = true;
                            MySpriteOBJ.transform.localScale = MySpriteOriginalScale;
                        }
                        else
                        {
                            PlayerLooksRight = false;
                            MySpriteOBJ.transform.localScale = new Vector3(-MySpriteOriginalScale.x, MySpriteOriginalScale.y, MySpriteOriginalScale.z);
                        }

                        //Start emiting smoke particles when touching the wall
                        WallGripParticles.emissionRate = WallGripEmissionRate;
                    }
                }
            }
        }
    }
    void OnCollisionStay2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Box" && !isDashing)
        {
            //print("isBox");

            /*foreach (ContactPoint2D contact in coll.contacts) {
             *  print(contact.point);
             * }*/
            float contactPoint = coll.contacts[0].point.y - coll.gameObject.transform.position.y;
            if (contactPoint < 0.0f)
            {
                animatorController.SetBool("Pushing", true);
            }
        }

        OnCollisionStayCounter += 1;
        UpInTheAir_Counter      = 0;

        //This is making sure that when character is colliding with something it is always registered.
        if (isGrounded == false && isWallSliding == false)
        {
            FixStateTimer += 1;
            if (FixStateTimer > 4)
            {
                foreach (ContactPoint2D contact in coll.contacts)
                {
                    if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
                    {
                        JumpForceCount = 0f;
                    }
                    else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
                    {
                        FixStateTimer = 0;
                        DJ_available  = false;
                        GroundedToObjectsList.Add(contact.collider.gameObject);
                        isGrounded = true;
                    }
                    else
                    {
                        if (contact.collider.tag != "Box")
                        {
                            if (this.rigidbody2D.velocity.y < 0f)
                            {
                                FixStateTimer = 0;
                                DJ_available  = false;
                                WalledToObjectsList.Add(contact.collider.gameObject);
                                isWallSliding = true;

                                this.transform.parent           = null;
                                PlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                                PlatformRoot.RootedTo           = contact.collider.gameObject;
                                this.transform.parent           = PlatformRoot.transform;

                                if (contact.normal.x > 0)
                                {
                                    FaceRight();
                                }
                                else
                                {
                                    FaceLeft();
                                }

                                //Start emiting smoke particles when touching the wall
                                WallGripParticles.emissionRate = WallGripEmissionRate;
                            }
                        }
                    }
                }
            }
        }


        //OnStay Ground Events:
        else if (isGrounded == true)
        {
            Vector2 StandDirection = Vector2.zero;
            foreach (ContactPoint2D contact in coll.contacts)
            {
                int CountHappenings = 0;
                foreach (GameObject GroundedObject in GroundedToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                    {
                        StandDirection  += contact.normal;
                        CountHappenings += 1;
                    }
                }
                if (CountHappenings > 0)
                {
                    StandDirection = StandDirection / CountHappenings;
                    //This makes sure that character doesn't walk on the walls.
                    if ((StandDirection.x > Ground_X_MAX || StandDirection.x < Ground_X_MIN) && (StandDirection.y > Ground_Y_MAX || StandDirection.y < Ground_Y_MIN))
                    {
                        this.rigidbody2D.AddForce(StandDirection * 100f);
                    }
                    else
                    {
                        //this Rotates the character to allign with platform.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);
                        float   TorqueTo        = Vector2.Angle(StandDirection, RealDirectionV2);
                        if (StandDirection.normalized.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-StandDirection.normalized.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.rigidbody2D.AddTorque(TorqueTo * 1000f * Time.deltaTime);

                        this.rigidbody2D.AddForce(StandDirection * (-300f));
                    }
                }
            }


            //OnStay Wall Events:
        }
        else if (isWallSliding == true)
        {
            foreach (ContactPoint2D contact in coll.contacts)
            {
                Vector2 WallDirection   = Vector2.zero;
                int     CountHappenings = 0;
                foreach (GameObject WallObject in WalledToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == WallObject.GetInstanceID())
                    {
                        WallDirection   += contact.normal;
                        CountHappenings += 1;
                    }
                }

                if (CountHappenings > 0)
                {
                    WallDirection = WallDirection / CountHappenings;
                    if ((WallDirection.x > Ground_X_MAX || WallDirection.x < Ground_X_MIN) && (WallDirection.y > Ground_Y_MAX || WallDirection.y < Ground_Y_MIN))
                    {
                        if ((leftInputActive == false && isFacingRight == false) || (rightInputActive == false && isFacingRight == true))
                        {
                            this.rigidbody2D.AddForce(WallDirection * -100f);
                        }
                        //this Rotates the character to allign with the wall.
                        Vector2 RealDirectionV2 = new Vector2(this.transform.up.x, this.transform.up.y);

                        if (isFacingRight == false)
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, 1.35f);
                        }
                        else
                        {
                            RealDirectionV2 = RotateThisVector(RealDirectionV2, -1.35f);
                        }

                        float TorqueTo = Vector2.Angle(WallDirection, RealDirectionV2);
                        if (contact.normal.x > RealDirectionV2.normalized.x)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        if (-contact.normal.y > RealDirectionV2.normalized.y)
                        {
                            TorqueTo = TorqueTo * (-1);
                        }
                        this.rigidbody2D.AddTorque(TorqueTo * 450f * Time.deltaTime);
                    }
                    else
                    {
                        if ((leftInputActive == false && isFacingRight == false) || (rightInputActive == false && isFacingRight == true))
                        {
                            this.rigidbody2D.AddForce(WallDirection * 100f);
                        }
                    }
                }
            }
        }
    }
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.CompareTag("Enemy"))
        {
            return;
        }

        //This makes sure character doesn't slide from previous force when hitting platform. Unless player is holding Left or Right button.
        if (isGrounded == false && leftInputActive == false && rightInputActive == false)
        {
            this.rigidbody2D.velocity = new Vector2(this.rigidbody2D.velocity.x * 0.25f, -0.01f);
            //this.rigidbody2D.velocity = new Vector2 (this.rigidbody2D.velocity.x * 0.0f, -0.01f);
        }
        else if (isGrounded == false)
        {
            this.rigidbody2D.velocity = new Vector2(this.rigidbody2D.velocity.x, -0.01f);
        }

        OnCollisionStayCounter += 1;
        OnCollisionBugThreshold = 0;
        UpInTheAir_Counter      = 0;

        foreach (ContactPoint2D contact in coll.contacts)
        {
            //If character hits his head to the roof. Stop Jump Force.
            if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
            {
                JumpForceCount = 0f;
            }

            //If it wasn't the roof. Was it a ground perhaps?
            else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
            {
                int CountHappenings = 0;
                foreach (GameObject GroundedObject in GroundedToObjectsList)
                {
                    if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                    {
                        CountHappenings += 1;
                    }
                }

                //Is the platform already listed in GroundedObjects? If not Add it to the list.
                if (CountHappenings == 0)
                {
                    DJ_available = false;
                    GroundedToObjectsList.Add(contact.collider.gameObject);
                    //Move PlatformRoot to the new platform.
                    this.transform.parent           = null;
                    PlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                    PlatformRoot.RootedTo           = contact.collider.gameObject;
                    this.transform.parent           = PlatformRoot.transform;

                    isGrounded = true;

                    this.rigidbody2D.AddForce(contact.normal * (-300f));

                    if (isWallSliding == true)
                    {
                        WallGripParticles.emissionRate = 0;
                        FixStateTimer = 0;
                    }
                }

                //If it wasnt a roof or a ground it must have been wall. No need for Normal check anymore.
            }
            else
            {
                //Character must be faling downwards to grab the wall.
                if (this.rigidbody2D.velocity.y < 0f && isGrounded == false)
                {
                    this.rigidbody2D.velocity = Vector2.zero;
                    //is the Object already listed in WalledObjects?
                    int CountHappenings = 0;
                    foreach (GameObject WalledObject in WalledToObjectsList)
                    {
                        if (contact.collider.gameObject.GetInstanceID() == WalledObject.GetInstanceID())
                        {
                            CountHappenings += 1;
                        }
                    }
                    //if not. Lets list it.
                    if (CountHappenings == 0)
                    {
                        //print (contact.collider.tag) ;
                        if (contact.collider.tag != "Box")
                        {
                            DJ_available = false;
                            WalledToObjectsList.Add(contact.collider.gameObject);
                            this.transform.parent           = null;
                            PlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                            PlatformRoot.RootedTo           = contact.collider.gameObject;
                            this.transform.parent           = PlatformRoot.transform;

                            isWallSliding = true;

                            //Check that the player is facing to the right direction
                            if (contact.normal.x > 0)
                            {
                                FaceRight();
                            }
                            else
                            {
                                FaceLeft();
                            }

                            //Start emiting smoke particles when touching the wall
                            WallGripParticles.emissionRate = WallGripEmissionRate;
                        }
                    }
                }
            }
        }
    }
예제 #6
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "Enemy")
        {
            GetComponent <AudioSource>().Play();
            GameObject go = Instantiate(dieParticle, transform.position, new Quaternion(0, 0, 0, 0)) as GameObject;
            go.transform.Rotate(new Vector3(270, 0, 0));
            Destroy(gameObject, 1f);
            GameObject.Find("NinjaSprites").GetComponent <SpriteRenderer>().enabled = false;
            GlobalValues.isPlayerRunning = false;
            playerIsDie = true;
            loseGamePanel.SetActive(true);
            int high = PlayerPrefs.GetInt("HIGH_SCORE", 0);
            if (jScore > high)
            {
                PlayerPrefs.SetInt("HIGH_SCORE", jScore);
            }
            highJ.GetComponent <Text>().text    = "   " + PlayerPrefs.GetInt("HIGH_SCORE", 0).ToString();
            currentJ.GetComponent <Text>().text = "   " + jScore.ToString();
        }
        else
        {
            //This makes sure Ninja doesn't slide from previous force when hitting platform. Unless player is holding Left or Right button.
            if (IsGrounded == false && Btn_Left_bool == false && Btn_Right_bool == false)
            {
                this.GetComponent <Rigidbody2D>().velocity = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x * 0.25f, -0.01f);
            }
            else if (IsGrounded == false)
            {
                this.GetComponent <Rigidbody2D>().velocity = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, -0.01f);
            }

            OnCollisionStayCounter += 1;
            OnCollisionBugThreshold = 0;
            UpInTheAir_Counter      = 0;

            foreach (ContactPoint2D contact in coll.contacts)
            {
                //If Ninja hits his head to the roof. Stop Jump Force.
                if (0.1f > contact.normal.y && ((contact.normal.x * contact.normal.x) < (0.85f * 0.85f)))
                {
                    JumpForceCount = 0f;
                }

                //If it wasn't the roof. Was it a ground perhaps?
                else if (contact.normal.x >= Ground_X_MIN && contact.normal.x <= Ground_X_MAX && contact.normal.y >= Ground_Y_MIN && contact.normal.y <= Ground_Y_MAX)
                {
                    int CountHappenings = 0;
                    foreach (GameObject GroundedObject in GroundedToObjectsList)
                    {
                        if (contact.collider.gameObject.GetInstanceID() == GroundedObject.GetInstanceID())
                        {
                            CountHappenings += 1;
                        }
                    }

                    //Is the platform already listed in GroundedObjects? If not Add it to the list.
                    if (CountHappenings == 0)
                    {
                        DJ_available = false;
                        GroundedToObjectsList.Add(contact.collider.gameObject);
                        //Move NinjaPlatformRoot to the new platform.
                        this.transform.parent = null;
                        NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                        NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                        this.transform.parent = NinjaPlatformRoot.transform;

                        IsGrounded = true;

                        this.GetComponent <Rigidbody2D>().AddForce(contact.normal * (-300f));

                        if (WallTouch == true)
                        {
                            WallGripParticles.emissionRate = 0;
                            FixStateTimer = 0;
                        }
                    }
                    //If it wasnt a roof or a ground it must have been wall. No need for Normal check anymore.
                }
                else
                {
                    //Ninja must be faling downwards to grab the wall.
                    if (this.GetComponent <Rigidbody2D>().velocity.y < 0f && IsGrounded == false)
                    {
                        this.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                        //is the Object already listed in WalledObjects?
                        int CountHappenings = 0;
                        foreach (GameObject WalledObject in WalledToObjectsList)
                        {
                            if (contact.collider.gameObject.GetInstanceID() == WalledObject.GetInstanceID())
                            {
                                CountHappenings += 1;
                            }
                        }
                        //if not. Lets list it.
                        if (CountHappenings == 0)
                        {
                            DJ_available = false;
                            WalledToObjectsList.Add(contact.collider.gameObject);
                            this.transform.parent = null;
                            NinjaPlatformRoot.transform.position = contact.collider.gameObject.transform.position;
                            NinjaPlatformRoot.RootedTo           = contact.collider.gameObject;
                            this.transform.parent = NinjaPlatformRoot.transform;

                            WallTouch = true;

                            //Check that the player is facing to the right direction
                            if (contact.normal.x > 0)
                            {
                                PlayerLooksRight = true;
                                MySpriteOBJ.transform.localScale = MySpriteOriginalScale;
                            }
                            else
                            {
                                PlayerLooksRight = false;
                                MySpriteOBJ.transform.localScale = new Vector3(-MySpriteOriginalScale.x, MySpriteOriginalScale.y, MySpriteOriginalScale.z);
                            }

                            //Start emiting smoke particles when touching the wall
                            WallGripParticles.emissionRate = WallGripEmissionRate;
                        }
                    }
                }
            }
        }
    }
예제 #7
0
        private static void Socket_OnReceivingEvent(System.Net.Sockets.Socket S, byte[] Packet)
        {
            int packetNumber = BitConverter.ToUInt16(Packet, 2);

            switch (packetNumber)
            {
            case 1000:
                Connect   connectPacket = new Connect(Packet);
                Character c             = new Character(connectPacket.Character, S);
                c.CharacterID             = (byte)charactersPool.Count;
                connectPacket.CharacterID = c.CharacterID;
                c.CharacterType           = connectPacket.Character;
                socket.Send(S, connectPacket.Packet());
                charactersPool.Add(c);
                if (charactersPool.Count == 2)
                {
                    GroundedObject GO = new GroundedObject();
                    GO.CharacterType = 0;
                    for (int i = 0; i < Constants.enemiesCount; i++)
                    {
                        GO.Buffer[i + 6] = (byte)(ran.Next(0, 3));
                    }
                    for (int i = 0; i < Constants.enemiesCount; i++)
                    {
                        int idx = i * 4 + 50;
                        int v   = ran.Next(-1100, -800);
                        Console.WriteLine("r: " + v);
                        byte[] Val = BitConverter.GetBytes(v);
                        Buffer.BlockCopy(Val, 0, GO.Buffer, idx, Val.Length);
                    }
                    socket.Send(charactersPool[0].socket, GO.Packet());
                    //Thread.Sleep(500);
                    socket.Send(charactersPool[1].socket, GO.Packet());
                    //Thread.Sleep(500);


                    GO.CharacterType = 1;
                    for (int i = 0; i < Constants.ringsCount; i++)
                    {
                        GO.Buffer[i + 6] = (byte)(ran.Next(0, 3));
                    }
                    for (int i = 0; i < Constants.ringsCount; i++)
                    {
                        int    idx = i * 4 + 50;
                        byte[] Val = BitConverter.GetBytes(ran.Next(-1100, -800));
                        Buffer.BlockCopy(Val, 0, GO.Buffer, idx, Val.Length);
                    }
                    socket.Send(charactersPool[0].socket, GO.Packet());
                    //Thread.Sleep(500);
                    socket.Send(charactersPool[1].socket, GO.Packet());
                    //Thread.Sleep(500);

                    socket.Send(charactersPool[0].socket, new GO()
                    {
                        SecondCharacter = (byte)charactersPool[1].CharacterType
                    }.Buffer);

                    socket.Send(charactersPool[1].socket, new GO()
                    {
                        SecondCharacter = (byte)charactersPool[0].CharacterType
                    }.Buffer);
                }
                break;

            case 1006:
                Movement m = new Movement(Packet);
                socket.Send(charactersPool[m.ID].socket, m.Buffer);
                break;

            case 1008:
                Respawn r = new Respawn(Packet);
                if (r.Change == 1)
                {
                    r.lane = (byte)(ran.Next(0, 3));
                }
                socket.Send(charactersPool[0].socket, r.Buffer);
                break;
            }
        }
예제 #8
0
 private void Awake()
 {
     gobj            = GetComponent <GroundedObject>();
     gobj.groundMask = LayerMask.GetMask("Ground");
 }