This is part of a rain animation I wrote.
it will give you some of the basics of OOP class set up
{ This is the heart of any OOP Program here we define a Raindrop
Public and Private are more meaningful here, we could access the X,Y coord directly
if they were Public but that is not considered good OOP practise, it's called data hiding
}
type TDrops = class(Tobject) // so it Decends from a TObject (known as Inheritance)
Image: TImage;
private
Icons: array [0..4] of TIcon; // holds the different Drop icons
FallSpeed: Integer;
SplatSpeed: integer;
SplatIndex: Integer;
SplatTimer: integer;
X,Y: integer;
FloorLevel: integer;
CeilingLevel: integer;
Shown: Boolean;
Kill: boolean;
public // mostly these give external access to the Drops Private variables
Stopped: boolean;
constructor CreateDrop(ISpeed,IIndex,IX,IY: integer;
FLevel,CLevel: integer;
TParent: TWinControl); // all OOP objects must have a constructure
destructor DestroyDrop;
procedure AssignImage(I: integer);
procedure SetSpeed(NSpeed: integer);
procedure SetSplatRate(NSpeed: integer);
function GetSpeed: integer;
procedure Position(IX, IY: integer);
function GetY: integer;
function GetX: integer;
procedure Fall;
procedure ShowDrop(Hide: Boolean);
end;
var
DropModule: TDropModule;
Drip: array[0..10] of TDrops; // an array to hold the drops (we can have max 10 in fact)
number: integer;
implementation
{$R *.DFM}
{ the following functions and procedure all relate to a particular drop whichever
one we are referencing from the array they are Part of the drop object}
{ The constructers main job is to set up the variables}
constructor TDrops.CreateDrop(ISpeed, IIndex,IX,IY: integer;
FLevel,CLevel: integer;
TParent: TWincontrol);
var a: integer;
begin
inherited Create; // so we can 'create' a drop not a general TObject
FallSpeed := Ispeed;
SplatSpeed := FallSpeed;
SplatTimer := SplatSpeed;
SplatIndex := IIndex;
X := IX;
Y := IY;
FloorLevel := FLevel;
CeilingLevel := CLevel;
Shown := False;
Stopped := True;
Kill := False;
for a := 0 to 4 do
begin
Icons[a] := Ticon.create; // create the icon array and load it
DropModule.DropImages.GetIcon(a, Icons[a]);
end;
Image := TImage.Create(Image); // make somwhere for the icon to go !!
with Image do
begin
AutoSize := True;
Top := Y;
Left := X;
Picture.Icon := Icons[SplatIndex];
Visible := Shown;
parent := TParent;
end;
end;
Steve
Be excellent to each other and Party on!