Пример #1
0
    public void Dead()
    {
        GameObject effect = spawner.GetObjectFromPool("BeaconEffect");

        effect.transform.position = this.transform.position;
        player.hp = player.Maxhp;
        ui.score += ui.BeaconScore;
        hp.StartCoroutine(hp.Dead(1));
    }
Пример #2
0
    public void Explode()
    {
        Collider2D[] hits = Physics2D.OverlapCircleAll(this.transform.position, DamageRadius);
        foreach (Collider2D hit in hits)
        {
            if (hit.GetComponent <HP>())
            {
                hit.GetComponent <HP>().TakeDamage(Damage);
            }
        }

        //spawner effect
        GameObject explosion = spawner.GetObjectFromPool("Explosion");

        explosion.transform.position   = this.transform.position;
        explosion.transform.localScale = Vector3.one * (DamageRadius / 5);
    }
Пример #3
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            Dead();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Weapon = WeaponType.MachineGun;
            Laser.SetActive(false);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            Weapon = WeaponType.Laser;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            Weapon = WeaponType.GrenadeLauncher;
        }

        moveVelocity = 0;

        switch (Weapon)
        {
        case WeaponType.Laser:
            if (Input.GetMouseButton(0))
            {
                Laser.SetActive(true);
            }
            else
            {
                Laser.SetActive(false);
            }
            break;

        case WeaponType.MachineGun:
            if (Input.GetMouseButton(0))
            {
                if (mg_timer <= 0)
                {
                    GameObject Bullet    = spawner.GetObjectFromPool("Bullet");
                    Vector2    cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Bullet.transform.position = this.transform.position;
                    Bullet.GetComponent <Rigidbody2D>().velocity = (cursorPos - (Vector2)this.transform.position).normalized * mg_bulletSpeed;
                    mg_timer = 1 / mg_firerate;
                }
            }
            mg_timer -= Time.deltaTime;
            break;

        case WeaponType.GrenadeLauncher:
            if (Input.GetMouseButton(0))
            {
                if (gl_timer <= 0)
                {
                    GameObject Bullet    = spawner.GetObjectFromPool("Grenade");
                    Vector2    cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Bullet.transform.position = this.transform.position;
                    Bullet.GetComponent <Rigidbody2D>().velocity = (cursorPos - (Vector2)this.transform.position).normalized * gl_bulletSpeed;
                    gl_timer = 1 / gl_firerate;
                }
            }
            gl_timer -= Time.deltaTime;
            break;

        default:
            break;
        }

        //Left Right Movement
        float x = 0;
        float y = 0;

        if (Input.GetKey(KeyCode.A))
        {
            moveVelocity = -move_speed;
            x           -= 1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveVelocity = move_speed;
            x           += 1;
        }

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
        {
            AD_input = true;
        }
        else
        {
            AD_input = false;
        }

        if (Input.GetKey(KeyCode.W))
        {
            y += 1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            y -= 1;
        }
        inputDirection = new Vector2(x, y);

        //through platform
        if (Input.GetKeyDown(KeyCode.S))
        {
            cl.isTrigger = true;
        }
        else if (Input.GetKeyUp(KeyCode.S))
        {
            cl.isTrigger = false;
        }

        if (ControlMode == PlayerControlMode.V1)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (grounded && !jump)
                {
                    rb.velocity = new Vector2(rb.velocity.x, jump_speed);
                    jump        = true;
                }
                else if (remainingDash > 0 && !grounded && !dash)
                {
                    jump = false;

                    remainingDash--;
                    remainingDashTime = DashTime;

                    angle = Mathf.Atan2(mc.cursorPos.y - transform.position.y, mc.cursorPos.x - transform.position.x);
                    //if (inputDirection.x == 0)
                    //{
                    //    inputDirection.y = 1;
                    //}
                    tempDashDirection = inputDirection;
                    hp.invincible     = true;
                    dash = true;
                    //trail.emitting = true;
                    rb.gravityScale = 0;
                }
            }
        }
        else if (ControlMode == PlayerControlMode.V2)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (remainingDashJump > 0)
                {
                    remainingDashJump--;
                    rb.velocity = new Vector2(rb.velocity.x, jump_speed);
                }
            }

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                if (remainingDashJump > 0 && !grounded && !dash)
                {
                    remainingDashJump--;
                    remainingDashTime = DashTime;

                    angle = Mathf.Atan2(mc.cursorPos.y - transform.position.y, mc.cursorPos.x - transform.position.x);
                    //if (inputDirection.x == 0)
                    //{
                    //    inputDirection.y = 1;
                    //}
                    tempDashDirection = inputDirection;
                    hp.invincible     = true;
                    dash = true;
                    //trail.emitting = true;
                    rb.gravityScale = 0;
                }
            }
        }
        else if (ControlMode == PlayerControlMode.V3)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (remainingJump > 0)
                {
                    remainingJump--;
                    rb.velocity = new Vector2(rb.velocity.x, jump_speed);
                }
            }

            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                if (remainingDash > 0 && !grounded && !dash)
                {
                    remainingDash--;
                    remainingDashTime = DashTime;

                    angle = Mathf.Atan2(mc.cursorPos.y - transform.position.y, mc.cursorPos.x - transform.position.x);
                    //if (inputDirection.x == 0)
                    //{
                    //    inputDirection.y = 1;
                    //}
                    tempDashDirection = inputDirection;
                    hp.invincible     = true;
                    dash = true;
                    //trail.emitting = true;
                    rb.gravityScale = 0;
                }
            }
        }
    }