описуємо
Нова форма FormGame
Описуємо
Кнопку називаємо raacket, перешкоди brick1,2,3,4,5, мяч ball
Поля label_right label_top label_left
private void move_ball()
{
int bx1, bx2, by1, by2;
bx1 = ball_x;
bx2 = ball_x + ball.Width;
by1 = ball_y;
by2 = ball_y + ball.Height;
if (bx1 + ball_sx < side_lx)
ball_sx = ball_shift_x;
if (bx2 + ball_sx > side_rx)
ball_sx = -ball_shift_x;
if (by1 + ball_sy < side_uy)
ball_sy = ball_shift_y;
if (by2 + ball_sy > racket_y)
{
// bool lose = true;
int bx0, by0;
bx0 = (bx1 + bx2) / 2;
by0 = (by1 + by2) / 2;
int rx1, rx2;
rx1 = racket_x;
rx2 = racket_x + raacket.Width;
if (rx1 <= bx0 && bx0 <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1,2);
}
else
if (rx1 <= bx2 + ball.Width && bx2 + ball.Width <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1, 2);
ball_sx = -ball_shift_x + rnd.Next(-1, 2);
}
else
if (rx1 <= bx1 - ball.Width && bx1 - ball.Width <= rx2)
{
ball_sy = -ball_shift_y + rnd.Next(-1, 2);
ball_sx = ball_shift_x + rnd.Next(-1, 2);
}
else
lose_ball();
}
ball_x += ball_sx;
ball_y += ball_sy;
ball.Location = new Point(ball_x, ball_y);
cross_brick(brick1);
cross_brick(brick2);
cross_brick(brick3);
cross_brick(brick4);
cross_brick(brick5);
}
private void cross_brick(Label brick)
{
if (!brick.Visible) return;
int bx1, bx2, bx0;
int by1, by2, by0;
int rx1, rx2, ry1, ry2;
bx1 = ball_x;
bx2 = ball_x+ball.Width;
bx0 = (bx1 / bx2) / 2;
by1 = ball_y;
by2 = ball_y + ball.Height;
by0 = (by1 / by2) / 2;
rx1 = brick.Location.X;
rx2 = rx1 + brick.Width;
ry1 = brick.Location.Y;
ry2 = ry1 + brick.Height;
if (rx1
ry1<=by2 && by2<=ry2)
{
drop_brick(brick);
ball_sy = -ball_sy;
return;
}
if (rx1 <= bx2 && bx2 <= rx2 &&
ry1 <= by0 && by0 <= ry2)
{
drop_brick(brick);
ball_sx = -ball_sx;
return;
}
if (rx1 <= bx2 && bx1 <= rx2 &&
ry1 <= by0 && by0 <= ry2)
{
drop_brick(brick);
ball_sx = -ball_sx;
return;
}
if (rx1 <= bx1 && bx1 <= rx2 &&
ry1 <= by0 && by0 <= ry2)
{
drop_brick(brick);
ball_sx = -ball_sx;
return;
}
if ((rx1 <= bx2 && bx2 <= rx2 && ry1 <= by2
&& by2 <= ry2) ||
(rx1 <= bx2 && bx2 <= rx2 && ry1 <= by2 && by2 <= ry2) ||
(rx1 <= bx2 && bx2 <= rx2 && ry1 <= by1 && by1 <= ry2) ||
(rx1 <= bx2 && bx2 <= rx2 && ry1 <= by2 && by2 <= ry2))
{
drop_brick(brick);
ball_sx = -ball_sx;
ball_sy = -ball_sy;
return;
}
}
Комментариев нет:
Отправить комментарий