Вот Юнит, относящийся к рыбам:
unit Fishes;
interface
uses Forms, Graphics, Types;
type
PFish = ^TFish;
PShuka = ^TShuka;
PCarp = ^TCarp;
TFish=object
x,y:integer;
color:integer;
Body:TBitmap;
Owner:TForm;
OwnerBody:TBitmap;
xSpeed,ySpeed,napr:integer;
constructor Init(px,py,pcolor:integer; myOwner:TForm; MyOwnerBody:TBitmap);
procedure LoadFromFile(FileName:string);
procedure Show;virtual;
procedure Move;virtual;
procedure Hide;
end;
TShuka=object(TFish)
constructor Init(px,py,pcolor:integer; myOwner:TForm; MyOwnerBody:TBitmap);
procedure Show;virtual;
procedure Move;virtual;
end;
TCarp=object(TFish)
constructor Init(px,py,pcolor:integer; myOwner:TForm; MyOwnerBody:TBitmap);
procedure Show;virtual;
procedure Move;virtual;
end;
implementation
constructor TFish.Init;
begin
end;
constructor TCarp.Init;
begin
x:=px;
y:=py;
color:=pcolor;
Owner:=myOwner;
OwnerBody:=MyOwnerBody;
Body:=TBitmap.Create;
LoadFromFile('Image\Fish1.bmp');
Body.Transparent:=true;
end;
constructor TShuka.Init;
begin
x:=px;
y:=py;
color:=pcolor;
Owner:=myOwner;
OwnerBody:=MyOwnerBody;
Body:=TBitmap.Create;
LoadFromFile('Image\Fish2.bmp');
Body.Transparent:=true;
end;
procedure TFish.LoadFromFile;
begin
Body.LoadFromFile(FileName);
end;
procedure TFish.Show;
begin
end;
procedure TFish.Move;
begin
end;
procedure TFish.Hide;
var
Rect1,Rect2:TRect;
begin
Rect1:=Rect(x,y,x+Body.Width,y+Body.Height);
Rect2:=Rect(x,y,x+Body.Width,y+Body.Height);
Owner.Canvas.BrushCopy(Rect1,OwnerBody,Rect2,clBlack);
end;
{=======================Shuka=======================}
procedure TShuka.Show;
begin
Owner.Canvas.Draw(x,y,Body);
end;
procedure TShuka.Move;
begin
xSpeed:=Random(10);
ySpeed:=Random(10);
napr:=1;
if (Random(200)<30) then
napr:=-napr;
case Random(2) of
0: Inc(x,xSpeed*napr);
1: Inc(y,ySpeed*napr);
end;
if (x>550)or(x<100) then
x:=100;
if (y>450)or(y<50) then
y:=50;
end;
{=======================Carp=======================}
procedure TCarp.Show;
begin
Owner.Canvas.Draw(x,y, Body);
end;
procedure TCarp.Move;
begin
xSpeed:=Random(10);
ySpeed:=Random(10);
napr:=1;
if (Random(200)<30) then
napr:=-napr;
case Random(2) of
0: Inc(x,xSpeed*napr);
1: Inc(y,ySpeed*napr);
end;
if (x>550)or(x<100) then
x:=100;
if (y>450)or(y<50) then
y:=50;
end;
begin
Randomize;
end.