unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DXSprite, DXDraws, StdCtrls, DXInput, DXClass;
type
TForm1 =
class(TForm)
DXDraw1: TDXDraw;
DXImageList1: TDXImageList;
DXSpriteEngine1: TDXSpriteEngine;
DXInput1: TDXInput;
DXTimer1: TDXTimer;
procedure FormCreate(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TAusrichtung = (auLeft, auRight, auUp, auDown);
TCar =
class(TImageSprite)
private
FMunitionMG: Integer;
FAusrichtung: TAusrichtung;
public
constructor Create (AParent: TSprite);
override;
procedure Schiessen;
procedure DoMove(MoveCount: Integer);
override;
property Ausrichtung: TAusrichtung
read FAusrichtung
write FAusrichtung;
property Munition: Integer
read FMunitionMG
write FMunitionMG;
end;
TMG =
class(TImageSprite)
public
constructor create(aparent: tsprite);
override;
procedure DoMove(MoveCount: Integer);
override;
end;
var
Form1: TForm1;
Car: TCar;
implementation
{$R *.dfm}
{ --- TCar --- }
constructor TCar.Create(AParent: TSprite);
begin
inherited;
Image := Form1.DXImageList1.Items.Find('
1');
Width := Image.Width;
Height := Image.Height;
FAusrichtung := auLeft;
X := 0;
Y := 0;
Z := 1;
FMunitionMG := 10;
end;
procedure TCar.DoMove(movecount: integer);
begin
inherited;
if IsLeft
in Form1.DxInput1.States
then
begin
X := X - 3;
FAusrichtung := auLeft;
end;
if IsRight
in Form1.DxInput1.States
then
begin
X := X + 3;
FAusrichtung := auRight;
end;
if IsDown
in Form1.DxInput1.States
then
begin
Y := Y + 3;
FAusrichtung := auDown;
end;
if IsUp
in Form1.DxInput1.States
then
begin
Y := Y - 3;
FAusrichtung := auUp;
end;
end;
procedure TCar.Schiessen;
begin
Dec(FMunitionMG);
with TMG.Create(engine)
do
begin
x := self.X;
y := self.Y;
end;
end;
{ ---------- }
{ --- TMG --- }
constructor TMG.create(aparent: tsprite);
begin
inherited create(aparent);
Image := Form1.DXImagelist1.Items.Find('
mg');
Width := Image.Width;
Height := Image.Height;
end;
procedure TMG.DoMove(MoveCount: Integer);
begin
inherited;
case Car.Ausrichtung
of
auLeft: X := X - 3;
auRight: X := X + 3;
auUp: Y := Y - 3;
auDown: Y := Y + 3;
end;
if (X > Form1.DXDraw1.Width)
or (X < 0)
then
Dead;
if (Y > Form1.DXDraw1.Height)
or (Y < 0)
then
Dead;
end;
{ ---------- }
procedure TForm1.FormCreate(Sender: TObject);
begin
Car := TCar.Create (DXSpriteEngine1.Engine);
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
DXInput1.Update;
DXDraw1.Surface.Fill(222);
DXSpriteEngine1.Draw;
DXSpriteEngine1.Move(20);
DXSpriteEngine1.Dead;
DXDraw1.Flip;
if isButton3
in DXInput1.States
then Close;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if Key = VK_SPACE
then
begin
if Car.Munition > 0
then
Car.Schiessen;
end;
end;
end.