GetAnother() public method

public GetAnother ( int offset = 1 ) : Pongpector,
offset int
return Pongpector,
Exemplo n.º 1
0
    public void Update()
    {
        if (isTop)
        {
            isValid = (pongpector.GetAnother(-1) == null);
        }
        else
        {
            isValid = (pongpector.GetAnother(1) == null);
        }
        if (!isValid)
        {
            return;
        }
        var rx = Mathf.Clamp(x * pongpector.width, width / 2 + 1, pongpector.width - width / 2 - 1);

        texture.DrawFilledRectangle(new Rect
                                        (rx - width / 2, y - height / 2, width, height), Color.blue);
    }
Exemplo n.º 2
0
    public bool Update()
    {
        pos += vel * speed;
        if (speed < 1)
        {
            speed += 0.01f;
        }
        if ((pos.x < pongpector.wallWidth + radius && vel.x < 0) ||
            (pos.x > pongpector.width - pongpector.wallWidth - radius && vel.x > 0))
        {
            vel.x *= -1;
        }
        if (pongpector.TestRacketCollision(pos, vel, radius))
        {
            vel.y *= -1;
            pongpector.AddScore();
        }
        var offset = 0;

        if (pos.y > pongpector.height + radius)
        {
            offset     = 1;
            this.pos.y = -radius;
        }
        else if (pos.y < -radius)
        {
            offset     = -1;
            this.pos.y = pongpector.height + radius;
        }
        if (offset != 0)
        {
            var np = pongpector.GetAnother(offset);
            if (np != null)
            {
                np.AddBall(this.pos, this.vel);
            }
            else
            {
                pongpector.Miss();
            }
            return(false);
        }
        texture.DrawFilledCircle((int)pos.x, (int)pos.y, radius, Color.blue);
        return(true);
    }