unit ufrmBreakout;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls, uCoords, uBrick, UPaddle, UBall;
type
TfrmBreakout =
class(TForm)
lblTime: TLabel;
lblScore: TLabel;
ptbGame: TPaintBox;
TmrGame: TTimer;
procedure FormCreate(Sender: TObject);
procedure TimerTick(Sender: TObject);
private
bricks : TList;
paddle : TPaddle;
balls : TList;
end;
const
BrickColumn = 8;
BrickRows = 5;
PaddleStartX = 192;
PaddleStartY = 380;
BallStartAngle = 90;
var
frmBreakout: TfrmBreakout;
implementation
{$R *.dfm}
procedure TfrmBreakout.FormCreate(Sender: TObject);
var
Coords: TCoords;
Brick: TBrick;
x,y: Integer;
xBall, yBall : Integer;
begin
//create the bricks
bricks := TList.Create;
for x := 0
to (BrickColumn-1)
do
begin
for y := 0
to (BrickRows-1)
do
begin
Coords := TCoords.Create(x*uBrick.BrickWidth,y*uBrick.BrickHeight);
Brick := TBrick.Create(Coords);
bricks.Add(Brick);
end;
end;
//create the paddle
Coords := TCoords.Create(PaddleStartX,PaddleStartY);
paddle := TPaddle.Create(Coords);
//create the ball
xBall := PaddleStartX + (uPaddle.PaddleWidth
div 2);
yBall := PaddleStartY - UBall.BallRadius;
Coords := TCoords.Create(xBall,yBall);
balls := TList.Create;
balls.Add(TBall.Create(Coords,BallStartAngle,0,-1));
end;
procedure TfrmBreakout.TimerTick(Sender: TObject);
var
i, j : Integer;
Ball: TBall;
Brick: TBrick;
begin
for i := 0
to balls.Count-1
do
begin
Ball := balls[i];
for j := 0
to bricks.Count-1
do
begin
Brick := bricks[j];
Brick.Collide(Ball);
end;
Ball.Coords.X := Ball.Coords.X+round(Ball.XSpeed);
Ball.Coords.Y := Ball.Coords.Y+round(Ball.YSpeed);
lblScore.Caption := '
y: ' + FloatToStr(Ball.YSpeed);
end;
end;
end.