unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DXClass, DXDraws, DXSprite, ExtCtrls;
type
TForm1 =
class(TForm)
DXDraw1: TDXDraw;
DXSpriteEngine1: TDXSpriteEngine;
DXImageList1: TDXImageList;
DXTimer1: TDXTimer;
procedure FormCreate(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
TAnimation =
class(TImageSprite)
private
vx, vy: Double;
public
constructor Create(AParent: TSprite);
override;
procedure DoMove(MoveCount: Integer);
override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
with TAnimation.Create(DXSpriteEngine1.Engine)
do
begin
X := 0;
Y := 0;
end;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
DXSpriteEngine1.Move(1);
DXDraw1.Surface.Fill(0);
DXSpriteEngine1.Draw;
DXDraw1.Flip;
end;
{ TAnimation }
constructor TAnimation.Create(AParent: TSprite);
begin
inherited;
vX := 2;
vY := 2;
Image := Form1.DXImageList1.Items.Find('
1');
Width := Image.Width;
Height := Image.Height;
AnimCount := 4;
AnimLooped := True;
AnimSpeed := 24/100;
AnimStart := 0;
end;
procedure TAnimation.DoMove(MoveCount: Integer);
begin
inherited;
if X <= 0
then
vX := 2;
if X >= Form1.DXDraw1.Width - Width
then
vX := - 2;
if Y <= 0
then
vY := 2;
if Y >= Form1.DXDraw1.Height - Height
then
vY := - 2;
X := X + vX;
Y := Y + vY;
end;
end.