unit Unit1;
interface
uses
Windows, Messages, SysUtils, Inifiles, Classes, Graphics, Controls, Forms, Dialogs,
DXDraws, Grids, StdCtrls, ExtCtrls, DXClass, DXSprite, DXInput;
type
TForm1 =
class(TForm)
DXImageList1: TDXImageList;
DXSpriteEngine1: TDXSpriteEngine;
DXTimer1: TDXTimer;
DXInput1: TDXInput;
DXDraw1: TDXDraw;
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen}
public
{ Public-Deklarationen}
end;
TPlayer =
class(TImageSprite)
public
constructor Create(AParent: TSprite );
override;
end;
TAnimation =
class(TImageSprite)
public
status:integer;
procedure DoMove(MoveCount: Integer);
override;
procedure DoCollision(Sprite: TSprite;
var Done: Boolean);
override;
constructor Create(AParent: TSprite );
override;
end;
var
Form1: TForm1;
Animation:TAnimation;
Player: TPlayer;
implementation
{$R *.DFM}
constructor TAnimation.Create(AParent: TSprite );
begin
inherited Create(AParent);
Image:=Form1.DXImageList1.Items[0];
Width :=Image.Width;
Height :=Image. Height;
end;
constructor TPlayer.Create(AParent: TSprite );
begin
inherited Create(AParent);
Image:=Form1.DXImageList1.Items[1];
Width :=Image.Width;
Height :=Image. Height;
end;
procedure TAnimation.DoMove(MoveCount: Integer);
begin
inherited DoMove(MoveCount);
If isUp
in Form1.DXInput1.States
Then begin
Y := Y -2;
status:=1;
end;
If isDown
in Form1.DXInput1.States
Then begin
Y := Y + 2;
status:=2;
end;
If isLeft
in Form1.DXInput1.States
Then begin
X := X -2;
status:=3;
end;
If isRight
in Form1.DXInput1.States
Then begin
X := X +2;
status:=4;
end;
collision;
end;
procedure Tanimation.DoCollision(Sprite: TSprite;
var Done: Boolean);
begin
if sprite
is TPlayer
then
begin
if status=1
then Y:=Y+2;
if status=2
then Y:=Y-2;
if status=3
then x:=x+2;
if status=4
then x:=x-2;
end;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
DXInput1.Update;
DXSpriteEngine1.Move(1);
DXDraw1.Surface.Fill(0);
DXSpriteEngine1.Draw;
DXDraw1.Flip;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
with TPlayer.Create(DXSpriteEngine1.Engine)
do
begin
x:=100;
y:=100;
end;
for i:= 1
to 3
do begin
with TAnimation.Create(DXSpriteEngine1.Engine)
do
begin
x:=64*i;
y:=0;
end;
end;
end;
end.