Пример #1
0
    string TestPrintState()
    {
        state = "";
        if (groundState.isTouching())
        {
            state += "\n Is Touching a Wall in General.";
        }

        if (groundState.isGround())
        {
            state += "\n Is Touching a Wall on the ground.";
        }
        if (groundState.isWall())
        {
            state += "\n Is Touching a Wall on the side.";
        }
        return(state);
    }
    void FixedUpdate()
    {
        if (!canMove)
        {
            return;
        }

        Dash();

        rb.AddForce(new Vector2(((input.x * speed) - rb.velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player.
        rb.velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : rb.velocity.x,
                                  (input.y == 1 && groundState.isTouching()) ? jumpForce : rb.velocity.y);              //Stop player if input.x is 0 (and grounded) and jump if input.y is 1

        if (groundState.isWall() && !groundState.isGround() && input.y == 1)
        {
            rb.velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, rb.velocity.y); //Add force negative to wall direction (with speed reduction)
        }
        input.y = 0;
    }
    void FixedUpdate()
    {
        GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0));                                                                       //Move player.
        GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1

        if (groundState.isWall() && !groundState.isGround() && input.y == 1)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction)
        }
        input.y = 0;
    }
Пример #4
0
    void FixedUpdate()
    {
        if (!SonoSuPiattaforma)
        {
            GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0));                                                                       //Move player.
            GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1
        }
        else
        {
            //if(input.x != )
        }

        if (groundState.isWall() && !groundState.isGround() && input.y == 1)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction)
            if (photonView.isMine && PlayerNetwork.possoMorire)
            {
                photonView.RPC("SuonoSalto", PhotonTargets.All);
            }
        }
        if (groundState.isGround() && input.y == 1 && photonView.isMine && PlayerNetwork.possoMorire)
        {
            photonView.RPC("SuonoSalto", PhotonTargets.All);
        }

        anim.SetFloat("Speed", Mathf.Abs(input.x));
        anim.SetBool("IsGrounded", groundState.isGround());
        anim.SetFloat("vSpeed", GetComponent <Rigidbody2D>().velocity.y);

        input.y = 0;
    }
