Thema: Delphi Tastenabfrage

Einzelnen Beitrag anzeigen

Spurius

Registriert seit: 19. Aug 2003
294 Beiträge
 
Delphi 7 Professional
 
#5

Re: Tastenabfrage

  Alt 31. Jan 2004, 11:59
Klappt leider nicht:
Delphi-Quellcode:
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);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
 type
  tcar = class(timagesprite)
   private
   public
    procedure DoMove(MoveCount: Integer); override;
    procedure shootmg;
 end;
 type
  tmg = class(timagesprite)
   public

  end;
var
  Form1: TForm1;
  car: tcar;
  mg: tmg;
  fire: integer;
implementation

{$R *.dfm}

procedure tcar.shootmg;
var i:integer;
begin
 fire := 1;
mg := tmg.Create(form1.dxspriteengine1.Engine);
 mg.Image := form1.dximagelist1.Items.Find('mg');
 mg.Width := mg.Image.Width;
 mg.Height := mg.Image.Height;
 mg.X := car.X;
 mg.Y := car.Y;
 for i := 1 to 100 do begin

   mg.X := mg.X + 3;
   form1.dxinput1.Update;
   form1.dxspriteengine1.Move(0);
   form1.dxspriteengine1.Dead;
   form1.dxdraw1.Surface.Fill(0);
   form1.dxspriteengine1.Draw;
   form1.dxdraw1.Flip;
 end;
   mg.Destroy;
   form1.dxspriteengine1.Move(0);
   form1.dxspriteengine1.Dead;
   form1.dxdraw1.Surface.Fill(0);
   form1.dxspriteengine1.Draw;
   form1.dxdraw1.Flip;
   fire := 0;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 car := tcar.Create(dxspriteengine1.Engine);
 car.Image := dximagelist1.Items.Find('1');
 car.X := 0;
 car.Y := 0;
 car.Width := car.Image.Width;
 car.Height := car.Image.Height;
 form1.DoubleBuffered := true;
 dxdraw1.DoubleBuffered := true;
 fire := 0;
end;
procedure tcar.DoMove(movecount: integer);
begin
 if isLeft in Form1.DxInput1.States then
    car.X := car.X -3;
  if isRight in Form1.DxInput1.States then
    car.X := car.X +3;
  if isdown in Form1.DxInput1.States then
    car.y := car.y +3;
  if isup in Form1.DxInput1.States then
    car.y := car.y -3;
  
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(0);
 dxspriteengine1.Draw;
 dxdraw1.Flip;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if (key = vk_space) and (fire=0) then car.shootmg;
end;

end.
  Mit Zitat antworten Zitat