TCar =
class(TImageSpriteEx)
private
speed: Single;
public
constructor Create(AParent: TSprite);
override;
procedure DoMove(MoveCount: Integer);
override;
end;
var
frmMain : TfrmMain;
Car : TCar;
implementation
{$R *.DFM}
constructor TCar.Create(AParent: TSprite);
begin
inherited Create(AParent);
Speed := 0;
end;
procedure TCar.DoMove(MoveCount: Integer);
begin
inherited DoMove(MoveCount);
if (isLeft
in frmMain.DXInput.States)
and (speed <> 0)
then
if speed < 0
then
Angle := angle + 1
else
Angle := angle - 1;
if (isRight
in frmMain.DXInput.States)
and (speed <> 0)
then
if speed < 0
then
Angle := angle - 1
else
Angle := angle + 1;
if isUp
in frmMain.DXInput.States
then
begin
if speed < 7
then
speed := speed + 0.05;
end;
if isDown
in frmMain.DXInput.States
then
begin
if speed < 7
then
speed := speed - 0.05;
end;
X := X + cos256(Angle) * speed;
if (x <= 0)
(* or (x + width >= frmMain.DXDraw.Width)*) then
begin
x := x - cos256(Angle) * speed;
speed := 0;
end;
Y := Y + sin256(Angle) * speed;
if (y <= 0)
or (y + height >= frmMain.DXDraw.height)
then
begin
y := y - sin256(Angle) * speed;
speed := 0;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
DXMap.LoadMap('
map\maps\map2.dxm');
Car := TCar.Create(DXSpriteEngine.Engine);
with Car
do
begin
Image := frmMain.DXImageList.Items.Find('
Car');
X := 150;
Y := 380;
Z := 0;
Width := Car.Image.Width;
Height := Car.Image.Height;
end;
end;
// Interval=0
procedure TfrmMain.DXTimerTimer(Sender: TObject; LagCount: Integer);
begin
DXInput.Update;
DXSpriteEngine.Move(1);
DXDraw.Surface.Fill(
RGB(13, 180, 50));
DXDraw.Surface.Fill(clBlack);
with DXDraw.Surface.Canvas
do
begin
Brush.Style := bsClear;
Font.Size := 12;
Font.Color := clRed;
TextOut(0,0, '
FPS: ' + IntToStr(LagCount));
Release;
end;
SpriteEngineMap.Draw;
DXSpriteEngine.Draw;
DXDraw.Flip;
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
begin
if not (DXMap =
nil)
then
begin
DXMap.Free;
end;
if not (DXDraw =
nil)
then
begin
DXDraw.Free;
end;
end;