unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type //Conventions Dictate that we private and protected fields are names starting with an "F"
{ TArrow }
TDart = class(TShape) //Inherits all the procedures, functions and variables of the class TShape
Private
FX1, FY1:Integer; //Current Position ---Addendum 1 Use TPoint instead
FGradient1:Real; //Gradient Number of the straight nine between it and the target point
FLife:Integer; //Life Total (Degrades and will delete the shape when reaches 0)
Procedure FSetGradient(M:Real); //Sets Gradient ---Addendum 2 The set function requires only 1 parameter.
Function FGetGradient:Real;
Public
Constructor Create(AOwner: TComponent); Override;
Destructor Destroy; Override;
Procedure ReduceLife(); //Controls Life Points
property Gradient: Real read FGetGradient write FSetGradient;
end;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Player: TShape;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
TDartQueue:array[0..15] of TDart;
implementation
{$R *.lfm}
{ TForm1 }
constructor TDart.Create(AOwner: TComponent); //Don't know what (AOwner:TComponent) does???
begin
inherited; //Don't know what this does either
Self.Parent := TForm1(AOwner);
FX1 :=Random(320);
FY1 :=Random(240);
Self.top :=FY1;
Self.Left :=FX1;
Self.Height :=16;
Self.Width :=16;
FLife :=10
end;
destructor TDart.Destroy;
begin
inherited Destroy;
end;
procedure TDart.FSetGradient(M:Real);
begin
FGradient1:=M;
end;
function TDart.FGetGradient: Real; //Obvious in its purpose
begin
FGetGradient:=FGradient1
end;
procedure TDart.ReduceLife();
begin
FLife := FLife-1;
if FLife <= 0 then
begin
Destroy; //Identifier Idents No Member "Destroy"
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s1: TDart;
begin
s1 := TDart.Create(Self);
s1.FSetGradient((Player.Top-s1.FY1)/(Player.Left-s1.FX1));
end;
procedure QueueShift(Queue: Array of TDart);
var
tmp : TDart;
i,j : Integer;
begin
for j := 0 to Length(Queue) do
begin
(Queue[j]).ReduceLife();
end;
tmp := Queue[0];
for i := 1 to Length(Queue) do
begin
Queue[i-1] := Queue[i];
Queue[Length(Queue)] := tmp;
end;
end;
procedure TForm1.Button1Click(Sender: TObject); //Lets Me Create LOTS Of Shapes on the click of a button
var
s1: TDart;
begin
s1:= TDart.Create(Self); //Self Refers to TForm1 (Creates the Shape)
s1.FSetGradient((Player.Top-s1.FY1)/(Player.Left-s1.FX1)); //Runs the Procedure Gradient Target Objects Coordinates
TDartQueue[15]:=s1;
QueueShift(TDartQueue);
end;
end.