Blob Blame Raw
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

const
  count = 20;
  speed = 10;
  br = 10;
  pr = 20;

var
  Form1: TForm1;
  score: integer;
  maxScore: integer;
  px, py: integer;
  bx, by: array[0..count] of integer;

implementation

{$R *.lfm}

procedure DrawPlayer(clear: boolean);
begin
  Form1.Canvas.Pen.Style := psClear;
  Form1.Canvas.Brush.Color := clBlue;
  if clear then Form1.Canvas.Brush.Color := Form1.Color;
  Form1.Canvas.Ellipse(px-pr, py-pr, px+pr, py+pr);
end;

procedure DrawBall(clear: boolean; i: integer);
begin
  Form1.Canvas.Pen.Style := psClear;
  Form1.Canvas.Brush.Color := clBlack;
  if clear then Form1.Canvas.Brush.Color := Form1.Color;
  Form1.Canvas.Ellipse(bx[i]-br, by[i]-br, bx[i]+br, by[i]+br);
end;

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  score := 0;
  px := ClientWidth div 2;
  py := ClientHeight div 2;
  for i := 0 to count-1 do begin
    bx[i] := random(ClientWidth);
    by[i] := -random(ClientHeight);
  end;
  refresh;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  DrawPlayer(true);
  px := x;
  py := y;
  DrawPlayer(false);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to count-1 do begin
    DrawBall(true, i);
    by[i] := by[i] + speed;
    if by[i] > ClientHeight then begin
      bx[i] := random(ClientWidth);
      by[i] := -br;
    end;
    DrawBall(false, i);
  end;

  DrawPlayer(false);

  for i := 0 to count-1 do begin
    if sqr(br+pr) > sqr(bx[i]-px) + sqr(by[i]-py) then begin
      FormCreate(nil);
    end;
  end;

  score := score + 1;
  if score > maxScore then maxScore := score;
  Label1.Caption := IntToStr(score);
  Label2.Caption := IntToStr(maxScore);
end;

end.