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 FormPaint(Sender: TObject);
procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure carcreate;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
tcar =
class(timagesprite)
public
munitionmg: integer;
ausrichtung: byte;
procedure DoMove(MoveCount: Integer);
override;
procedure shootmg;
end;
type
tmg =
class(timagesprite)
public
end;
var
Form1: TForm1;
car: tcar;
mg: tmg;
fire,start: integer;
implementation
{$R *.dfm}
procedure tform1.carcreate;
begin
car := tcar.Create(dxspriteengine1.Engine);
car.Image := dximagelist1.Items.Find('
1');
car.X := 0;
car.Y := 0;
car.ausrichtung := 1;
car.Width := car.Image.Width;
car.Height := car.Image.Height;
car.munitionmg := 10;
end;
procedure tcar.shootmg;
var i:integer;
begin
fire := 0;
mg := tmg.Create(form1.dxspriteengine1.Engine);
mg.X := car.X;
mg.Y := car.Y;
mg.Image := form1.dximagelist1.Items.Find('
mg');
mg.Width := mg.Image.Width;
mg.Height := mg.Image.Height;
for i := 1
to 100
do begin
if car.ausrichtung = 1
then begin
mg.y := mg.y + 3;
form1.dxinput1.Update;
form1.dxspriteengine1.Move(0);
form1.dxspriteengine1.Dead;
form1.dxdraw1.Surface.Fill(222);
form1.dxspriteengine1.Draw;
form1.dxdraw1.Flip;
end;
if car.ausrichtung = 2
then begin
mg.X := mg.X + 3;
form1.dxinput1.Update;
form1.dxspriteengine1.Move(0);
form1.dxspriteengine1.Dead;
form1.dxdraw1.Surface.Fill(222);
form1.dxspriteengine1.Draw;
form1.dxdraw1.Flip;
end;
end;
mg.Free;
mg :=
nil;
form1.dxspriteengine1.Move(0);
form1.dxspriteengine1.Dead;
form1.dxdraw1.Surface.Fill(222);
form1.dxspriteengine1.Draw;
form1.dxdraw1.Flip;
car.munitionmg := car.munitionmg -1;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.DoubleBuffered := true;
dxdraw1.DoubleBuffered := true;
dxdraw1.Height := form1.Height;
dxdraw1.Width := form1.Width;
fire := 1;
carcreate;
end;
procedure tcar.DoMove(movecount: integer);
begin
if isLeft
in Form1.DxInput1.States
then begin
car.X := car.X -3;
car.ausrichtung := 4;
end;
if isRight
in Form1.DxInput1.States
then begin
car.X := car.X +3;
car.ausrichtung := 2;
end;
if isdown
in Form1.DxInput1.States
then begin
car.y := car.y +3;
car.ausrichtung := 3;
end;
if isup
in Form1.DxInput1.States
then begin
car.y := car.y -3;
car.ausrichtung := 1;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
form1.dxspriteengine1.Draw;
form1.dxdraw1.Flip;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
dxinput1.Update;
dxspriteengine1.Move(0);
dxspriteengine1.Dead;
dxdraw1.Surface.Fill(222);
dxspriteengine1.Draw;
dxdraw1.Flip;
if assigned(mg)
then fire := 0
else fire := 1;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (key = vk_space)
and (car.munitionmg > 0)
and (fire = 1)
then begin
car.shootmg;
end;
if key=vk_escape
then application.Terminate;
end;
end.