Esempio n. 1
0
    void Sleeped(Vector3 vel)
    {
        if (sleep_time <= current_root_time)
        {
            slowliness        = 0f;
            current_M_state   = Player_M_states.NORMAL;
            current_root_time = 0f;
            ResetSlowliness();
        }
        else
        {
            if (current_root_time < 1)
            {
                slowliness          = 1 - current_root_time;
                can_throw_abilities = true;
            }
            else
            {
                can_throw_abilities = false;
            }

            current_root_time += Time.fixedDeltaTime;
        }

        vel           = vel * velocity * Time.fixedDeltaTime * slowliness;
        body.velocity = vel;
    }
Esempio n. 2
0
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.CompareTag("Bullet"))
        {
            OnCollisonDestroy c = col.gameObject.GetComponent <OnCollisonDestroy>();
            SlowMe(c.force, c.slow_time);
        }

        else if (col.gameObject.CompareTag("ShotGun"))
        {
            Vector3 direction = col.transform.position;
            direction.y = 0;
            direction  -= transform.position;
            float force = col.gameObject.GetComponent <OnCollisonDestroy>().force;
            PushMe(-direction.normalized, (int)force, col.gameObject.GetComponent <OnCollisonDestroy>().slow_time);
        }

        else if (col.gameObject.CompareTag("SlowBullet"))
        {
            OnCollisonDestroy c = col.gameObject.GetComponent <OnCollisonDestroy>();
            slowliness      = 1 - c.force;
            sleep_time      = c.slow_time;
            current_M_state = Player_M_states.SLEEPED;
            Invoke("ResetSlowliness", 5f);
        }
    }
Esempio n. 3
0
    void Dash(Vector3 dir)
    {
        dash_current_cooldown += Time.fixedDeltaTime;

        int x = di_x ? -1 : 1;
        int z = di_z ? -1 : 1;

        Vector3 shoot_tmp = shoot_point;

        if (Mathf.Abs(dir.x) < Mathf.Abs(dir.z))
        {
            shoot_tmp.z = shoot_tmp.x;
            shoot_tmp.x = 0;
        }
        shoot_tmp.x *= x;
        shoot_tmp.z *= z;

        Vector3 speed = dir.normalized * dash_force * velocity * Time.fixedDeltaTime;

        body.velocity = dir.normalized * dash_force * velocity * Time.fixedDeltaTime;


        if (dash_time <= dash_current_cooldown)
        {
            current_M_state       = Player_M_states.NORMAL;
            curr_col.enabled      = true;
            dash_current_cooldown = 0.0f;
        }
    }
Esempio n. 4
0
 public void RootMe(float time)
 {
     if (current_M_state == Player_M_states.NORMAL || current_M_state == Player_M_states.PUSHED)
     {
         body.velocity     = Vector3.zero;
         current_M_state   = Player_M_states.ROOTED;
         root_time         = time;
         current_root_time = 0f;
     }
 }
Esempio n. 5
0
 public void PushMe(Vector3 direction, int push_force, float push_time)
 {
     if (last_time_pushed > 0.2f)
     {
         body.AddForce(direction * velocity * push_force);
         current_M_state     = Player_M_states.PUSHED;
         last_time_pushed    = 0.0f;
         current_time_pushed = 0f;
         time_pushed         = push_time;
     }
 }
Esempio n. 6
0
    void Update()
    {
        //DASH -------------------------------------
        if (dash_cooldown <= dash_current_cooldown && AbilitiesUp())
        {
            if (GamePad.GetButtonDown(dash_button, player_num) || Input.GetKeyDown(dash_test_button))
            {
                current_M_state       = Player_M_states.DASHING;
                curr_col.enabled      = false;
                dash_current_cooldown = 0.0f;
            }
        }
        else if (current_M_state == Player_M_states.NORMAL)
        {
            dash_current_cooldown += Time.deltaTime;
        }

        if (GamePad.GetButtonDown(recharge_button, player_num) || Input.GetKeyDown(recharge_test_button))
        {
            Invoke("RechargeCharges", charges_reload_time);
        }
    }
Esempio n. 7
0
    void FixedUpdate()
    {
        Vector2 inp = GamePad.GetAxis(GamePad.Axis.LeftStick, player_num, false);
        float   h   = inp.x;
        float   v   = inp.y;

        if (Mathf.Abs(h) > 0.01f)
        {
            di_x = (h > 0) ? false : true;
        }
        if (Mathf.Abs(v) > 0.01f)
        {
            di_z = (v > 0) ? false : true;
        }

        if (AbilitiesUp())
        {
            GetComponent <SpriteRenderer>().flipX = di_x;
        }

        Vector3 vel = new Vector3(h, 0, v);

        slowliness = 1f;
        foreach (float f in slow_list)
        {
            if (f < slowliness)
            {
                slowliness = f;
            }
        }

        speed_boost = 1f;
        foreach (float f in speed_list)
        {
            if (f > speed_boost)
            {
                speed_boost = f;
            }
        }

        switch (current_M_state)
        {
        case Player_M_states.NORMAL:
            vel                 = vel * velocity * Time.fixedDeltaTime * slowliness * speed_boost;
            body.velocity       = vel;
            can_throw_abilities = true;
            break;

        case Player_M_states.DASHING:
            Dash(vel);
            can_throw_abilities = false;
            break;

        case Player_M_states.PUSHED:
            if (time_pushed < current_time_pushed)
            {
                current_M_state = Player_M_states.NORMAL;
            }
            else
            {
                current_time_pushed += Time.fixedDeltaTime;
            }
            can_throw_abilities = false;
            break;

        case Player_M_states.SLEEPED:
            Sleeped(vel);
            break;

        case Player_M_states.ROOTED:
            can_throw_abilities = true;
            if (root_time <= current_root_time)
            {
                current_M_state   = Player_M_states.NORMAL;
                current_root_time = 0f;
            }
            else
            {
                current_root_time += Time.fixedDeltaTime;
            }
            break;

        case Player_M_states.STUNED:
            can_throw_abilities = false;
            if (root_time <= current_root_time)
            {
                current_M_state   = Player_M_states.NORMAL;
                current_root_time = 0f;
            }
            else
            {
                current_root_time += Time.fixedDeltaTime;
            }
            break;

        case Player_M_states.PAUSED:
            can_throw_abilities = false;
            break;
        }
        last_time_pushed += Time.fixedDeltaTime;

        if (player_animator != null)
        {
            player_animator.SetFloat("Velocity", vel.magnitude);
        }
    }