Example #1
0
    // Update is called once per frame
    void Update()
    {
        velocity.y -= 6f * Time.deltaTime;

        float current_x = transform.position.x;
        float current_y = transform.position.y;
        float diff_x    = velocity.x * Time.deltaTime;
        float diff_y    = velocity.y * Time.deltaTime;
        float change_x  = current_x + diff_x;
        float change_y  = current_y + diff_y;

        int result_x = 0;
        int result_y = 0;

        while (groundController.CheckCollisionBetween(current_x * 80, current_y * 80, change_x * 80, change_y * 80, ref result_x, ref result_y) == true)
        {
            Tool.EmitWeaponSound(clipBomb);
            groundController.ExplodeGround(result_x, result_y, radius);
            Tool.CreateExplosionParticle(new Vector3(0.0125f * result_x, 0.0125f * result_y, -5), 40);

            if (--remain == 0)
            {
                Destroy(gameObject);

                // get next turn player
                GameDirector.GetNextTank().NextTurn(1);
                return;
            }
        }

        int   dir   = GetComponent <SpriteRenderer>().flipX ? 1 : -1;
        float angle = Mathf.Atan2(velocity.y * dir, velocity.x * dir) * 180 / Mathf.PI;

        transform.Translate(velocity.x * Time.deltaTime, velocity.y * Time.deltaTime, 0, Space.World);
        transform.rotation = Quaternion.Euler(0, 0, angle);
        if (transform.position.x < -10 || transform.position.x > 19.2f || transform.position.y < -3)
        {
            Destroy(gameObject);
            // get next turn player
            GameDirector.GetNextTank().NextTurn(1);
            return;
        }
        Camera.main.GetComponent <CameraController>().FollowCamera(transform.position);
    }