diff --git a/lazarus/scroller/project1.ico b/lazarus/scroller/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/scroller/project1.ico differ diff --git a/lazarus/scroller/project1.lpi b/lazarus/scroller/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/scroller/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/scroller/project1.lpr b/lazarus/scroller/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/scroller/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/scroller/project1.res b/lazarus/scroller/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/scroller/project1.res differ diff --git a/lazarus/scroller/unit1.lfm b/lazarus/scroller/unit1.lfm new file mode 100644 index 0000000..d9ba95d --- /dev/null +++ b/lazarus/scroller/unit1.lfm @@ -0,0 +1,34 @@ +object Form1: TForm1 + Left = 183 + Height = 443 + Top = 258 + Width = 461 + Caption = 'Form1' + ClientHeight = 443 + ClientWidth = 461 + OnCreate = FormCreate + OnMouseMove = FormMouseMove + LCLVersion = '1.6.2.0' + object Label1: TLabel + Left = 18 + Height = 21 + Top = 18 + Width = 43 + Caption = 'Label1' + ParentColor = False + end + object Label2: TLabel + Left = 18 + Height = 21 + Top = 40 + Width = 43 + Caption = 'Label2' + ParentColor = False + end + object Timer1: TTimer + Interval = 50 + OnTimer = Timer1Timer + left = 88 + top = 16 + end +end diff --git a/lazarus/scroller/unit1.pas b/lazarus/scroller/unit1.pas new file mode 100644 index 0000000..820429c --- /dev/null +++ b/lazarus/scroller/unit1.pas @@ -0,0 +1,115 @@ +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. +