示例#1
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();

            paddleRect.Origin.X += paddle.Position.X;
            paddleRect.Origin.Y += paddle.Position.Y;

            float lowY  = paddleRect.MinY;
            float midY  = paddleRect.MidY;
            float highY = paddleRect.MaxY;

            float leftX  = paddleRect.MinX;
            float rightX = paddleRect.MaxX;

            if (Position.X > leftX && Position.X < rightX)
            {
                bool  hit         = false;
                float angleOffset = 0.0f;

                if (Position.Y > midY && Position.Y <= highY + radius())
                {
                    Position    = new CCPoint(Position.X, highY + radius());
                    hit         = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (Position.Y < midY && Position.Y >= lowY - radius())
                {
                    Position    = new CCPoint(Position.X, lowY - radius());
                    hit         = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
                    float hitAngle = (float)Math.Atan2(new CCPoint(paddle.Position.X - Position.X, paddle.Position.Y - Position.Y).Y, new CCPoint(paddle.Position.X - Position.X, paddle.Position.Y - Position.Y).X) + angleOffset;

                    float scalarVelocity = (float)Math.Sqrt((double)(m_velocity.X * m_velocity.X + m_velocity.Y * m_velocity.Y)) * 1.05f;
                    float velocityAngle  = -(float)Math.Atan2(m_velocity.Y, m_velocity.X) + 0.5f * hitAngle;

                    m_velocity = new CCPoint(new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).X *scalarVelocity, new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).Y *scalarVelocity);
                }
            }
        }
示例#2
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();

            paddleRect.origin.x += paddle.position.x;
            paddleRect.origin.y += paddle.position.y;

            float lowY  = CCRect.CCRectGetMinY(paddleRect);
            float midY  = CCRect.CCRectGetMidY(paddleRect);
            float highY = CCRect.CCRectGetMaxY(paddleRect);

            float leftX  = CCRect.CCRectGetMinX(paddleRect);
            float rightX = CCRect.CCRectGetMaxX(paddleRect);

            if (position.x > leftX && position.x < rightX)
            {
                bool  hit         = false;
                float angleOffset = 0.0f;

                if (position.y > midY && position.y <= highY + radius())
                {
                    position    = new CCPoint(position.x, highY + radius());
                    hit         = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (position.y < midY && position.y >= lowY - radius())
                {
                    position    = new CCPoint(position.x, lowY - radius());
                    hit         = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
                    float hitAngle = (float)Math.Atan2(new CCPoint(paddle.position.x - position.x, paddle.position.y - position.y).y, new CCPoint(paddle.position.x - position.x, paddle.position.y - position.y).x) + angleOffset;

                    float scalarVelocity = (float)Math.Sqrt((double)(m_velocity.x * m_velocity.x + m_velocity.y * m_velocity.y)) * 1.05f;
                    float velocityAngle  = -(float)Math.Atan2(m_velocity.y, m_velocity.x) + 0.5f * hitAngle;

                    m_velocity = new CCPoint(new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).x *scalarVelocity, new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).y *scalarVelocity);
                }
            }
        }
示例#3
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();
            paddleRect.Origin.X += paddle.Position.X;
            paddleRect.Origin.Y += paddle.Position.Y;

            float lowY = CCRect.CCRectGetMinY(paddleRect);
            float midY = CCRect.CCRectGetMidY(paddleRect);
            float highY = CCRect.CCRectGetMaxY(paddleRect);

            float leftX = CCRect.CCRectGetMinX(paddleRect);
            float rightX = CCRect.CCRectGetMaxX(paddleRect);

            if (Position.X > leftX && Position.X < rightX)
            {

                bool hit = false;
                float angleOffset = 0.0f;

                if (Position.Y > midY && Position.Y <= highY + radius())
                {
                    Position = new CCPoint(Position.X, highY + radius());
                    hit = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (Position.Y < midY && Position.Y >= lowY - radius())
                {
                    Position = new CCPoint(Position.X, lowY - radius());
                    hit = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
                    float hitAngle = (float)Math.Atan2(new CCPoint(paddle.Position.X - Position.X, paddle.Position.Y - Position.Y).Y, new CCPoint(paddle.Position.X - Position.X, paddle.Position.Y - Position.Y).X) + angleOffset;

                    float scalarVelocity = (float)Math.Sqrt((double)(m_velocity.X * m_velocity.X + m_velocity.Y * m_velocity.Y)) * 1.05f;
                    float velocityAngle = -(float)Math.Atan2(m_velocity.Y, m_velocity.X) + 0.5f * hitAngle;

                    m_velocity = new CCPoint(new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).X * scalarVelocity, new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).Y * scalarVelocity);
                }
            }
        }
