示例#1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Palette")
        {
            //give more directoin when velocity of the paddle isnt 0
            ps = other.GetComponent <PaletteScript>();

            paddleVel = ps.velocity;
            bool isRight = ps.isRight;

            direction.Normalize();

            if (isRight && direction.x > 0)
            {
                //if right paddle invert  direction x and add paddle speed
                direction.x  = -direction.x;
                direction.y += paddleVel / dividingFac;

                SendBang(_transmitterRight, "/paddle/hit/ball");
                SendBang(_transmitterRight, "/paddle/hit/ball/left");
                //bullet time slow motion
            }
            if (!isRight && direction.x < 0)
            {
                //if left paddle invert  direction x and add paddle speed
                direction.x  = -direction.x;
                direction.y += paddleVel / dividingFac;

                SendBang(_transmitterLeft, "/paddle/hit/ball");
                //bullet time slow motion
            }

            direction.x *= (1 + Mathf.Abs(direction.y)) / dirFac;
        }
    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        //get coordinate to create level relative to screenwidth
        bottomLeft = Camera.main.ScreenToWorldPoint(new Vector2(0, 0));
        topRight   = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));
        float width  = topRight.x - bottomLeft.x;
        float height = topRight.y - bottomLeft.y;

        //define partition size relative to screenwidth
        partitionsize = (float)topRight.x / partitionX;
        partitionY    = (float)topRight.y / partitionsize;
        int x = (int)(partitionX * (partitionY + 1));


        circleArr = new GameObject[x];
        float offset = partitionsize;

        colorRight = new Color(1f, 1f, 1f, 0.5f);
        colorLeft  = new Color(1f, 1f, 1f, 0.5f);

        oldColL = colorLeft;
        oldColR = colorRight;



        //place circles on scene
        int t = 0;

        for (int i = 0; i < (int)(partitionY + 1); i++)
        {
            for (int j = 0; j < (int)partitionX; j++)
            {
                //instantiate with position decided by j and i on a grid relative to screen
                circleArr[t] = Instantiate(circleBg, new Vector3(bottomLeft.x + j * (float)width / partitionX + offset, bottomLeft.y + i * (float)height / partitionY + offset, 0), Quaternion.identity);
                cs           = circleArr[t].GetComponent <CircleScript>();
                sr           = circleArr[t].GetComponent <SpriteRenderer>();

                if (Random.Range(0f, 2f) > 1)
                {
                    cs.isRight = true;
                }
                else
                {
                    cs.isRight = false;
                }

                sr.color = new Color(1f, 1f, 1f, 0.5f);
                t++;
            }
        }

        scoreRight = 0;
        scoreLeft  = 0;

        scoreLeftText.text  = scoreLeft.ToString();
        scoreRightText.text = scoreRight.ToString();



        //instantiate both palette and assign sides
        PaletteScript palette1 = Instantiate(palette) as PaletteScript;
        PaletteScript palette2 = Instantiate(palette) as PaletteScript;

        palette1.Init(true);
        palette2.Init(false);



        _receiver = GameObject.Find("OSCRx").GetComponent <OSCReceiver>();
        _receiver.Bind(addrColorLeft, ColorChange);
        _receiver.Bind(addrColorRight, ColorChange);
        _receiver.Bind(addrScaleRight, ScaleChange);
        _receiver.Bind(addrScaleLeft, ScaleChange);
    }