Пример #5
0
    void FixedUpdate()
    {
        if (endGame || paused)
        {
            return;
        }
        GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.onGround() ? accel : airAccel), 0));
        GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.onGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y);

        if (groundState.onWall() && !groundState.onGround() && input.y == 1)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.getWallDir() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y);
        }

        input.y = 0;
    }
    void Update()
    {
        if (Team.team.Length == 0)
        {
            return;
        }
        speedTimer -= Time.deltaTime;
        if (speedTimer <= 0)
        {
            speed = 5 + GetComponent <CharacterStats> ().Speed.GetValue();
            if (speed <= 5)
            {
                speed = 10f;
            }
        }
        if (Input.GetKey(KeyBindScript.keys["Up"]))
        {
            rawY = 1f;
        }
        else if (Input.GetKey(KeyBindScript.keys["Down"]))
        {
            rawY = -1f;
        }
        else
        {
            rawY = 0f;
        }

        CharacterStats Character = GetComponent <CharacterStats> ();

        //Handle input
        if (groundState.isTouching() && Input.GetKeyDown(KeyBindScript.keys["Jump"]) && !GetComponent <CharacterStats>().knockBack)
        {
            anim.SetTrigger("takeOf");
            isJumping       = true;
            jumpTimeCounter = jumpTime;
            if (groundState.isTouching())
            {
                createDust();
            }
            input.y = 1;
            audioManager.Play("PlayerJump");
        }
        if (groundState.isGround() == false)
        {
            anim.SetBool("isJumping", true);
        }
        else
        {
            anim.SetBool("isJumping", false);
        }
        if (Input.GetKey(KeyBindScript.keys["Jump"]) && isJumping == true)
        {
            if (jumpTimeCounter > 0)
            {
                // GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 1 * jump);

                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                isJumping = false;
            }
        }
        if (Input.GetKeyUp(KeyBindScript.keys["Jump"]))
        {
            isJumping = false;
        }

        if (Input.GetKey(KeyBindScript.keys["Left"]) && !GetComponent <CharacterStats>().knockBack)
        {
            input.x     = -1;
            lastInput.x = -1;
            if (transform.localRotation.y == 0)
            {
                if (groundState.isGround())
                {
                    createDust();
                }
                if (!isFiring)
                {
                    transform.localRotation = Quaternion.Euler(0, 180, 0);
                    facing = -1;
                }
            }
            if (!isJumping)
            {
                anim.SetBool("isRunning", true);
            }
        }
        else if (Input.GetKey(KeyBindScript.keys["Right"]) && !GetComponent <CharacterStats>().knockBack)
        {
            input.x     = 1;
            lastInput.x = 1;
            if (transform.localRotation.y == -1)
            {
                if (groundState.isGround())
                {
                    createDust();
                }
                if (!isFiring)
                {
                    transform.localRotation = Quaternion.Euler(0, 0, 0);
                    facing = 1;
                }
            }
            if (!isJumping)
            {
                anim.SetBool("isRunning", true);
            }
        }
        else
        {
            input.x = 0;
            anim.SetBool("isRunning", false);
        }
        if (isJumping)
        {
            anim.SetBool("isRunning", false);
        }
        if (isJumping && groundState.isGround())
        {
            isJumping = false;
        }
        if (GetComponent <Rigidbody2D> ().velocity.y < 0 && groundState.isTouching() == false)
        {
            jumped = true;
        }
        if (groundState.isWall() && !groundState.isGround())
        {
            anim.SetBool("isWall", true);
            createDust();
        }
        else
        {
            anim.SetBool("isWall", false);
        }
        // Fire
        if (Character.currentAffliction != "Pacifist")
        {
            if (Input.GetKey(KeyBindScript.keys["Fire"]) && Time.time > nextFire)
            {
                nextFire = Time.time + Team.team[GetComponent <CharacterStats> ().currentChar].fireRate;
                fire();
                // shake.camShake();
            }
            if (Input.GetKeyDown(KeyBindScript.keys["Fire"]))
            {
                isFiring = true;
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Fire"]))
            {
                isFiring = false;
            }
        }
        // Mechanic
        if (Character.ClassType.GetValue() == 1)          // Runner
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && canDash && Time.time > nextDash)
            {
                audioManager.Play("Runner", UnityEngine.Random.Range(1, 3));
                Dash(input.x, rawY);
                Team.team[Character.currentChar].runner_state = 0;
                nextDash = Time.time + Character.runner_CDR;
            }
            else if (Time.time > nextRefreshRunner)
            {
                nextRefreshRunner = Time.time + 0.1f;
                if (Team.team[Character.currentChar].runner_state + Team.team[Character.currentChar].runner_step > 20)
                {
                    Team.team[Character.currentChar].runner_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].runner_state += Team.team[Character.currentChar].runner_step;
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 2)            //Climber
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && Time.time > nextClimb)
            {
                //create the link (raycast ...)
                audioManager.Play("Climber", UnityEngine.Random.Range(1, 3));

                int          LayerIndex = LayerMask.NameToLayer("Ground");
                int          layerMask  = (1 << LayerIndex);
                RaycastHit2D hit;

                hit                   = Physics2D.Raycast(transform.position, new Vector2(facing < 0 ? -0.5f : 0.5f, 1), Mathf.Infinity, layerMask);
                joint.enabled         = true;
                joint.connectedBody   = hit.collider.gameObject.GetComponent <Rigidbody2D> ();
                joint.connectedAnchor = hit.point - new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.y);
                joint.distance        = Vector2.Distance(transform.position, hit.point);
                line.enabled          = true;
                line.SetPosition(0, transform.position);
                line.SetPosition(1, hit.point);
                nextClimb = Time.time + Character.climber_CDR;
                if (Team.team[Character.currentChar].climber_state == 20)
                {
                    Team.team[Character.currentChar].climber_state = 0;
                }
            }
            else if (Time.time > nextRefreshClimber)
            {
                nextRefreshClimber = Time.time + 0.1f;
                if (Team.team[Character.currentChar].climber_state + Team.team[Character.currentChar].climber_step > 20)
                {
                    Team.team[Character.currentChar].climber_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].climber_state += Team.team[Character.currentChar].climber_step;
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                if (joint.distance > 0.2f)
                {
                    joint.distance -= step;
                }
                else
                {
                    joint.enabled = false;
                    line.enabled  = false;
                }
                line.SetPosition(0, transform.position);
            }
            else if (Time.time > nextRefreshClimber)
            {
                nextRefreshClimber = Time.time + 0.1f;
                if (Team.team[Character.currentChar].climber_state + Team.team[Character.currentChar].climber_step > 20)
                {
                    Team.team[Character.currentChar].climber_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].climber_state += Team.team[Character.currentChar].climber_step;
                }
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
                // delete the link

                joint.enabled = false;
                line.enabled  = false;
            }
        }
        else if (Character.ClassType.GetValue() == 3)            // Hacker
        {
            GameObject[] turrets = GameObject.FindGameObjectsWithTag("Turret");
            GameObject   turret  = GetClosestTurret(turrets);
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                audioManager.Play("Hacker", UnityEngine.Random.Range(1, 3));
                // Show range
                foreach (GameObject n in turrets)
                {
                    if (!n.transform.GetChild(1).gameObject.GetComponent <turretScript> ().getDeactivation())
                    {
                        n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = true;
                    }
                    else
                    {
                        n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = false;
                    }
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                if (turret)
                {
                    turret.transform.GetChild(1).gameObject.GetComponent <turretScript> ().hack(transform.position);
                }
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
                // Hide range
                foreach (GameObject n in turrets)
                {
                    n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = false;
                    n.transform.GetChild(1).gameObject.GetComponent <turretScript> ().resetHack();
                }
            }
        }
        else if (Character.ClassType.GetValue() == 4)            // Tracker
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && Time.time > NextFlag && groundState.isGround() && Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags > 0)
            {
                audioManager.Play("Tracker", UnityEngine.Random.Range(1, 3));
                NextFlag = Time.time + FlagRate;
                Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags -= 1;
                GetComponent <CharacterStats> ().UpdatePower();
                // Spawn a landmark
                Instantiate(FlagSprite, new Vector3(transform.position.x, transform.position.y - 0.1f, transform.position.z), Quaternion.identity);
            }
            else if (Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags <= 0)
            {
                // display error msg for 2 sec
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 5)            // Tank
        {
            if (Shield.activeSelf == true)
            {
                Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield += Time.deltaTime;
                Team.team[GetComponent <CharacterStats> ().currentChar].tank_state        = (int)(Team.team[GetComponent <CharacterStats> ().currentChar].tank_shield - Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield);
                GetComponent <CharacterStats> ().UpdatePower();
            }
            if (Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield >= Character.tank_shield)
            {
                canShield = false;
                Shield.SetActive(false);
            }
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                audioManager.Play("Tank", UnityEngine.Random.Range(1, 3));
                if (Shield.activeSelf == false && canShield)
                {
                    Shield.SetActive(true);
                }
                else
                {
                    Shield.SetActive(false);
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 6)            // Grenadier
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                shootBomb();
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                shootBomb();
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
    }