示例#4
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();
            paddleRect.origin.x += paddle.position.x;
            paddleRect.origin.y += paddle.position.y;

            float lowY = CCRect.CCRectGetMinY(paddleRect);
            float midY = CCRect.CCRectGetMidY(paddleRect);
            float highY = CCRect.CCRectGetMaxY(paddleRect);

            float leftX = CCRect.CCRectGetMinX(paddleRect);
            float rightX = CCRect.CCRectGetMaxX(paddleRect);

            if (position.x > leftX && position.x < rightX)
            {

                bool hit = false;
                float angleOffset = 0.0f;

                if (position.y > midY && position.y <= highY + radius())
                {
                    position = new CCPoint(position.x, highY + radius());
                    hit = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (position.y < midY && position.y >= lowY - radius())
                {
                    position = new CCPoint(position.x, lowY - radius());
                    hit = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
                    float hitAngle = (float)Math.Atan2(new CCPoint(paddle.position.x - position.x, paddle.position.y - position.y).y, new CCPoint(paddle.position.x - position.x, paddle.position.y - position.y).x) + angleOffset;

                    float scalarVelocity = (float)Math.Sqrt((double)(m_velocity.x * m_velocity.x + m_velocity.y * m_velocity.y)) * 1.05f;
                    float velocityAngle = -(float)Math.Atan2(m_velocity.y, m_velocity.x) + 0.5f * hitAngle;

                    m_velocity = new CCPoint(new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).x * scalarVelocity, new CCPoint((float)Math.Cos(velocityAngle), (float)Math.Sin(velocityAngle)).y * scalarVelocity);
                }
            }
        }
示例#5
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();
            paddleRect.Origin.X += paddle.Position.X;
            paddleRect.Origin.Y += paddle.Position.Y;

            float lowY = paddleRect.MinY;
            float midY = paddleRect.MidY;
            float highY = paddleRect.MaxY;

            float leftX = paddleRect.MinX;
            float rightX = paddleRect.MaxX;

            if (Position.X > leftX && Position.X < rightX)
            {

                bool hit = false;
                float angleOffset = 0.0f;

                if (Position.Y > midY && Position.Y <= highY + radius())
                {
                    Position = new CCPoint(Position.X, highY + radius());
                    hit = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (Position.Y < midY && Position.Y >= lowY - radius())
                {
                    Position = new CCPoint(Position.X, lowY - radius());
                    hit = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
					float hitAngle = (paddle.Position - Position).Angle + angleOffset;
                    float scalarVelocity = m_velocity.Length * 1.05f;
                    float velocityAngle = -m_velocity.Angle + 0.5f * hitAngle;

					m_velocity = CCPoint.ForAngle(velocityAngle) * scalarVelocity;
                }
            }
        }
示例#6
0
        public void collideWithPaddle(Paddle paddle)
        {
            CCRect paddleRect = paddle.rect();

            paddleRect.Origin.X += paddle.Position.X;
            paddleRect.Origin.Y += paddle.Position.Y;

            float lowY  = paddleRect.MinY;
            float midY  = paddleRect.MidY;
            float highY = paddleRect.MaxY;

            float leftX  = paddleRect.MinX;
            float rightX = paddleRect.MaxX;

            if (Position.X > leftX && Position.X < rightX)
            {
                bool  hit         = false;
                float angleOffset = 0.0f;

                if (Position.Y > midY && Position.Y <= highY + radius())
                {
                    Position    = new CCPoint(Position.X, highY + radius());
                    hit         = true;
                    angleOffset = (float)Math.PI / 2;
                }
                else if (Position.Y < midY && Position.Y >= lowY - radius())
                {
                    Position    = new CCPoint(Position.X, lowY - radius());
                    hit         = true;
                    angleOffset = -(float)Math.PI / 2;
                }

                if (hit)
                {
                    float hitAngle       = (paddle.Position - Position).Angle + angleOffset;
                    float scalarVelocity = m_velocity.Length * 1.05f;
                    float velocityAngle  = -m_velocity.Angle + 0.5f * hitAngle;

                    m_velocity = CCPoint.ForAngle(velocityAngle) * scalarVelocity;
                }
            }
        }