Thema: Delphi DelphiX "Schussproblem"

Einzelnen Beitrag anzeigen

Spurius

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

Re: DelphiX "Schussproblem"

  Alt 4. Feb 2004, 13:56
Sorry wenn der Code unübersichtlich ist
Ich bekomm jetzt eine Zugriffsverletzung:
Delphi-Quellcode:
type
  tcar = class(timagesprite)
   public
    munitionmg: integer;
    ausrichtung: byte;
    procedure DoMove(MoveCount: Integer); override;
    procedure shootmg;
  end;
 type
  tmg = class(timagesprite)
   public
     constructor create(aparent: tsprite); override;
   end;
var
  Form1: TForm1;
  car: tcar;
  mg: tmg;
  fire,start: integer;
implementation

{$R *.dfm}
constructor tmg.create(aparent: tsprite);
begin
 inherited create(aparent);
 Image := form1.dximagelist1.Items.Find('mg');
 Width := Image.Width;
 Height := Image.Height;
end;
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;
 with tmg.create(engine) do
  begin
   x := car.X;
   y := car.Y;
  end;
for i := 1 to 100 do begin
   if car.ausrichtung = 1 then begin
   mg.y := mg.y + 3; // <<<<<<<<<<< Da
   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.
  Mit Zitat antworten Zitat