|
root / delphi / HADP_Mar1997 / fishtank / clone / GoofFish.pas Created by zope. Last modified 2004-07-15 01:40:25. |
| Filename | GoofFish.pas |
|---|---|
| Size | 2671 |
| Content-type | text/plain |
| |
unit GoofFish;
interface
uses
SysUtils,
Classes,
Graphics,
Fish;
type
TGoofFish = class( TFish )
private
FCycle : integer;
FOffset : integer;
FHorizontalSpeed : integer;
FVerticalSpeed : integer;
protected
// Implement inherited abstract methods.
function GetCommonName : string; override;
function GetScientificName : string; override;
function GetWidth : integer; override;
function GetHeight : integer; override;
function GetBitmap : TBitmap; override;
public
constructor Create;
procedure Swim( var X : integer; var Y : integer;
maxX, maxY : integer ); override;
function Clone : TFish; override;
end;
implementation
uses
Controls;
var
TheImageList : array[ 'a'..'b', 0..2 ] of TBitmap;
constructor TGoofFish.Create;
begin
FCycle := 0;
FHorizontalSpeed := Random( 11 ) - 5;
FVerticalSpeed := Random( 5 ) - 2;
if FHorizontalSpeed > 0 then
FOffset := 1
else
FOffset := 0;
end;
function TGoofFish.GetCommonName : string;
begin
Result := 'Gooffish';
end;
function TGoofFish.GetScientificName : string;
begin
Result := 'Goofus fubarii';
end;
function TGoofFish.GetWidth : integer;
begin
Result := 50;
end;
function TGoofFish.GetHeight : integer;
begin
Result := 50;
end;
function TGoofFish.GetBitmap : TBitmap;
var
iBmp : integer;
bmp : TBitMap;
cOffset : char;
begin
cOffset := Chr( Ord( 'a' ) + FOffset );
Result := TheImageList[ cOffset, FCycle ];
end;
procedure TGoofFish.Swim( var X : integer; var Y : integer;
maxX, maxY : integer );
begin
FCycle := ( FCycle + 1 ) mod 3;
X := X + FHorizontalSpeed;
if ( X <= 0 ) or ( X + Width >= maxX ) or ( Random( 100 ) < 5 ) then
begin
FHorizontalSpeed := - FHorizontalSpeed;
FOffset := 1 - FOffset;
end;
Y := Y + FVerticalSpeed;
if ( Y <= 0 ) or ( Y + Height >= maxY ) or ( Random( 100 ) < 5 ) then
FVerticalSpeed := - FVerticalSpeed;
end;
function TGoofFish.Clone : TFish;
begin
Result := TGoofFish.Create;
end;
procedure Setup;
const
fileNameFmt = 'goof_0%d%s.bmp';
var
cImage : char;
iImage : integer;
fileName : string;
bmp : TBitmap;
begin
for cImage := 'a' to 'b' do
begin
for iImage := 1 to 3 do
begin
fileName := Format( fileNameFmt, [ iImage, cImage ] );
bmp := TBitmap.Create;
bmp.LoadFromFile( fileName );
TheImageList[ cImage, iImage-1 ] := bmp;
end;
end;
end;
procedure Cleanup;
begin
end;
initialization
Setup;
finalization
Cleanup;
end.