コード例 #1
0
ファイル: PlayerEngine.cs プロジェクト: Raminka/Platformer2D
 private void Start()
 {
     maximumSpeed     = variables.playerVariables.maximumSpeed;
     isOnAir          = true;
     canMoveLaterally = true;
     compteurSaut     = variables.playerVariables.maximumSaut;
     lastWallTouched  = typeOfWall.NONE;
     canGoWest        = true;
     canGoEast        = true;
     inTransparent    = false;
 }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Target"))
        {
            other.GetComponent <Renderer>().material.color = Color.green;
        }

        if (other.CompareTag("North") & gravity.deplacement().y >= 0)
        {
            player.setIsOnAir(true);
            gravity.Off();
            gravity.On();
        }
        if (other.CompareTag("East"))
        {
            actualWall = typeOfWall.EAST;
            if (transform.position.y >= other.transform.position.y - other.transform.lossyScale.y / 2 /*2.5f*/ & transform.position.y <= other.transform.position.y + other.transform.lossyScale.y / 2)//2.5f)
            {
                player.canGoEast   = false;
                transform.position = new Vector3(other.transform.position.x + 0.33f, transform.position.y, transform.position.z);
            }
            else if (gravity.deplacement().y >= 0 & transform.position.y <= other.transform.position.y + other.transform.lossyScale.y / 2)// 2.5f)
            {
                player.setIsOnAir(true);
                gravity.Off();
                gravity.On();
            }
            else if (transform.position.y >= other.transform.position.y + other.transform.lossyScale.y / 2 - 0.1)//2.4f )
            {
                player.setIsOnAir(false);
                gravity.Off();
                transform.position = new Vector3(transform.position.x, other.transform.position.y + other.transform.lossyScale.y / 2 + 0.25f /* 2.75f*/, transform.position.z);
            }
        }
        else if (other.CompareTag("West"))
        {
            actualWall = typeOfWall.WEST;
            if (transform.position.y >= other.transform.position.y - other.transform.lossyScale.y / 2 /*2.5f*/ & transform.position.y <= other.transform.position.y + other.transform.lossyScale.y / 2)//2.5f)
            {
                player.canGoWest   = false;
                transform.position = new Vector3(other.transform.position.x - 0.33f, transform.position.y, transform.position.z);
            }
            else if (gravity.deplacement().y >= 0 & transform.position.y <= other.transform.position.y + other.transform.lossyScale.y / 2) //2.5f)
            {
                player.setIsOnAir(true);
                gravity.Off();
                gravity.On();
            }
            else if (transform.position.y >= other.transform.position.y + other.transform.lossyScale.y / 2 - 0.1)//2.4f)
            {
                player.setIsOnAir(false);
                gravity.Off();
                transform.position = new Vector3(transform.position.x, other.transform.position.y + other.transform.lossyScale.y / 2 + 0.25f /*2.75f*/, transform.position.z);
            }
        }
        else
        {
            actualWall = typeOfWall.NONE;
            player.setLastWall(typeOfWall.NONE);
        }

        if (actualWall != typeOfWall.NONE & actualWall != player.getLastWall())
        {
            player.wallJump();
            player.setLastWall(actualWall);
        }



        if (other.CompareTag("Floor"))
        {
            player.setIsOnAir(false);
        }
        else if (other.CompareTag("Crossable") || other.CompareTag("NonCrossable"))
        {
            float temp = gravity.deplacement().y;
            if (other.transform.position.y <= transform.position.y - 0.15)  //crossable ou non crossable par au-dessus
            {
                player.setIsOnAir(false);
                gravity.Off();
                transform.position = new Vector3(transform.position.x, other.transform.position.y + 0.3f, transform.position.z);
            }
            else if (other.CompareTag("NonCrossable") & gravity.deplacement().y >= 0) //non crossable par en-dessous (de côté ou non)
            {
                player.setCanMoveLaterally(false);
                player.setIsOnAir(true);
                gravity.Off();
                gravity.On();
            }
            else if (other.CompareTag("Crossable") & gravity.deplacement().y >= 0) //crossable par en-dessous
            {
                player.setCanMoveLaterally(true);
            }
            else if (gravity.deplacement().y == temp)  //non crossable par le côté
            {
                player.setCanMoveLaterally(false);
            }
        }

        if (other.CompareTag("trans"))
        {
            player.inTransparent = true;
        }
    }
コード例 #3
0
ファイル: PlayerEngine.cs プロジェクト: Raminka/Platformer2D
 public void setLastWall(typeOfWall wall)
 {
     lastWallTouched = wall;
 }
コード例 #4
0
 private void Start()
 {
     actualWall = typeOfWall.NONE;
 }