Sida 1 av 3
ParallelArrays
Se först:
Lektion 23 - Parallella Arrayer [6.53] [
http://www.blip.tv/file/3156004 ] unit Unit1;{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm) Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Shape6: TShape;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure Timer1Timer(Sender: TObject);
private
{ private declarations } public
Shape:Array[1..6] of TShape;
MoveRight:Array[1..6] of Boolean;
MoveUp:Array[1..6] of Boolean;
Speed:Array[1..6] of Integer;
end;
Sida 2 av 3
var
Form1: TForm1;
x:integer;
implementation { TForm1 }
procedure TForm1.Timer1Timer(Sender: TObject);
begin
for x:= 1 to 6 do begin
if MoveRight[x] = True then
Shape[x].Left := Shape[x].Left + Speed[x]
else
Shape[x].Left := Shape[x].Left - Speed[x];
if Shape[x].Left <=0 then MoveRight[x] := True;
if Shape[x].Left + Shape[x].Width >= Form1.Width then MoveRight[x] := False;
if MoveUp[x] = True then
Shape[x].Top := Shape[x].Top - Speed[x]
else
Shape[x].Top := Shape[x].Top + Speed[x];
if Shape[x].Top <= 0 then MoveUp[x] := False;
if Shape[x].Top + Shape[x].Height >= Form1.Height then MoveUp[x] := True;
end;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
if ((Key = 'p') or (Key = 'P')) and (Timer1.Enabled = True) then Timer1.Enabled := False
else if ((Key = 'p') or (Key = 'P')) and (Timer1.Enabled = False) then Timer1.Enabled := True;
end;
Sida 3 av 3
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered := True;
Shape[1] := Shape1;
Shape[2] := Shape2;
Shape[3] := Shape3;
Shape[4] := Shape4;
Shape[5] := Shape5;
Shape[6] := Shape6;
for x := 1 to 6 do begin
Speed[x] := x;
end;
end;
initialization {$I unit1.lrs}
end.